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

Side by Side Diff: content/common/sandbox_seccomp_bpf_linux.cc

Issue 10837135: Factor common syscall from GPU and Flash policies (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/audit.h> 9 #include <linux/audit.h>
10 #include <linux/filter.h> 10 #include <linux/filter.h>
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 if (strcmp(pathname, kDriRcPath) == 0) { 220 if (strcmp(pathname, kDriRcPath) == 0) {
221 int ret = OpenWithCache(pathname, flags); 221 int ret = OpenWithCache(pathname, flags);
222 return (ret == -1) ? -errno : ret; 222 return (ret == -1) ? -errno : ret;
223 } else { 223 } else {
224 return -ENOENT; 224 return -ENOENT;
225 } 225 }
226 } 226 }
227 227
228 #if defined(__x86_64__) 228 #if defined(__x86_64__)
229 // x86_64 only because it references system calls that are multiplexed on IA32. 229 // x86_64 only because it references system calls that are multiplexed on IA32.
230 bool IsGpuAndFlashPolicyAllowed_x86_64(int sysno) {
231 switch (sysno) {
232 case __NR_brk:
233 case __NR_clone: // TODO(jln) restrict flags.
234 case __NR_close:
235 case __NR_dup:
236 case __NR_epoll_create:
237 case __NR_epoll_ctl:
238 case __NR_epoll_wait:
239 case __NR_exit:
240 case __NR_exit_group:
241 case __NR_fcntl:
242 case __NR_fstat:
243 case __NR_futex:
244 case __NR_getegid:
Chris Evans 2012/08/07 06:43:45 Should we start preparing for the renderer policy
jln (very slow on Chromium) 2012/08/07 08:02:41 Done in the following CL. I went through every x86
245 case __NR_geteuid:
246 case __NR_getgid:
247 case __NR_gettid:
248 case __NR_getuid:
249 case __NR_lseek:
250 case __NR_madvise:
251 case __NR_mmap:
Chris Evans 2012/08/07 06:43:45 Unrelated to this CL I know, but maybe a TODO here
jln (very slow on Chromium) 2012/08/07 08:02:41 Yes, good point. There are quite a few where we'll
252 case __NR_mprotect:
253 case __NR_munmap:
254 case __NR_pipe:
255 case __NR_prctl:
256 case __NR_read:
257 case __NR_recvmsg:
258 case __NR_restart_syscall:
259 case __NR_rt_sigaction: // Breakpad signal handler.
260 case __NR_rt_sigprocmask:
261 case __NR_rt_sigreturn:
262 case __NR_sched_yield:
263 case __NR_sendmsg:
264 case __NR_set_robust_list:
265 case __NR_shutdown:
266 case __NR_socketpair:
267 case __NR_write:
268 return true;
269 default:
270 if (IsGettimeSyscall(sysno) ||
271 IsKillSyscall(sysno)) {
272 return true;
273 } else {
274 return false;
275 }
276 }
277 }
278
279 // x86_64 only because it references system calls that are multiplexed on IA32.
230 playground2::Sandbox::ErrorCode GpuProcessPolicy_x86_64(int sysno) { 280 playground2::Sandbox::ErrorCode GpuProcessPolicy_x86_64(int sysno) {
231 switch(sysno) { 281 switch(sysno) {
232 case __NR_read: 282 case __NR_eventfd2:
283 case __NR_getpid: // Nvidia binary driver.
284 case __NR_getppid: // ATI binary driver.
233 case __NR_ioctl: 285 case __NR_ioctl:
234 case __NR_poll:
235 case __NR_epoll_wait:
236 case __NR_recvfrom:
237 case __NR_write:
238 case __NR_writev:
239 case __NR_gettid:
240 case __NR_sched_yield: // Nvidia binary driver.
241
242 case __NR_futex:
243 case __NR_madvise:
244 case __NR_sendmsg:
245 case __NR_recvmsg:
246 case __NR_eventfd2:
247 case __NR_pipe:
248 case __NR_mmap:
249 case __NR_mprotect:
250 case __NR_clone: // TODO(jln) restrict flags.
251 case __NR_set_robust_list:
252 case __NR_getuid:
253 case __NR_geteuid:
254 case __NR_getgid:
255 case __NR_getegid:
256 case __NR_epoll_create:
257 case __NR_fcntl:
258 case __NR_socketpair:
259 case __NR_epoll_ctl:
260 case __NR_prctl:
261 case __NR_fstat:
262 case __NR_close:
263 case __NR_restart_syscall:
264 case __NR_rt_sigreturn:
265 case __NR_brk:
266 case __NR_rt_sigprocmask:
267 case __NR_munmap:
268 case __NR_dup:
269 case __NR_mlock: 286 case __NR_mlock:
270 case __NR_munlock: 287 case __NR_munlock:
271 case __NR_exit: 288 case __NR_poll:
272 case __NR_exit_group: 289 case __NR_recvfrom:
273 case __NR_lseek: 290 case __NR_writev:
274 case __NR_getpid: // Nvidia binary driver.
275 case __NR_getppid: // ATI binary driver.
276 case __NR_shutdown: // Virtual driver.
277 case __NR_rt_sigaction: // Breakpad signal handler.
278 return playground2::Sandbox::SB_ALLOWED; 291 return playground2::Sandbox::SB_ALLOWED;
279 case __NR_socket: 292 case __NR_socket:
280 return EACCES; // Nvidia binary driver. 293 return EACCES; // Nvidia binary driver.
281 case __NR_fchmod: 294 case __NR_fchmod:
282 return EPERM; // ATI binary driver. 295 return EPERM; // ATI binary driver.
283 case __NR_open: 296 case __NR_open:
284 // Accelerated video decode is enabled by default only on Chrome OS. 297 // Accelerated video decode is enabled by default only on Chrome OS.
285 if (IsAcceleratedVideoDecodeEnabled()) { 298 if (IsAcceleratedVideoDecodeEnabled()) {
286 // Accelerated video decode needs to open /dev/dri/card0, and 299 // Accelerated video decode needs to open /dev/dri/card0, and
287 // dup()'ing an already open file descriptor does not work. 300 // dup()'ing an already open file descriptor does not work.
288 // Allow open() even though it severely weakens the sandbox, 301 // Allow open() even though it severely weakens the sandbox,
289 // to test the sandboxing mechanism in general. 302 // to test the sandboxing mechanism in general.
290 // TODO(jorgelo): remove this once we solve the libva issue. 303 // TODO(jorgelo): remove this once we solve the libva issue.
291 return playground2::Sandbox::SB_ALLOWED; 304 return playground2::Sandbox::SB_ALLOWED;
292 } else { 305 } else {
293 // Hook open() in the GPU process to allow opening /etc/drirc, 306 // Hook open() in the GPU process to allow opening /etc/drirc,
294 // needed by Mesa. 307 // needed by Mesa.
295 // The hook needs dup(), lseek(), and close() to be allowed. 308 // The hook needs dup(), lseek(), and close() to be allowed.
296 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL); 309 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL);
297 } 310 }
298 default: 311 default:
299 if (IsGettimeSyscall(sysno) || 312 if (IsGpuAndFlashPolicyAllowed_x86_64(sysno)) {
300 IsKillSyscall(sysno)) { // GPU watchdog.
301 return playground2::Sandbox::SB_ALLOWED; 313 return playground2::Sandbox::SB_ALLOWED;
302 } 314 }
303 // Generally, filename-based syscalls will fail with ENOENT to behave 315 // Generally, filename-based syscalls will fail with ENOENT to behave
304 // similarly to a possible future setuid sandbox. 316 // similarly to a possible future setuid sandbox.
305 if (IsFileSystemSyscall(sysno)) { 317 if (IsFileSystemSyscall(sysno)) {
306 return ENOENT; 318 return ENOENT;
307 } 319 }
308 // In any other case crash the program with our SIGSYS handler 320 // In any other case crash the program with our SIGSYS handler
309 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); 321 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL);
310 } 322 }
311 } 323 }
312 324
313 // x86_64 only because it references system calls that are multiplexed on IA32. 325 // x86_64 only because it references system calls that are multiplexed on IA32.
314 playground2::Sandbox::ErrorCode FlashProcessPolicy_x86_64(int sysno) { 326 playground2::Sandbox::ErrorCode FlashProcessPolicy_x86_64(int sysno) {
315 switch (sysno) { 327 switch (sysno) {
316 case __NR_futex:
317 case __NR_write:
318 case __NR_epoll_wait:
319 case __NR_read:
320 case __NR_times:
321 case __NR_clone: // TODO(jln): restrict flags.
322 case __NR_set_robust_list:
323 case __NR_getuid:
324 case __NR_geteuid:
325 case __NR_getgid:
326 case __NR_getegid:
327 case __NR_epoll_create:
328 case __NR_fcntl:
329 case __NR_socketpair:
330 case __NR_pipe:
331 case __NR_epoll_ctl:
332 case __NR_gettid:
333 case __NR_prctl:
334 case __NR_fstat:
335 case __NR_sendmsg:
336 case __NR_mmap:
337 case __NR_munmap:
338 case __NR_mprotect:
339 case __NR_madvise:
340 case __NR_rt_sigaction:
341 case __NR_rt_sigprocmask:
342 case __NR_wait4:
343 case __NR_exit_group:
344 case __NR_exit:
345 case __NR_rt_sigreturn:
346 case __NR_restart_syscall:
347 case __NR_close:
348 case __NR_recvmsg:
349 case __NR_lseek:
350 case __NR_brk:
351 case __NR_sched_yield:
352 case __NR_shutdown:
353 case __NR_sched_getaffinity: 328 case __NR_sched_getaffinity:
354 case __NR_sched_setscheduler: 329 case __NR_sched_setscheduler:
355 case __NR_dup: // Flash Access.
356 // These are under investigation, and hopefully not here for the long term. 330 // These are under investigation, and hopefully not here for the long term.
331 case __NR_shmat:
357 case __NR_shmctl: 332 case __NR_shmctl:
358 case __NR_shmat:
359 case __NR_shmdt: 333 case __NR_shmdt:
334 case __NR_times:
Chris Evans 2012/08/07 06:43:45 Should we just fold times() into IsGettimeSyscall(
jln (very slow on Chromium) 2012/08/07 08:02:41 It is actually in my "global process environment"
335 case __NR_wait4:
360 return playground2::Sandbox::SB_ALLOWED; 336 return playground2::Sandbox::SB_ALLOWED;
361 case __NR_ioctl: 337 case __NR_ioctl:
362 return ENOTTY; // Flash Access. 338 return ENOTTY; // Flash Access.
363 case __NR_socket: 339 case __NR_socket:
364 return EACCES; 340 return EACCES;
365 default: 341 default:
366 if (IsGettimeSyscall(sysno) || 342 if (IsGpuAndFlashPolicyAllowed_x86_64(sysno)) {
367 IsKillSyscall(sysno)) {
368 return playground2::Sandbox::SB_ALLOWED; 343 return playground2::Sandbox::SB_ALLOWED;
369 } 344 }
370 if (IsFileSystemSyscall(sysno)) { 345 if (IsFileSystemSyscall(sysno)) {
371 return ENOENT; 346 return ENOENT;
372 } 347 }
373 // In any other case crash the program with our SIGSYS handler. 348 // In any other case crash the program with our SIGSYS handler.
374 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); 349 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL);
375 } 350 }
376 } 351 }
377 #endif 352 #endif
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 // Process-specific policy. 514 // Process-specific policy.
540 ShouldEnableSeccompBpf(process_type) && 515 ShouldEnableSeccompBpf(process_type) &&
541 SupportsSandbox()) { 516 SupportsSandbox()) {
542 return StartBpfSandbox_x86(command_line, process_type); 517 return StartBpfSandbox_x86(command_line, process_type);
543 } 518 }
544 #endif 519 #endif
545 return false; 520 return false;
546 } 521 }
547 522
548 } // namespace content 523 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698