| 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 <string> | 15 #include <string> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/bind.h" |
| 18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 19 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
| 20 #include "base/logging.h" | 21 #include "base/logging.h" |
| 21 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
| 22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 23 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" | 24 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" |
| 24 #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" |
| 25 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 26 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" | 28 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" |
| 27 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 29 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| 28 #include "sandbox/linux/services/broker_process.h" | 30 #include "sandbox/linux/services/broker_process.h" |
| 29 #include "sandbox/linux/services/linux_syscalls.h" | 31 #include "sandbox/linux/services/linux_syscalls.h" |
| 30 | 32 |
| 31 using sandbox::BrokerProcess; | 33 using sandbox::BrokerProcess; |
| 32 using sandbox::ErrorCode; | 34 using sandbox::ErrorCode; |
| 33 using sandbox::SandboxBPF; | 35 using sandbox::SandboxBPF; |
| 34 using sandbox::SyscallSets; | 36 using sandbox::SyscallSets; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 switch (sysno) { | 131 switch (sysno) { |
| 130 case __NR_access: | 132 case __NR_access: |
| 131 case __NR_open: | 133 case __NR_open: |
| 132 case __NR_openat: | 134 case __NR_openat: |
| 133 return ErrorCode(ErrorCode::ERR_ALLOWED); | 135 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 134 default: | 136 default: |
| 135 return GpuProcessPolicy::EvaluateSyscall(sandbox, sysno); | 137 return GpuProcessPolicy::EvaluateSyscall(sandbox, sysno); |
| 136 } | 138 } |
| 137 } | 139 } |
| 138 | 140 |
| 139 bool EnableGpuBrokerPolicyCallback() { | 141 void UpdateProcessTypeToGpuBroker() { |
| 140 return SandboxSeccompBPF::StartSandboxWithExternalPolicy( | 142 CommandLine::StringVector exec = CommandLine::ForCurrentProcess()->GetArgs(); |
| 141 scoped_ptr<sandbox::SandboxBPFPolicy>(new GpuBrokerProcessPolicy)); | 143 CommandLine::Reset(); |
| 144 CommandLine::Init(0, NULL); |
| 145 CommandLine::ForCurrentProcess()->InitFromArgv(exec); |
| 146 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kProcessType, |
| 147 "gpu-broker"); |
| 148 |
| 149 // Update the process title. The argv was already cached by the call to |
| 150 // SetProcessTitleFromCommandLine in content_main_runner.cc, so we can pass |
| 151 // NULL here (we don't have the original argv at this point). |
| 152 SetProcessTitleFromCommandLine(NULL); |
| 153 } |
| 154 |
| 155 bool UpdateProcessTypeAndEnableSandbox( |
| 156 const base::Callback<bool(void)>& broker_sandboxer_callback) { |
| 157 UpdateProcessTypeToGpuBroker(); |
| 158 return broker_sandboxer_callback.Run(); |
| 142 } | 159 } |
| 143 | 160 |
| 144 } // namespace | 161 } // namespace |
| 145 | 162 |
| 146 GpuProcessPolicy::GpuProcessPolicy() : broker_process_(NULL) {} | 163 GpuProcessPolicy::GpuProcessPolicy() : broker_process_(NULL) {} |
| 147 | 164 |
| 148 GpuProcessPolicy::~GpuProcessPolicy() {} | 165 GpuProcessPolicy::~GpuProcessPolicy() {} |
| 149 | 166 |
| 150 // Main policy for x86_64/i386. Extended by CrosArmGpuProcessPolicy. | 167 // Main policy for x86_64/i386. Extended by CrosArmGpuProcessPolicy. |
| 151 ErrorCode GpuProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox, | 168 ErrorCode GpuProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 181 bool GpuProcessPolicy::PreSandboxHook() { | 198 bool GpuProcessPolicy::PreSandboxHook() { |
| 182 // Warm up resources needed by the policy we're about to enable and | 199 // Warm up resources needed by the policy we're about to enable and |
| 183 // eventually start a broker process. | 200 // eventually start a broker process. |
| 184 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm(); | 201 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm(); |
| 185 // This policy is for x86 or Desktop. | 202 // This policy is for x86 or Desktop. |
| 186 DCHECK(!chromeos_arm_gpu); | 203 DCHECK(!chromeos_arm_gpu); |
| 187 | 204 |
| 188 DCHECK(!broker_process()); | 205 DCHECK(!broker_process()); |
| 189 // Create a new broker process. | 206 // Create a new broker process. |
| 190 InitGpuBrokerProcess( | 207 InitGpuBrokerProcess( |
| 191 EnableGpuBrokerPolicyCallback, | 208 base::Bind(&SandboxSeccompBPF::StartSandboxWithExternalPolicy, |
| 209 base::Passed(scoped_ptr<sandbox::SandboxBPFPolicy>( |
| 210 new GpuBrokerProcessPolicy))), |
| 192 std::vector<std::string>(), // No extra files in whitelist. | 211 std::vector<std::string>(), // No extra files in whitelist. |
| 193 std::vector<std::string>()); | 212 std::vector<std::string>()); |
| 194 | 213 |
| 195 if (IsArchitectureX86_64() || IsArchitectureI386()) { | 214 if (IsArchitectureX86_64() || IsArchitectureI386()) { |
| 196 // Accelerated video decode dlopen()'s some shared objects | 215 // Accelerated video decode dlopen()'s some shared objects |
| 197 // inside the sandbox, so preload them now. | 216 // inside the sandbox, so preload them now. |
| 198 if (IsAcceleratedVideoDecodeEnabled()) { | 217 if (IsAcceleratedVideoDecodeEnabled()) { |
| 199 const char* I965DrvVideoPath = NULL; | 218 const char* I965DrvVideoPath = NULL; |
| 200 | 219 |
| 201 if (IsArchitectureX86_64()) { | 220 if (IsArchitectureX86_64()) { |
| 202 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; | 221 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; |
| 203 } else if (IsArchitectureI386()) { | 222 } else if (IsArchitectureI386()) { |
| 204 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; | 223 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; |
| 205 } | 224 } |
| 206 | 225 |
| 207 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 226 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 208 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 227 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 209 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 228 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 210 } | 229 } |
| 211 } | 230 } |
| 212 | 231 |
| 213 return true; | 232 return true; |
| 214 } | 233 } |
| 215 | 234 |
| 216 void GpuProcessPolicy::InitGpuBrokerProcess( | 235 void GpuProcessPolicy::InitGpuBrokerProcess( |
| 217 bool (*broker_sandboxer_callback)(void), | 236 const base::Callback<bool(void)>& broker_sandboxer_callback, |
| 218 const std::vector<std::string>& read_whitelist_extra, | 237 const std::vector<std::string>& read_whitelist_extra, |
| 219 const std::vector<std::string>& write_whitelist_extra) { | 238 const std::vector<std::string>& write_whitelist_extra) { |
| 220 static const char kDriRcPath[] = "/etc/drirc"; | 239 static const char kDriRcPath[] = "/etc/drirc"; |
| 221 static const char kDriCard0Path[] = "/dev/dri/card0"; | 240 static const char kDriCard0Path[] = "/dev/dri/card0"; |
| 222 | 241 |
| 223 CHECK(broker_process_ == NULL); | 242 CHECK(broker_process_ == NULL); |
| 224 | 243 |
| 225 // All GPU process policies need these files brokered out. | 244 // All GPU process policies need these files brokered out. |
| 226 std::vector<std::string> read_whitelist; | 245 std::vector<std::string> read_whitelist; |
| 227 read_whitelist.push_back(kDriCard0Path); | 246 read_whitelist.push_back(kDriCard0Path); |
| 228 read_whitelist.push_back(kDriRcPath); | 247 read_whitelist.push_back(kDriRcPath); |
| 229 // Add eventual extra files from read_whitelist_extra. | 248 // Add eventual extra files from read_whitelist_extra. |
| 230 read_whitelist.insert(read_whitelist.end(), | 249 read_whitelist.insert(read_whitelist.end(), |
| 231 read_whitelist_extra.begin(), | 250 read_whitelist_extra.begin(), |
| 232 read_whitelist_extra.end()); | 251 read_whitelist_extra.end()); |
| 233 | 252 |
| 234 std::vector<std::string> write_whitelist; | 253 std::vector<std::string> write_whitelist; |
| 235 write_whitelist.push_back(kDriCard0Path); | 254 write_whitelist.push_back(kDriCard0Path); |
| 236 // Add eventual extra files from write_whitelist_extra. | 255 // Add eventual extra files from write_whitelist_extra. |
| 237 write_whitelist.insert(write_whitelist.end(), | 256 write_whitelist.insert(write_whitelist.end(), |
| 238 write_whitelist_extra.begin(), | 257 write_whitelist_extra.begin(), |
| 239 write_whitelist_extra.end()); | 258 write_whitelist_extra.end()); |
| 240 | 259 |
| 241 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), | 260 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), |
| 242 read_whitelist, | 261 read_whitelist, |
| 243 write_whitelist); | 262 write_whitelist); |
| 244 // Initialize the broker process and give it a sandbox callback. | 263 // The initialization callback will perform generic initialization and then |
| 245 CHECK(broker_process_->Init(broker_sandboxer_callback)); | 264 // call broker_sandboxer_callback. |
| 265 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, |
| 266 broker_sandboxer_callback))); |
| 246 } | 267 } |
| 247 | 268 |
| 248 } // namespace content | 269 } // namespace content |
| OLD | NEW |