| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/sandbox_linux/bpf_gpu_policy_linux.h" | 5 #include "content/common/sandbox_linux/bpf_gpu_policy_linux.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" | 25 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" |
| 26 #include "content/common/set_process_title.h" | 26 #include "content/common/set_process_title.h" |
| 27 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 28 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" | 28 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" |
| 29 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" | 29 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" |
| 30 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" | 30 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" |
| 31 #include "sandbox/linux/services/linux_syscalls.h" | 31 #include "sandbox/linux/services/linux_syscalls.h" |
| 32 #include "sandbox/linux/syscall_broker/broker_process.h" | 32 #include "sandbox/linux/syscall_broker/broker_process.h" |
| 33 | 33 |
| 34 using sandbox::BrokerProcess; | 34 using sandbox::BrokerProcess; |
| 35 using sandbox::syscall_broker::BrokerPermission; |
| 35 using sandbox::SyscallSets; | 36 using sandbox::SyscallSets; |
| 36 using sandbox::arch_seccomp_data; | 37 using sandbox::arch_seccomp_data; |
| 37 using sandbox::bpf_dsl::Allow; | 38 using sandbox::bpf_dsl::Allow; |
| 38 using sandbox::bpf_dsl::ResultExpr; | 39 using sandbox::bpf_dsl::ResultExpr; |
| 39 using sandbox::bpf_dsl::Trap; | 40 using sandbox::bpf_dsl::Trap; |
| 40 | 41 |
| 41 namespace content { | 42 namespace content { |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 }; | 133 }; |
| 133 | 134 |
| 134 // x86_64/i386 or desktop ARM. | 135 // x86_64/i386 or desktop ARM. |
| 135 // A GPU broker policy is the same as a GPU policy with open and | 136 // A GPU broker policy is the same as a GPU policy with open and |
| 136 // openat allowed. | 137 // openat allowed. |
| 137 ResultExpr GpuBrokerProcessPolicy::EvaluateSyscall(int sysno) const { | 138 ResultExpr GpuBrokerProcessPolicy::EvaluateSyscall(int sysno) const { |
| 138 switch (sysno) { | 139 switch (sysno) { |
| 139 case __NR_access: | 140 case __NR_access: |
| 140 case __NR_open: | 141 case __NR_open: |
| 141 case __NR_openat: | 142 case __NR_openat: |
| 143 case __NR_unlink: |
| 142 return Allow(); | 144 return Allow(); |
| 143 default: | 145 default: |
| 144 return GpuProcessPolicy::EvaluateSyscall(sysno); | 146 return GpuProcessPolicy::EvaluateSyscall(sysno); |
| 145 } | 147 } |
| 146 } | 148 } |
| 147 | 149 |
| 148 void UpdateProcessTypeToGpuBroker() { | 150 void UpdateProcessTypeToGpuBroker() { |
| 149 base::CommandLine::StringVector exec = | 151 base::CommandLine::StringVector exec = |
| 150 base::CommandLine::ForCurrentProcess()->GetArgs(); | 152 base::CommandLine::ForCurrentProcess()->GetArgs(); |
| 151 base::CommandLine::Reset(); | 153 base::CommandLine::Reset(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) | 195 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) |
| 194 // The Nvidia driver uses flags not in the baseline policy | 196 // The Nvidia driver uses flags not in the baseline policy |
| 195 // (MAP_LOCKED | MAP_EXECUTABLE | MAP_32BIT) | 197 // (MAP_LOCKED | MAP_EXECUTABLE | MAP_32BIT) |
| 196 case __NR_mmap: | 198 case __NR_mmap: |
| 197 #endif | 199 #endif |
| 198 // We also hit this on the linux_chromeos bot but don't yet know what | 200 // We also hit this on the linux_chromeos bot but don't yet know what |
| 199 // weird flags were involved. | 201 // weird flags were involved. |
| 200 case __NR_mprotect: | 202 case __NR_mprotect: |
| 201 // TODO(jln): restrict prctl. | 203 // TODO(jln): restrict prctl. |
| 202 case __NR_prctl: | 204 case __NR_prctl: |
| 205 case __NR_ftruncate: |
| 203 return Allow(); | 206 return Allow(); |
| 204 case __NR_access: | 207 case __NR_access: |
| 205 case __NR_open: | 208 case __NR_open: |
| 206 case __NR_openat: | 209 case __NR_openat: |
| 207 DCHECK(broker_process_); | 210 DCHECK(broker_process_); |
| 208 return Trap(GpuSIGSYS_Handler, broker_process_); | 211 return Trap(GpuSIGSYS_Handler, broker_process_); |
| 209 case __NR_setpriority: | 212 case __NR_setpriority: |
| 210 return sandbox::RestrictGetSetpriority(GetPolicyPid()); | 213 return sandbox::RestrictGetSetpriority(GetPolicyPid()); |
| 211 case __NR_sched_getaffinity: | 214 case __NR_sched_getaffinity: |
| 212 case __NR_sched_setaffinity: | 215 case __NR_sched_setaffinity: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 224 // Warm up resources needed by the policy we're about to enable and | 227 // Warm up resources needed by the policy we're about to enable and |
| 225 // eventually start a broker process. | 228 // eventually start a broker process. |
| 226 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm(); | 229 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm(); |
| 227 // This policy is for x86 or Desktop. | 230 // This policy is for x86 or Desktop. |
| 228 DCHECK(!chromeos_arm_gpu); | 231 DCHECK(!chromeos_arm_gpu); |
| 229 | 232 |
| 230 DCHECK(!broker_process()); | 233 DCHECK(!broker_process()); |
| 231 // Create a new broker process. | 234 // Create a new broker process. |
| 232 InitGpuBrokerProcess( | 235 InitGpuBrokerProcess( |
| 233 GpuBrokerProcessPolicy::Create, | 236 GpuBrokerProcessPolicy::Create, |
| 234 std::vector<std::string>(), // No extra files in whitelist. | 237 std::vector<BrokerPermission>()); // No extra files in whitelist. |
| 235 std::vector<std::string>()); | |
| 236 | 238 |
| 237 if (IsArchitectureX86_64() || IsArchitectureI386()) { | 239 if (IsArchitectureX86_64() || IsArchitectureI386()) { |
| 238 // Accelerated video dlopen()'s some shared objects | 240 // Accelerated video dlopen()'s some shared objects |
| 239 // inside the sandbox, so preload them now. | 241 // inside the sandbox, so preload them now. |
| 240 if (IsAcceleratedVideoEnabled()) { | 242 if (IsAcceleratedVideoEnabled()) { |
| 241 const char* I965DrvVideoPath = NULL; | 243 const char* I965DrvVideoPath = NULL; |
| 242 | 244 |
| 243 if (IsArchitectureX86_64()) { | 245 if (IsArchitectureX86_64()) { |
| 244 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; | 246 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; |
| 245 } else if (IsArchitectureI386()) { | 247 } else if (IsArchitectureI386()) { |
| 246 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; | 248 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; |
| 247 } | 249 } |
| 248 | 250 |
| 249 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 251 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 250 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 252 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 251 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 253 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 252 } | 254 } |
| 253 } | 255 } |
| 254 | 256 |
| 255 return true; | 257 return true; |
| 256 } | 258 } |
| 257 | 259 |
| 258 void GpuProcessPolicy::InitGpuBrokerProcess( | 260 void GpuProcessPolicy::InitGpuBrokerProcess( |
| 259 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), | 261 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), |
| 260 const std::vector<std::string>& read_whitelist_extra, | 262 const std::vector<BrokerPermission>& permissions_extra) { |
| 261 const std::vector<std::string>& write_whitelist_extra) { | |
| 262 static const char kDriRcPath[] = "/etc/drirc"; | 263 static const char kDriRcPath[] = "/etc/drirc"; |
| 263 static const char kDriCard0Path[] = "/dev/dri/card0"; | 264 static const char kDriCard0Path[] = "/dev/dri/card0"; |
| 265 static const char kShm[] = "/dev/shm/"; |
| 264 | 266 |
| 265 CHECK(broker_process_ == NULL); | 267 CHECK(broker_process_ == NULL); |
| 266 | 268 |
| 267 // All GPU process policies need these files brokered out. | 269 // All GPU process policies need these files brokered out. |
| 268 std::vector<std::string> read_whitelist; | 270 std::vector<BrokerPermission> permissions; |
| 269 read_whitelist.push_back(kDriCard0Path); | 271 permissions.push_back(BROKER_PERM_READ_WRITE(kDriCard0Path)); |
| 270 read_whitelist.push_back(kDriRcPath); | 272 permissions.push_back(BROKER_PERM_READ_ONLY(kDriRcPath)); |
| 271 // Add eventual extra files from read_whitelist_extra. | 273 permissions.push_back(BROKER_PERM_READ_WRITE_CREATE_UNLINK_RECURSIVE(kShm)); |
| 272 read_whitelist.insert(read_whitelist.end(), | |
| 273 read_whitelist_extra.begin(), | |
| 274 read_whitelist_extra.end()); | |
| 275 | 274 |
| 276 std::vector<std::string> write_whitelist; | 275 // Add eventual extra files from permissions_extra. |
| 277 write_whitelist.push_back(kDriCard0Path); | 276 permissions.insert(permissions.end(), permissions_extra.begin(), |
| 278 // Add eventual extra files from write_whitelist_extra. | 277 permissions_extra.end()); |
| 279 write_whitelist.insert(write_whitelist.end(), | |
| 280 write_whitelist_extra.begin(), | |
| 281 write_whitelist_extra.end()); | |
| 282 | 278 |
| 283 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), | 279 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); |
| 284 read_whitelist, | |
| 285 write_whitelist); | |
| 286 // The initialization callback will perform generic initialization and then | 280 // The initialization callback will perform generic initialization and then |
| 287 // call broker_sandboxer_callback. | 281 // call broker_sandboxer_callback. |
| 288 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, | 282 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, |
| 289 broker_sandboxer_allocator))); | 283 broker_sandboxer_allocator))); |
| 290 } | 284 } |
| 291 | 285 |
| 292 } // namespace content | 286 } // namespace content |
| OLD | NEW |