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> |
11 #include <sys/stat.h> | 11 #include <sys/stat.h> |
12 #include <sys/types.h> | 12 #include <sys/types.h> |
13 #include <unistd.h> | 13 #include <unistd.h> |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "base/bind.h" | 19 #include "base/bind.h" |
20 #include "base/command_line.h" | 20 #include "base/command_line.h" |
21 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
22 #include "base/logging.h" | 22 #include "base/logging.h" |
23 #include "base/macros.h" | 23 #include "base/macros.h" |
24 #include "base/memory/ptr_util.h" | 24 #include "base/memory/ptr_util.h" |
| 25 #include "base/strings/stringprintf.h" |
25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
26 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" | 27 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" |
27 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" | 28 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" |
28 #include "content/common/set_process_title.h" | 29 #include "content/common/set_process_title.h" |
29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
30 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" | 31 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" |
31 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" | 32 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" |
32 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" | 33 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" |
33 #include "sandbox/linux/syscall_broker/broker_file_permission.h" | 34 #include "sandbox/linux/syscall_broker/broker_file_permission.h" |
34 #include "sandbox/linux/syscall_broker/broker_process.h" | 35 #include "sandbox/linux/syscall_broker/broker_process.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 case __NR_open: | 125 case __NR_open: |
125 #if defined(MEMORY_SANITIZER) | 126 #if defined(MEMORY_SANITIZER) |
126 // http://crbug.com/372840 | 127 // http://crbug.com/372840 |
127 __msan_unpoison_string(reinterpret_cast<const char*>(args.args[0])); | 128 __msan_unpoison_string(reinterpret_cast<const char*>(args.args[0])); |
128 #endif | 129 #endif |
129 return broker_process->Open(reinterpret_cast<const char*>(args.args[0]), | 130 return broker_process->Open(reinterpret_cast<const char*>(args.args[0]), |
130 static_cast<int>(args.args[1])); | 131 static_cast<int>(args.args[1])); |
131 #endif // !defined(__aarch64__) | 132 #endif // !defined(__aarch64__) |
132 case __NR_faccessat: | 133 case __NR_faccessat: |
133 if (static_cast<int>(args.args[0]) == AT_FDCWD) { | 134 if (static_cast<int>(args.args[0]) == AT_FDCWD) { |
134 return | 135 return broker_process->Access( |
135 broker_process->Access(reinterpret_cast<const char*>(args.args[1]), | 136 reinterpret_cast<const char*>(args.args[1]), |
136 static_cast<int>(args.args[2])); | 137 static_cast<int>(args.args[2])); |
137 } else { | 138 } else { |
138 return -EPERM; | 139 return -EPERM; |
139 } | 140 } |
140 case __NR_openat: | 141 case __NR_openat: |
141 // Allow using openat() as open(). | 142 // Allow using openat() as open(). |
142 if (static_cast<int>(args.args[0]) == AT_FDCWD) { | 143 if (static_cast<int>(args.args[0]) == AT_FDCWD) { |
143 return | 144 return broker_process->Open(reinterpret_cast<const char*>(args.args[1]), |
144 broker_process->Open(reinterpret_cast<const char*>(args.args[1]), | 145 static_cast<int>(args.args[2])); |
145 static_cast<int>(args.args[2])); | |
146 } else { | 146 } else { |
147 return -EPERM; | 147 return -EPERM; |
148 } | 148 } |
149 default: | 149 default: |
150 RAW_CHECK(false); | 150 RAW_CHECK(false); |
151 return -ENOSYS; | 151 return -ENOSYS; |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 void AddV4L2GpuWhitelist(std::vector<BrokerFilePermission>* permissions) { | 155 void AddV4L2GpuWhitelist(std::vector<BrokerFilePermission>* permissions) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 bool UpdateProcessTypeAndEnableSandbox( | 222 bool UpdateProcessTypeAndEnableSandbox( |
223 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void)) { | 223 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void)) { |
224 DCHECK(broker_sandboxer_allocator); | 224 DCHECK(broker_sandboxer_allocator); |
225 UpdateProcessTypeToGpuBroker(); | 225 UpdateProcessTypeToGpuBroker(); |
226 return SandboxSeccompBPF::StartSandboxWithExternalPolicy( | 226 return SandboxSeccompBPF::StartSandboxWithExternalPolicy( |
227 base::WrapUnique(broker_sandboxer_allocator()), base::ScopedFD()); | 227 base::WrapUnique(broker_sandboxer_allocator()), base::ScopedFD()); |
228 } | 228 } |
229 | 229 |
230 } // namespace | 230 } // namespace |
231 | 231 |
232 GpuProcessPolicy::GpuProcessPolicy() : GpuProcessPolicy(false) { | 232 GpuProcessPolicy::GpuProcessPolicy() : GpuProcessPolicy(false) {} |
233 } | |
234 | 233 |
235 GpuProcessPolicy::GpuProcessPolicy(bool allow_mincore) | 234 GpuProcessPolicy::GpuProcessPolicy(bool allow_mincore) |
236 : broker_process_(NULL), allow_mincore_(allow_mincore) { | 235 : broker_process_(NULL), allow_mincore_(allow_mincore) {} |
237 } | |
238 | 236 |
239 GpuProcessPolicy::~GpuProcessPolicy() {} | 237 GpuProcessPolicy::~GpuProcessPolicy() {} |
240 | 238 |
241 // Main policy for x86_64/i386. Extended by CrosArmGpuProcessPolicy. | 239 // Main policy for x86_64/i386. Extended by CrosArmGpuProcessPolicy. |
242 ResultExpr GpuProcessPolicy::EvaluateSyscall(int sysno) const { | 240 ResultExpr GpuProcessPolicy::EvaluateSyscall(int sysno) const { |
243 switch (sysno) { | 241 switch (sysno) { |
244 #if !defined(OS_CHROMEOS) | 242 #if !defined(OS_CHROMEOS) |
245 case __NR_ftruncate: | 243 case __NR_ftruncate: |
246 #endif | 244 #endif |
247 case __NR_ioctl: | 245 case __NR_ioctl: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 const char* I965DrvVideoPath = NULL; | 303 const char* I965DrvVideoPath = NULL; |
306 const char* I965HybridDrvVideoPath = NULL; | 304 const char* I965HybridDrvVideoPath = NULL; |
307 | 305 |
308 if (IsArchitectureX86_64()) { | 306 if (IsArchitectureX86_64()) { |
309 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; | 307 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; |
310 I965HybridDrvVideoPath = "/usr/lib64/va/drivers/hybrid_drv_video.so"; | 308 I965HybridDrvVideoPath = "/usr/lib64/va/drivers/hybrid_drv_video.so"; |
311 } else if (IsArchitectureI386()) { | 309 } else if (IsArchitectureI386()) { |
312 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; | 310 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; |
313 } | 311 } |
314 | 312 |
315 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 313 dlopen(I965DrvVideoPath, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); |
316 if (I965HybridDrvVideoPath) | 314 if (I965HybridDrvVideoPath) |
317 dlopen(I965HybridDrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 315 dlopen(I965HybridDrvVideoPath, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); |
318 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 316 dlopen("libva.so.1", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); |
319 #if defined(USE_OZONE) | 317 #if defined(USE_OZONE) |
320 dlopen("libva-drm.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 318 dlopen("libva-drm.so.1", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); |
321 #elif defined(USE_X11) | 319 #elif defined(USE_X11) |
322 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 320 dlopen("libva-x11.so.1", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); |
323 #endif | 321 #endif |
324 } | 322 } |
325 } | 323 } |
326 | 324 |
327 return true; | 325 return true; |
328 } | 326 } |
329 | 327 |
330 void GpuProcessPolicy::InitGpuBrokerProcess( | 328 void GpuProcessPolicy::InitGpuBrokerProcess( |
331 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), | 329 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), |
332 const std::vector<BrokerFilePermission>& permissions_extra) { | 330 const std::vector<BrokerFilePermission>& permissions_extra) { |
333 static const char kDriRcPath[] = "/etc/drirc"; | 331 static const char kDriRcPath[] = "/etc/drirc"; |
334 static const char kDriCard0Path[] = "/dev/dri/card0"; | 332 static const char kDriCard0Path[] = "/dev/dri/card0"; |
| 333 static const char kDriCardBasePath[] = "/dev/dri/card"; |
| 334 |
| 335 static const char kNvidiaCtlPath[] = "/dev/nvidiactl"; |
| 336 static const char kNvidiaDeviceBasePath[] = "/dev/nvidia"; |
| 337 static const char kNvidiaParamsPath[] = "/proc/driver/nvidia/params"; |
| 338 |
335 static const char kDevShm[] = "/dev/shm/"; | 339 static const char kDevShm[] = "/dev/shm/"; |
336 | 340 |
337 CHECK(broker_process_ == NULL); | 341 CHECK(broker_process_ == NULL); |
338 | 342 |
339 // All GPU process policies need these files brokered out. | 343 // All GPU process policies need these files brokered out. |
340 std::vector<BrokerFilePermission> permissions; | 344 std::vector<BrokerFilePermission> permissions; |
341 permissions.push_back(BrokerFilePermission::ReadWrite(kDriCard0Path)); | 345 permissions.push_back(BrokerFilePermission::ReadWrite(kDriCard0Path)); |
342 permissions.push_back(BrokerFilePermission::ReadOnly(kDriRcPath)); | 346 permissions.push_back(BrokerFilePermission::ReadOnly(kDriRcPath)); |
| 347 |
343 if (!IsChromeOS()) { | 348 if (!IsChromeOS()) { |
| 349 // For shared memory. |
344 permissions.push_back( | 350 permissions.push_back( |
345 BrokerFilePermission::ReadWriteCreateUnlinkRecursive(kDevShm)); | 351 BrokerFilePermission::ReadWriteCreateUnlinkRecursive(kDevShm)); |
346 } else if (UseV4L2Codec()){ | 352 // For multi-card DRI setups. NOTE: /dev/dri/card0 was already added above. |
| 353 for (int i = 1; i <= 9; ++i) { |
| 354 permissions.push_back(BrokerFilePermission::ReadWrite( |
| 355 base::StringPrintf("%s%d", kDriCardBasePath, i))); |
| 356 } |
| 357 // For Nvidia GLX driver. |
| 358 permissions.push_back(BrokerFilePermission::ReadWrite(kNvidiaCtlPath)); |
| 359 for (int i = 0; i <= 9; ++i) { |
| 360 permissions.push_back(BrokerFilePermission::ReadWrite( |
| 361 base::StringPrintf("%s%d", kNvidiaDeviceBasePath, i))); |
| 362 } |
| 363 permissions.push_back(BrokerFilePermission::ReadOnly(kNvidiaParamsPath)); |
| 364 } else if (UseV4L2Codec()) { |
347 AddV4L2GpuWhitelist(&permissions); | 365 AddV4L2GpuWhitelist(&permissions); |
348 if (UseLibV4L2()) { | 366 if (UseLibV4L2()) { |
349 dlopen("/usr/lib/libv4l2.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 367 dlopen("/usr/lib/libv4l2.so", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); |
350 // This is a device-specific encoder plugin. | 368 // This is a device-specific encoder plugin. |
351 dlopen("/usr/lib/libv4l/plugins/libv4l-encplugin.so", | 369 dlopen("/usr/lib/libv4l/plugins/libv4l-encplugin.so", |
352 RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 370 RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); |
353 } | 371 } |
354 } | 372 } |
355 | 373 |
356 // Add eventual extra files from permissions_extra. | 374 // Add eventual extra files from permissions_extra. |
357 for (const auto& perm : permissions_extra) { | 375 for (const auto& perm : permissions_extra) { |
358 permissions.push_back(perm); | 376 permissions.push_back(perm); |
359 } | 377 } |
360 | 378 |
361 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); | 379 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); |
362 // The initialization callback will perform generic initialization and then | 380 // The initialization callback will perform generic initialization and then |
363 // call broker_sandboxer_callback. | 381 // call broker_sandboxer_callback. |
364 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, | 382 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, |
365 broker_sandboxer_allocator))); | 383 broker_sandboxer_allocator))); |
366 } | 384 } |
367 | 385 |
368 } // namespace content | 386 } // namespace content |
OLD | NEW |