Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <asm/unistd.h> | 5 #include <asm/unistd.h> |
| 6 #include <dlfcn.h> | 6 #include <dlfcn.h> |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <linux/net.h> | 9 #include <linux/net.h> |
| 10 #include <signal.h> | 10 #include <signal.h> |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 #include <sys/ioctl.h> | 12 #include <sys/ioctl.h> |
| 13 #include <sys/mman.h> | 13 #include <sys/mman.h> |
| 14 #include <sys/prctl.h> | 14 #include <sys/prctl.h> |
| 15 #include <sys/socket.h> | 15 #include <sys/socket.h> |
| 16 #include <sys/stat.h> | 16 #include <sys/stat.h> |
| 17 #include <sys/types.h> | 17 #include <sys/types.h> |
| 18 #include <ucontext.h> | 18 #include <ucontext.h> |
| 19 #include <unistd.h> | 19 #include <unistd.h> |
| 20 | 20 |
| 21 #include <vector> | 21 #include <vector> |
| 22 | 22 |
| 23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 24 #include "base/command_line.h" | 24 #include "base/command_line.h" |
| 25 #include "base/logging.h" | 25 #include "base/logging.h" |
| 26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 27 #include "content/common/sandbox_linux.h" | |
| 28 #include "content/common/sandbox_seccomp_bpf_linux.h" | |
| 29 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 30 #include "sandbox/linux/services/broker_process.h" | |
| 31 | 28 |
| 32 // These are the only architectures supported for now. | 29 // These are the only architectures supported for now. |
| 33 #if defined(__i386__) || defined(__x86_64__) || \ | 30 #if defined(__i386__) || defined(__x86_64__) || \ |
| 34 (defined(__arm__) && (defined(__thumb__) || defined(__ARM_EABI__))) | 31 (defined(__arm__) && (defined(__thumb__) || defined(__ARM_EABI__))) |
| 35 #define SECCOMP_BPF_SANDBOX | 32 #define SECCOMP_BPF_SANDBOX |
| 36 #endif | 33 #endif |
| 37 | 34 |
| 38 #if defined(SECCOMP_BPF_SANDBOX) | 35 #if defined(SECCOMP_BPF_SANDBOX) |
| 39 #include "base/posix/eintr_wrapper.h" | 36 #include "base/posix/eintr_wrapper.h" |
| 40 #include "content/common/sandbox_bpf_base_policy_linux.h" | 37 #include "content/common/sandbox_linux/bpf_cros_arm_gpu_policy_linux.h" |
| 38 #include "content/common/sandbox_linux/bpf_gpu_policy_linux.h" | |
| 39 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" | |
| 40 #include "content/common/sandbox_linux/sandbox_linux.h" | |
| 41 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" | |
| 41 #include "sandbox/linux/seccomp-bpf-helpers/baseline_policy.h" | 42 #include "sandbox/linux/seccomp-bpf-helpers/baseline_policy.h" |
| 42 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" | 43 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" |
| 43 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" | 44 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" |
| 44 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" | 45 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" |
| 45 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 46 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| 46 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h" | 47 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h" |
| 47 #include "sandbox/linux/services/linux_syscalls.h" | 48 #include "sandbox/linux/services/linux_syscalls.h" |
| 48 | 49 |
| 49 using sandbox::BaselinePolicy; | 50 using sandbox::BaselinePolicy; |
| 50 using sandbox::BrokerProcess; | |
| 51 using sandbox::ErrorCode; | 51 using sandbox::ErrorCode; |
| 52 using sandbox::SandboxBPF; | 52 using sandbox::SandboxBPF; |
| 53 using sandbox::SyscallSets; | 53 using sandbox::SyscallSets; |
| 54 using sandbox::arch_seccomp_data; | 54 using sandbox::arch_seccomp_data; |
| 55 | 55 |
| 56 namespace content { | 56 namespace content { |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| 59 | 59 |
| 60 void StartSandboxWithPolicy(sandbox::SandboxBPFPolicy* policy); | 60 void StartSandboxWithPolicy(sandbox::SandboxBPFPolicy* policy); |
| 61 | 61 |
| 62 inline bool IsChromeOS() { | 62 inline bool IsChromeOS() { |
| 63 #if defined(OS_CHROMEOS) | 63 #if defined(OS_CHROMEOS) |
| 64 return true; | 64 return true; |
| 65 #else | 65 #else |
| 66 return false; | 66 return false; |
| 67 #endif | 67 #endif |
| 68 } | 68 } |
| 69 | 69 |
| 70 inline bool IsArchitectureX86_64() { | |
| 71 #if defined(__x86_64__) | |
| 72 return true; | |
| 73 #else | |
| 74 return false; | |
| 75 #endif | |
| 76 } | |
| 77 | |
| 78 inline bool IsArchitectureI386() { | |
| 79 #if defined(__i386__) | |
| 80 return true; | |
| 81 #else | |
| 82 return false; | |
| 83 #endif | |
| 84 } | |
| 85 | |
| 86 inline bool IsArchitectureArm() { | 70 inline bool IsArchitectureArm() { |
| 87 #if defined(__arm__) | 71 #if defined(__arm__) |
| 88 return true; | 72 return true; |
| 89 #else | 73 #else |
| 90 return false; | 74 return false; |
| 91 #endif | 75 #endif |
| 92 } | 76 } |
| 93 | 77 |
| 94 inline bool IsUsingToolKitGtk() { | 78 inline bool IsUsingToolKitGtk() { |
| 95 #if defined(TOOLKIT_GTK) | 79 #if defined(TOOLKIT_GTK) |
| 96 return true; | 80 return true; |
| 97 #else | 81 #else |
| 98 return false; | 82 return false; |
| 99 #endif | 83 #endif |
| 100 } | 84 } |
| 101 | 85 |
| 102 // Policies for the GPU process. | |
| 103 // TODO(jln): move to gpu/ | |
| 104 | |
| 105 bool IsAcceleratedVideoDecodeEnabled() { | |
| 106 // Accelerated video decode is currently enabled on Chrome OS, | |
| 107 // but not on Linux: crbug.com/137247. | |
| 108 bool is_enabled = IsChromeOS(); | |
| 109 | |
| 110 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 111 is_enabled = is_enabled && | |
| 112 !command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode); | |
| 113 | |
| 114 return is_enabled; | |
| 115 } | |
| 116 | |
| 117 intptr_t GpuSIGSYS_Handler(const struct arch_seccomp_data& args, | |
| 118 void* aux_broker_process) { | |
| 119 RAW_CHECK(aux_broker_process); | |
| 120 BrokerProcess* broker_process = | |
| 121 static_cast<BrokerProcess*>(aux_broker_process); | |
| 122 switch (args.nr) { | |
| 123 case __NR_access: | |
| 124 return broker_process->Access(reinterpret_cast<const char*>(args.args[0]), | |
| 125 static_cast<int>(args.args[1])); | |
| 126 case __NR_open: | |
| 127 return broker_process->Open(reinterpret_cast<const char*>(args.args[0]), | |
| 128 static_cast<int>(args.args[1])); | |
| 129 case __NR_openat: | |
| 130 // Allow using openat() as open(). | |
| 131 if (static_cast<int>(args.args[0]) == AT_FDCWD) { | |
| 132 return | |
| 133 broker_process->Open(reinterpret_cast<const char*>(args.args[1]), | |
| 134 static_cast<int>(args.args[2])); | |
| 135 } else { | |
| 136 return -EPERM; | |
| 137 } | |
| 138 default: | |
| 139 RAW_CHECK(false); | |
| 140 return -ENOSYS; | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 class GpuProcessPolicy : public SandboxBPFBasePolicy { | |
| 145 public: | |
| 146 explicit GpuProcessPolicy(void* broker_process) | |
| 147 : broker_process_(broker_process) {} | |
| 148 virtual ~GpuProcessPolicy() {} | |
| 149 | |
| 150 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, | |
| 151 int system_call_number) const OVERRIDE; | |
| 152 | |
| 153 private: | |
| 154 const void* broker_process_; // Non-owning pointer. | |
| 155 DISALLOW_COPY_AND_ASSIGN(GpuProcessPolicy); | |
| 156 }; | |
| 157 | |
| 158 // Main policy for x86_64/i386. Extended by ArmGpuProcessPolicy. | |
| 159 ErrorCode GpuProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox, | |
| 160 int sysno) const { | |
| 161 switch (sysno) { | |
| 162 case __NR_ioctl: | |
| 163 #if defined(__i386__) || defined(__x86_64__) | |
| 164 // The Nvidia driver uses flags not in the baseline policy | |
| 165 // (MAP_LOCKED | MAP_EXECUTABLE | MAP_32BIT) | |
| 166 case __NR_mmap: | |
| 167 #endif | |
| 168 // We also hit this on the linux_chromeos bot but don't yet know what | |
| 169 // weird flags were involved. | |
| 170 case __NR_mprotect: | |
| 171 case __NR_sched_getaffinity: | |
| 172 case __NR_sched_setaffinity: | |
| 173 case __NR_setpriority: | |
| 174 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 175 case __NR_access: | |
| 176 case __NR_open: | |
| 177 case __NR_openat: | |
| 178 return sandbox->Trap(GpuSIGSYS_Handler, broker_process_); | |
| 179 default: | |
| 180 if (SyscallSets::IsEventFd(sysno)) | |
| 181 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 182 | |
| 183 // Default on the baseline policy. | |
| 184 return SandboxBPFBasePolicy::EvaluateSyscall(sandbox, sysno); | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 class GpuBrokerProcessPolicy : public GpuProcessPolicy { | |
| 189 public: | |
| 190 GpuBrokerProcessPolicy() : GpuProcessPolicy(NULL) {} | |
| 191 virtual ~GpuBrokerProcessPolicy() {} | |
| 192 | |
| 193 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, | |
| 194 int system_call_number) const OVERRIDE; | |
| 195 | |
| 196 private: | |
| 197 DISALLOW_COPY_AND_ASSIGN(GpuBrokerProcessPolicy); | |
| 198 }; | |
| 199 | |
| 200 // x86_64/i386. | |
| 201 // A GPU broker policy is the same as a GPU policy with open and | |
| 202 // openat allowed. | |
| 203 ErrorCode GpuBrokerProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox, | |
| 204 int sysno) const { | |
| 205 switch (sysno) { | |
| 206 case __NR_access: | |
| 207 case __NR_open: | |
| 208 case __NR_openat: | |
| 209 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 210 default: | |
| 211 return GpuProcessPolicy::EvaluateSyscall(sandbox, sysno); | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 class ArmGpuProcessPolicy : public GpuProcessPolicy { | |
| 216 public: | |
| 217 explicit ArmGpuProcessPolicy(void* broker_process, bool allow_shmat) | |
| 218 : GpuProcessPolicy(broker_process), allow_shmat_(allow_shmat) {} | |
| 219 virtual ~ArmGpuProcessPolicy() {} | |
| 220 | |
| 221 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, | |
| 222 int system_call_number) const OVERRIDE; | |
| 223 | |
| 224 private: | |
| 225 const bool allow_shmat_; // Allow shmat(2). | |
| 226 DISALLOW_COPY_AND_ASSIGN(ArmGpuProcessPolicy); | |
| 227 }; | |
| 228 | |
| 229 // Generic ARM GPU process sandbox, inheriting from GpuProcessPolicy. | |
| 230 ErrorCode ArmGpuProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox, | |
| 231 int sysno) const { | |
| 232 #if defined(__arm__) | |
| 233 if (allow_shmat_ && sysno == __NR_shmat) | |
| 234 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 235 #endif // defined(__arm__) | |
| 236 | |
| 237 switch (sysno) { | |
| 238 #if defined(__arm__) | |
| 239 // ARM GPU sandbox is started earlier so we need to allow networking | |
| 240 // in the sandbox. | |
| 241 case __NR_connect: | |
| 242 case __NR_getpeername: | |
| 243 case __NR_getsockname: | |
| 244 case __NR_sysinfo: | |
| 245 case __NR_uname: | |
| 246 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 247 // Allow only AF_UNIX for |domain|. | |
| 248 case __NR_socket: | |
| 249 case __NR_socketpair: | |
| 250 return sandbox->Cond(0, ErrorCode::TP_32BIT, | |
| 251 ErrorCode::OP_EQUAL, AF_UNIX, | |
| 252 ErrorCode(ErrorCode::ERR_ALLOWED), | |
| 253 ErrorCode(EPERM)); | |
| 254 #endif // defined(__arm__) | |
| 255 default: | |
| 256 if (SyscallSets::IsAdvancedScheduler(sysno)) | |
| 257 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 258 | |
| 259 // Default to the generic GPU policy. | |
| 260 return GpuProcessPolicy::EvaluateSyscall(sandbox, sysno); | |
| 261 } | |
| 262 } | |
| 263 | |
| 264 class ArmGpuBrokerProcessPolicy : public ArmGpuProcessPolicy { | |
| 265 public: | |
| 266 ArmGpuBrokerProcessPolicy() : ArmGpuProcessPolicy(NULL, false) {} | |
| 267 virtual ~ArmGpuBrokerProcessPolicy() {} | |
| 268 | |
| 269 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, | |
| 270 int system_call_number) const OVERRIDE; | |
| 271 | |
| 272 private: | |
| 273 DISALLOW_COPY_AND_ASSIGN(ArmGpuBrokerProcessPolicy); | |
| 274 }; | |
| 275 | |
| 276 // A GPU broker policy is the same as a GPU policy with open and | |
| 277 // openat allowed. | |
| 278 ErrorCode ArmGpuBrokerProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox, | |
| 279 int sysno) const { | |
| 280 switch (sysno) { | |
| 281 case __NR_access: | |
| 282 case __NR_open: | |
| 283 case __NR_openat: | |
| 284 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 285 default: | |
| 286 return ArmGpuProcessPolicy::EvaluateSyscall(sandbox, sysno); | |
| 287 } | |
| 288 } | |
| 289 | |
| 290 // Policy for renderer and worker processes. | 86 // Policy for renderer and worker processes. |
| 291 // TODO(jln): move to renderer/ | 87 // TODO(jln): move to renderer/ |
| 292 | 88 |
| 293 class RendererOrWorkerProcessPolicy : public SandboxBPFBasePolicy { | 89 class RendererOrWorkerProcessPolicy : public SandboxBPFBasePolicy { |
| 294 public: | 90 public: |
| 295 RendererOrWorkerProcessPolicy() {} | 91 RendererOrWorkerProcessPolicy() {} |
| 296 virtual ~RendererOrWorkerProcessPolicy() {} | 92 virtual ~RendererOrWorkerProcessPolicy() {} |
| 297 | 93 |
| 298 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, | 94 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, |
| 299 int system_call_number) const OVERRIDE; | 95 int system_call_number) const OVERRIDE; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 CHECK_EQ(SandboxBPFBasePolicy::GetFSDeniedErrno(), errno); | 269 CHECK_EQ(SandboxBPFBasePolicy::GetFSDeniedErrno(), errno); |
| 474 | 270 |
| 475 // We should never allow the creation of netlink sockets. | 271 // We should never allow the creation of netlink sockets. |
| 476 syscall_ret = socket(AF_NETLINK, SOCK_DGRAM, 0); | 272 syscall_ret = socket(AF_NETLINK, SOCK_DGRAM, 0); |
| 477 CHECK_EQ(-1, syscall_ret); | 273 CHECK_EQ(-1, syscall_ret); |
| 478 CHECK_EQ(EPERM, errno); | 274 CHECK_EQ(EPERM, errno); |
| 479 #endif // !defined(NDEBUG) | 275 #endif // !defined(NDEBUG) |
| 480 } | 276 } |
| 481 } | 277 } |
| 482 | 278 |
| 483 bool EnableGpuBrokerPolicyCallback() { | |
| 484 StartSandboxWithPolicy(new GpuBrokerProcessPolicy); | |
| 485 return true; | |
| 486 } | |
| 487 | |
| 488 bool EnableArmGpuBrokerPolicyCallback() { | |
| 489 StartSandboxWithPolicy(new ArmGpuBrokerProcessPolicy); | |
| 490 return true; | |
| 491 } | |
| 492 | |
| 493 // Files needed by the ARM GPU userspace. | |
| 494 static const char kLibGlesPath[] = "/usr/lib/libGLESv2.so.2"; | |
| 495 static const char kLibEglPath[] = "/usr/lib/libEGL.so.1"; | |
| 496 | |
| 497 void AddArmMaliGpuWhitelist(std::vector<std::string>* read_whitelist, | |
| 498 std::vector<std::string>* write_whitelist) { | |
| 499 // Device file needed by the ARM GPU userspace. | |
| 500 static const char kMali0Path[] = "/dev/mali0"; | |
| 501 | |
| 502 // Devices needed for video decode acceleration on ARM. | |
| 503 static const char kDevMfcDecPath[] = "/dev/mfc-dec"; | |
| 504 static const char kDevGsc1Path[] = "/dev/gsc1"; | |
| 505 | |
| 506 // Devices needed for video encode acceleration on ARM. | |
| 507 static const char kDevMfcEncPath[] = "/dev/mfc-enc"; | |
| 508 | |
| 509 read_whitelist->push_back(kMali0Path); | |
| 510 read_whitelist->push_back(kDevMfcDecPath); | |
| 511 read_whitelist->push_back(kDevGsc1Path); | |
| 512 read_whitelist->push_back(kDevMfcEncPath); | |
| 513 | |
| 514 write_whitelist->push_back(kMali0Path); | |
| 515 write_whitelist->push_back(kDevMfcDecPath); | |
| 516 write_whitelist->push_back(kDevGsc1Path); | |
| 517 write_whitelist->push_back(kDevMfcEncPath); | |
| 518 } | |
| 519 | |
| 520 void AddArmTegraGpuWhitelist(std::vector<std::string>* read_whitelist, | |
| 521 std::vector<std::string>* write_whitelist) { | |
| 522 // Device files needed by the Tegra GPU userspace. | |
| 523 static const char kDevNvhostCtrlPath[] = "/dev/nvhost-ctrl"; | |
| 524 static const char kDevNvhostGr2dPath[] = "/dev/nvhost-gr2d"; | |
| 525 static const char kDevNvhostGr3dPath[] = "/dev/nvhost-gr3d"; | |
| 526 static const char kDevNvhostIspPath[] = "/dev/nvhost-isp"; | |
| 527 static const char kDevNvhostViPath[] = "/dev/nvhost-vi"; | |
| 528 static const char kDevNvmapPath[] = "/dev/nvmap"; | |
| 529 static const char kDevTegraSemaPath[] = "/dev/tegra_sema"; | |
| 530 | |
| 531 read_whitelist->push_back(kDevNvhostCtrlPath); | |
| 532 read_whitelist->push_back(kDevNvhostGr2dPath); | |
| 533 read_whitelist->push_back(kDevNvhostGr3dPath); | |
| 534 read_whitelist->push_back(kDevNvhostIspPath); | |
| 535 read_whitelist->push_back(kDevNvhostViPath); | |
| 536 read_whitelist->push_back(kDevNvmapPath); | |
| 537 read_whitelist->push_back(kDevTegraSemaPath); | |
| 538 | |
| 539 write_whitelist->push_back(kDevNvhostCtrlPath); | |
| 540 write_whitelist->push_back(kDevNvhostGr2dPath); | |
| 541 write_whitelist->push_back(kDevNvhostGr3dPath); | |
| 542 write_whitelist->push_back(kDevNvhostIspPath); | |
| 543 write_whitelist->push_back(kDevNvhostViPath); | |
| 544 write_whitelist->push_back(kDevNvmapPath); | |
| 545 write_whitelist->push_back(kDevTegraSemaPath); | |
| 546 } | |
| 547 | |
| 548 void AddArmGpuWhitelist(std::vector<std::string>* read_whitelist, | |
| 549 std::vector<std::string>* write_whitelist) { | |
| 550 // On ARM we're enabling the sandbox before the X connection is made, | |
| 551 // so we need to allow access to |.Xauthority|. | |
| 552 static const char kXAuthorityPath[] = "/home/chronos/.Xauthority"; | |
| 553 static const char kLdSoCache[] = "/etc/ld.so.cache"; | |
| 554 | |
| 555 read_whitelist->push_back(kXAuthorityPath); | |
| 556 read_whitelist->push_back(kLdSoCache); | |
| 557 read_whitelist->push_back(kLibGlesPath); | |
| 558 read_whitelist->push_back(kLibEglPath); | |
| 559 | |
| 560 AddArmMaliGpuWhitelist(read_whitelist, write_whitelist); | |
| 561 AddArmTegraGpuWhitelist(read_whitelist, write_whitelist); | |
| 562 } | |
| 563 | |
| 564 // Start a broker process to handle open() inside the sandbox. | |
| 565 void InitGpuBrokerProcess(bool for_chromeos_arm, | |
| 566 BrokerProcess** broker_process) { | |
| 567 static const char kDriRcPath[] = "/etc/drirc"; | |
| 568 static const char kDriCard0Path[] = "/dev/dri/card0"; | |
| 569 | |
| 570 CHECK(broker_process); | |
| 571 CHECK(*broker_process == NULL); | |
| 572 | |
| 573 bool (*sandbox_callback)(void) = NULL; | |
| 574 | |
| 575 // All GPU process policies need these files brokered out. | |
| 576 std::vector<std::string> read_whitelist; | |
| 577 read_whitelist.push_back(kDriCard0Path); | |
| 578 read_whitelist.push_back(kDriRcPath); | |
| 579 | |
| 580 std::vector<std::string> write_whitelist; | |
| 581 write_whitelist.push_back(kDriCard0Path); | |
| 582 | |
| 583 if (for_chromeos_arm) { | |
| 584 // We shouldn't be using this policy on non-ARM architectures. | |
| 585 DCHECK(IsArchitectureArm()); | |
| 586 AddArmGpuWhitelist(&read_whitelist, &write_whitelist); | |
| 587 sandbox_callback = EnableArmGpuBrokerPolicyCallback; | |
| 588 } else { | |
| 589 sandbox_callback = EnableGpuBrokerPolicyCallback; | |
| 590 } | |
| 591 | |
| 592 *broker_process = new BrokerProcess(SandboxBPFBasePolicy::GetFSDeniedErrno(), | |
| 593 read_whitelist, | |
| 594 write_whitelist); | |
| 595 // Initialize the broker process and give it a sandbox callback. | |
| 596 CHECK((*broker_process)->Init(sandbox_callback)); | |
| 597 } | |
| 598 | |
| 599 // Warms up/preloads resources needed by the policies. | |
| 600 // Eventually start a broker process and return it in broker_process. | |
| 601 void WarmupPolicy(bool chromeos_arm_gpu, | |
| 602 BrokerProcess** broker_process) { | |
| 603 if (!chromeos_arm_gpu) { | |
| 604 // Create a new broker process. | |
| 605 InitGpuBrokerProcess(false /* not for ChromeOS ARM */, broker_process); | |
| 606 | |
| 607 if (IsArchitectureX86_64() || IsArchitectureI386()) { | |
| 608 // Accelerated video decode dlopen()'s some shared objects | |
| 609 // inside the sandbox, so preload them now. | |
| 610 if (IsAcceleratedVideoDecodeEnabled()) { | |
| 611 const char* I965DrvVideoPath = NULL; | |
| 612 | |
| 613 if (IsArchitectureX86_64()) { | |
| 614 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; | |
| 615 } else if (IsArchitectureI386()) { | |
| 616 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; | |
| 617 } | |
| 618 | |
| 619 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 620 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 621 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 622 } | |
| 623 } | |
| 624 } else { | |
| 625 // ChromeOS ARM GPU policy. | |
| 626 // Create a new broker process. | |
| 627 InitGpuBrokerProcess(true /* for ChromeOS ARM */, broker_process); | |
| 628 | |
| 629 // Preload the Mali library. | |
| 630 dlopen("/usr/lib/libmali.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 631 | |
| 632 // Preload the Tegra libraries. | |
| 633 dlopen("/usr/lib/libnvrm.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 634 dlopen("/usr/lib/libnvrm_graphics.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 635 dlopen("/usr/lib/libnvos.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 636 dlopen("/usr/lib/libnvddk_2d.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 637 dlopen("/usr/lib/libardrv_dynamic.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 638 dlopen("/usr/lib/libnvwsi.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 639 dlopen("/usr/lib/libnvglsi.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 640 dlopen("/usr/lib/libcgdrv.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
| 641 } | |
| 642 } | |
| 643 | |
| 644 void StartGpuProcessSandbox(const CommandLine& command_line, | |
| 645 const std::string& process_type) { | |
| 646 bool chromeos_arm_gpu = false; | |
| 647 bool allow_sysv_shm = false; | |
| 648 | |
| 649 if (process_type == switches::kGpuProcess) { | |
| 650 // On Chrome OS ARM, we need a specific GPU process policy. | |
| 651 if (IsChromeOS() && IsArchitectureArm()) { | |
| 652 chromeos_arm_gpu = true; | |
| 653 if (command_line.HasSwitch(switches::kGpuSandboxAllowSysVShm)) { | |
| 654 allow_sysv_shm = true; | |
| 655 } | |
| 656 } | |
| 657 } | |
| 658 | |
| 659 // This should never be destroyed, as after the sandbox is started it is | |
| 660 // vital to the process. Ownership is transfered to the policies and then to | |
| 661 // the BPF sandbox which will keep it around to service SIGSYS traps from the | |
| 662 // kernel. | |
| 663 BrokerProcess* broker_process = NULL; | |
| 664 // Warm up resources needed by the policy we're about to enable and | |
| 665 // eventually start a broker process. | |
| 666 WarmupPolicy(chromeos_arm_gpu, &broker_process); | |
| 667 | |
| 668 scoped_ptr<SandboxBPFBasePolicy> gpu_policy; | |
| 669 if (chromeos_arm_gpu) { | |
| 670 gpu_policy.reset(new ArmGpuProcessPolicy(broker_process, allow_sysv_shm)); | |
| 671 } else { | |
| 672 gpu_policy.reset(new GpuProcessPolicy(broker_process)); | |
| 673 } | |
| 674 StartSandboxWithPolicy(gpu_policy.release()); | |
| 675 } | |
| 676 | 279 |
| 677 // This function takes ownership of |policy|. | 280 // This function takes ownership of |policy|. |
| 678 void StartSandboxWithPolicy(sandbox::SandboxBPFPolicy* policy) { | 281 void StartSandboxWithPolicy(sandbox::SandboxBPFPolicy* policy) { |
| 679 // Starting the sandbox is a one-way operation. The kernel doesn't allow | 282 // Starting the sandbox is a one-way operation. The kernel doesn't allow |
| 680 // us to unload a sandbox policy after it has been started. Nonetheless, | 283 // us to unload a sandbox policy after it has been started. Nonetheless, |
| 681 // in order to make the use of the "Sandbox" object easier, we allow for | 284 // in order to make the use of the "Sandbox" object easier, we allow for |
| 682 // the object to be destroyed after the sandbox has been started. Note that | 285 // the object to be destroyed after the sandbox has been started. Note that |
| 683 // doing so does not stop the sandbox. | 286 // doing so does not stop the sandbox. |
| 684 SandboxBPF sandbox; | 287 SandboxBPF sandbox; |
| 685 sandbox.SetSandboxPolicy(policy); | 288 sandbox.SetSandboxPolicy(policy); |
| 686 sandbox.StartSandbox(); | 289 sandbox.StartSandbox(); |
| 687 } | 290 } |
| 688 | 291 |
| 689 void StartNonGpuSandbox(const std::string& process_type) { | 292 // nacl_helper needs to be tiny and includes only part of content/ |
| 293 // in its dependencies. Make sure to not link things that are not needed. | |
| 294 #if !defined(IN_NACL_HELPER) | |
| 295 scoped_ptr<SandboxBPFBasePolicy> GetGpuProcessSandbox() { | |
| 296 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 297 bool allow_sysv_shm = false; | |
| 298 if (command_line.HasSwitch(switches::kGpuSandboxAllowSysVShm)) { | |
| 299 DCHECK(IsArchitectureArm()); | |
| 300 allow_sysv_shm = true; | |
| 301 } | |
| 302 | |
| 303 if (IsChromeOS() && IsArchitectureArm()) { | |
| 304 return scoped_ptr<SandboxBPFBasePolicy>( | |
| 305 new CrosArmGpuProcessPolicy(allow_sysv_shm)); | |
| 306 } else { | |
| 307 return scoped_ptr<SandboxBPFBasePolicy>(new GpuProcessPolicy); | |
| 308 } | |
| 309 } | |
| 310 | |
| 311 // Initialize the seccomp-bpf sandbox. | |
| 312 bool StartBPFSandbox(const CommandLine& command_line, | |
| 313 const std::string& process_type) { | |
| 690 scoped_ptr<SandboxBPFBasePolicy> policy; | 314 scoped_ptr<SandboxBPFBasePolicy> policy; |
| 691 | 315 |
| 692 if (process_type == switches::kRendererProcess || | 316 if (process_type == switches::kGpuProcess) { |
| 693 process_type == switches::kWorkerProcess) { | 317 policy.reset(GetGpuProcessSandbox().release()); |
| 318 } else if (process_type == switches::kRendererProcess || | |
| 319 process_type == switches::kWorkerProcess) { | |
| 694 policy.reset(new RendererOrWorkerProcessPolicy); | 320 policy.reset(new RendererOrWorkerProcessPolicy); |
| 695 } else if (process_type == switches::kPpapiPluginProcess) { | 321 } else if (process_type == switches::kPpapiPluginProcess) { |
| 696 policy.reset(new FlashProcessPolicy); | 322 policy.reset(new FlashProcessPolicy); |
| 697 } else if (process_type == switches::kUtilityProcess) { | 323 } else if (process_type == switches::kUtilityProcess) { |
| 698 policy.reset(new BlacklistDebugAndNumaPolicy); | 324 policy.reset(new BlacklistDebugAndNumaPolicy); |
| 699 } else { | 325 } else { |
| 700 NOTREACHED(); | 326 NOTREACHED(); |
| 701 policy.reset(new AllowAllPolicy); | 327 policy.reset(new AllowAllPolicy); |
| 702 } | 328 } |
| 703 | 329 |
| 330 CHECK(policy->PreSandboxHook()); | |
| 704 StartSandboxWithPolicy(policy.release()); | 331 StartSandboxWithPolicy(policy.release()); |
| 705 } | |
| 706 | |
| 707 // Initialize the seccomp-bpf sandbox. | |
| 708 bool StartBPFSandbox(const CommandLine& command_line, | |
| 709 const std::string& process_type) { | |
| 710 | |
| 711 if (process_type == switches::kGpuProcess) { | |
| 712 StartGpuProcessSandbox(command_line, process_type); | |
| 713 } else { | |
| 714 StartNonGpuSandbox(process_type); | |
| 715 } | |
| 716 | 332 |
| 717 RunSandboxSanityChecks(process_type); | 333 RunSandboxSanityChecks(process_type); |
| 718 return true; | 334 return true; |
| 719 } | 335 } |
| 336 #else // defined(IN_NACL_HELPER) | |
| 337 bool StartBPFSandbox(const CommandLine& command_line, | |
| 338 const std::string& process_type) { | |
| 339 NOTREACHED(); | |
| 340 return false; | |
|
Mark Seaborn
2013/12/13 01:08:47
Redundant when there's another return later? It l
jln (very slow on Chromium)
2013/12/13 01:31:31
It was to make it absolutely clear that what's bel
| |
| 341 // Avoid -Wunused-function with clearly dead code. | |
| 342 ignore_result(IsChromeOS); | |
| 343 ignore_result(IsArchitectureArm); | |
| 344 ignore_result(RunSandboxSanityChecks); | |
| 345 return false; | |
| 346 } | |
| 347 #endif // !defined(IN_NACL_HELPER) | |
| 720 | 348 |
| 721 } // namespace | 349 } // namespace |
| 722 | 350 |
| 723 #endif // SECCOMP_BPF_SANDBOX | 351 #endif // SECCOMP_BPF_SANDBOX |
| 724 | 352 |
| 725 // Is seccomp BPF globally enabled? | 353 // Is seccomp BPF globally enabled? |
| 726 bool SandboxSeccompBPF::IsSeccompBPFDesired() { | 354 bool SandboxSeccompBPF::IsSeccompBPFDesired() { |
| 727 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 355 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 728 if (!command_line.HasSwitch(switches::kNoSandbox) && | 356 if (!command_line.HasSwitch(switches::kNoSandbox) && |
| 729 !command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) { | 357 !command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 scoped_ptr<sandbox::SandboxBPFPolicy> | 422 scoped_ptr<sandbox::SandboxBPFPolicy> |
| 795 SandboxSeccompBPF::GetBaselinePolicy() { | 423 SandboxSeccompBPF::GetBaselinePolicy() { |
| 796 #if defined(SECCOMP_BPF_SANDBOX) | 424 #if defined(SECCOMP_BPF_SANDBOX) |
| 797 return scoped_ptr<sandbox::SandboxBPFPolicy>(new BaselinePolicy); | 425 return scoped_ptr<sandbox::SandboxBPFPolicy>(new BaselinePolicy); |
| 798 #else | 426 #else |
| 799 return scoped_ptr<sandbox::SandboxBPFPolicy>(); | 427 return scoped_ptr<sandbox::SandboxBPFPolicy>(); |
| 800 #endif // defined(SECCOMP_BPF_SANDBOX) | 428 #endif // defined(SECCOMP_BPF_SANDBOX) |
| 801 } | 429 } |
| 802 | 430 |
| 803 } // namespace content | 431 } // namespace content |
| OLD | NEW |