Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: content/common/sandbox_linux/bpf_gpu_policy_linux.cc

Issue 163433011: Clarify the process title of GPU broker process. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Build fix for unittests Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 GpuBrokerChildInitCallback(
jln (very slow on Chromium) 2014/02/20 23:38:52 Sorry for my earlier recommendation, but given how
dshwang 2014/02/21 07:03:13 done.
156 const base::Callback<bool(void)>& gpu_broker_child_init_callback) {
157 UpdateProcessTypeToGpuBroker();
158 return gpu_broker_child_init_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
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(
209 &SandboxSeccompBPF::StartSandboxWithExternalPolicy,
210 base::Passed(scoped_ptr<sandbox::SandboxBPFPolicy>(
211 new GpuBrokerProcessPolicy))),
192 std::vector<std::string>(), // No extra files in whitelist. 212 std::vector<std::string>(), // No extra files in whitelist.
193 std::vector<std::string>()); 213 std::vector<std::string>());
194 214
195 if (IsArchitectureX86_64() || IsArchitectureI386()) { 215 if (IsArchitectureX86_64() || IsArchitectureI386()) {
196 // Accelerated video decode dlopen()'s some shared objects 216 // Accelerated video decode dlopen()'s some shared objects
197 // inside the sandbox, so preload them now. 217 // inside the sandbox, so preload them now.
198 if (IsAcceleratedVideoDecodeEnabled()) { 218 if (IsAcceleratedVideoDecodeEnabled()) {
199 const char* I965DrvVideoPath = NULL; 219 const char* I965DrvVideoPath = NULL;
200 220
201 if (IsArchitectureX86_64()) { 221 if (IsArchitectureX86_64()) {
202 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; 222 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so";
203 } else if (IsArchitectureI386()) { 223 } else if (IsArchitectureI386()) {
204 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; 224 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so";
205 } 225 }
206 226
207 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); 227 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
208 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); 228 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
209 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); 229 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
210 } 230 }
211 } 231 }
212 232
213 return true; 233 return true;
214 } 234 }
215 235
216 void GpuProcessPolicy::InitGpuBrokerProcess( 236 void GpuProcessPolicy::InitGpuBrokerProcess(
217 bool (*broker_sandboxer_callback)(void), 237 const base::Callback<bool(void)>& gpu_broker_child_init_callback,
218 const std::vector<std::string>& read_whitelist_extra, 238 const std::vector<std::string>& read_whitelist_extra,
219 const std::vector<std::string>& write_whitelist_extra) { 239 const std::vector<std::string>& write_whitelist_extra) {
220 static const char kDriRcPath[] = "/etc/drirc"; 240 static const char kDriRcPath[] = "/etc/drirc";
221 static const char kDriCard0Path[] = "/dev/dri/card0"; 241 static const char kDriCard0Path[] = "/dev/dri/card0";
222 242
223 CHECK(broker_process_ == NULL); 243 CHECK(broker_process_ == NULL);
224 244
225 // All GPU process policies need these files brokered out. 245 // All GPU process policies need these files brokered out.
226 std::vector<std::string> read_whitelist; 246 std::vector<std::string> read_whitelist;
227 read_whitelist.push_back(kDriCard0Path); 247 read_whitelist.push_back(kDriCard0Path);
228 read_whitelist.push_back(kDriRcPath); 248 read_whitelist.push_back(kDriRcPath);
229 // Add eventual extra files from read_whitelist_extra. 249 // Add eventual extra files from read_whitelist_extra.
230 read_whitelist.insert(read_whitelist.end(), 250 read_whitelist.insert(read_whitelist.end(),
231 read_whitelist_extra.begin(), 251 read_whitelist_extra.begin(),
232 read_whitelist_extra.end()); 252 read_whitelist_extra.end());
233 253
234 std::vector<std::string> write_whitelist; 254 std::vector<std::string> write_whitelist;
235 write_whitelist.push_back(kDriCard0Path); 255 write_whitelist.push_back(kDriCard0Path);
236 // Add eventual extra files from write_whitelist_extra. 256 // Add eventual extra files from write_whitelist_extra.
237 write_whitelist.insert(write_whitelist.end(), 257 write_whitelist.insert(write_whitelist.end(),
238 write_whitelist_extra.begin(), 258 write_whitelist_extra.begin(),
239 write_whitelist_extra.end()); 259 write_whitelist_extra.end());
240 260
241 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), 261 broker_process_ = new BrokerProcess(GetFSDeniedErrno(),
242 read_whitelist, 262 read_whitelist,
243 write_whitelist); 263 write_whitelist);
244 // Initialize the broker process and give it a sandbox callback. 264 // Initialize the broker process and give it a broker process init callback.
jln (very slow on Chromium) 2014/02/20 23:38:52 Let's add a clarification as this becomes convolut
dshwang 2014/02/21 07:03:13 thank you for good sentence. this part is the most
245 CHECK(broker_process_->Init(broker_sandboxer_callback)); 265 CHECK(broker_process_->Init(
266 base::Bind(&GpuBrokerChildInitCallback, gpu_broker_child_init_callback)));
246 } 267 }
247 268
248 } // namespace content 269 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698