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/audit.h> | 9 #include <linux/audit.h> |
10 #include <linux/filter.h> | 10 #include <linux/filter.h> |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 // case __NR_umask: | 190 // case __NR_umask: |
191 return true; | 191 return true; |
192 default: | 192 default: |
193 return false; | 193 return false; |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 // System calls that directly access the file system. They might aquire | 197 // System calls that directly access the file system. They might aquire |
198 // a new file descriptor or otherwise perform an operation directly | 198 // a new file descriptor or otherwise perform an operation directly |
199 // via a path. | 199 // via a path. |
200 // For many, EPERM is a valid errno, but not for all of them. | 200 // Both EPERM and ENOENT are valid errno unless otherwise noted in comment. |
201 bool IsFileSystemSyscall(int sysno) { | 201 bool IsFileSystemSyscall(int sysno) { |
202 switch (sysno) { | 202 switch (sysno) { |
203 case __NR_access: | 203 case __NR_access: // EPERM not a valid errno. |
204 // case __NR_chmod: | 204 case __NR_chmod: |
205 // case __NR_chown: | 205 case __NR_chown: |
206 // case __NR_creat: | 206 case __NR_creat: |
207 case __NR_execve: | 207 case __NR_execve: |
208 // case __NR_faccessat: | 208 case __NR_faccessat: // EPERM not a valid errno. |
209 // case __NR_fchmodat: | 209 case __NR_fchmodat: |
210 // case __NR_fchownat: // Should be called chownat ? | 210 case __NR_fchownat: // Should be called chownat ? |
211 // case __NR_futimesat: // Should be called utimesat ? | 211 case __NR_futimesat: // Should be called utimesat ? |
212 // case __NR_getdents: | 212 case __NR_getdents: |
213 // case __NR_getdents64: | 213 case __NR_getdents64: |
Chris Evans
2012/08/09 07:09:15
getdents() is not a filesystem syscall. It takes a
jln (very slow on Chromium)
2012/08/09 16:59:12
Oh, wow, I missed that, thanks!
| |
214 // case __NR_lchown: | 214 case __NR_lchown: |
215 // case __NR_link: | 215 case __NR_link: |
216 // case __NR_linkat: | 216 case __NR_linkat: |
217 // case __NR_lookup_dcookie: | 217 case __NR_lookup_dcookie: // ENOENT not a valid errno. |
218 case __NR_lstat: | 218 case __NR_lstat: // EPERM not a valid errno. |
219 case __NR_mkdir: | 219 case __NR_mkdir: |
220 case __NR_mkdirat: | 220 case __NR_mkdirat: |
221 case __NR_mknod: | 221 case __NR_mknod: |
222 case __NR_mknodat: | 222 case __NR_mknodat: |
223 // case __NR_newfstatat: // Should be called statat ? | 223 case __NR_newfstatat: // EPERM not a valid errno. |
224 // Should be called statat ? | |
224 case __NR_open: | 225 case __NR_open: |
225 case __NR_openat: | 226 case __NR_openat: |
226 case __NR_readlink: | 227 case __NR_readlink: // EPERM not a valid errno. |
227 case __NR_readlinkat: | 228 case __NR_readlinkat: |
228 // case __NR_rename: | 229 case __NR_rename: |
229 // case __NR_renameat: | 230 case __NR_renameat: |
230 // case __NR_rmdir: | 231 case __NR_rmdir: |
231 case __NR_stat: | 232 case __NR_stat: // EPERM not a valid errno. |
232 // case __NR_statfs: | 233 case __NR_statfs: // EPERM not a valid errno. |
233 // case __NR_symlink: | 234 case __NR_symlink: |
234 // case __NR_symlinkat: | 235 case __NR_symlinkat: |
235 // case __NR_truncate: | 236 case __NR_truncate: |
236 // case __NR_unlink: | 237 case __NR_unlink: |
237 // case __NR_unlinkat: | 238 case __NR_unlinkat: |
238 // case __NR_uselib: | 239 case __NR_uselib: // Neither EPERM, nor ENOENT are valid errno. |
239 // case __NR_ustat: // Deprecated. | 240 case __NR_ustat: // Same as above. Deprecated. |
240 // case __NR_utime: | 241 case __NR_utime: |
241 // case __NR_utimensat: // New. | 242 case __NR_utimensat: // New. |
Chris Evans
2012/08/09 07:09:15
Will this compile on Ubuntu 10.04 ?
Could you quic
jln (very slow on Chromium)
2012/08/09 16:59:12
This problem was getting annoying, so I solved it
| |
242 // case __NR_utimes: | 243 case __NR_utimes: |
243 return true; | 244 return true; |
244 default: | 245 default: |
245 return false; | 246 return false; |
246 } | 247 } |
247 } | 248 } |
248 | 249 |
250 // TODO(jln): these should be denied gracefully as well. | |
249 bool IsAllowedFileSystemCapabilitySyscall(int sysno) { | 251 bool IsAllowedFileSystemCapabilitySyscall(int sysno) { |
250 switch (sysno) { | 252 switch (sysno) { |
251 // case __NR_fadvise64: | 253 // case __NR_fadvise64: |
252 // case __NR_flock: | 254 // case __NR_flock: |
253 case __NR_fstat: | 255 case __NR_fstat: |
254 // case __NR_fstatfs: // Give information about the whole filesystem. | 256 // case __NR_fstatfs: // Give information about the whole filesystem. |
255 // case __NR_fsync: | 257 // case __NR_fsync: |
256 // case __NR_fdatasync: | 258 // case __NR_fdatasync: |
257 // case __NR_sync_file_range: | 259 // case __NR_sync_file_range: |
258 return true; | 260 return true; |
261 default: | |
262 return false; | |
263 } | |
264 } | |
265 | |
266 // EPERM is a good errno for any of these. | |
267 bool IsDeniedFileSystemCapabilitySyscall(int sysno) { | |
268 switch (sysno) { | |
259 case __NR_fallocate: | 269 case __NR_fallocate: |
260 case __NR_fchmod: | 270 case __NR_fchmod: |
261 case __NR_fchown: | 271 case __NR_fchown: |
262 case __NR_ftruncate: | 272 case __NR_ftruncate: |
273 return true; | |
263 default: | 274 default: |
264 return false; | 275 return false; |
265 } | 276 } |
266 } | 277 } |
267 | 278 |
268 bool IsGetProcessIdSyscall(int sysno) { | 279 bool IsGetProcessIdSyscall(int sysno) { |
Chris Evans
2012/08/09 07:09:15
Not sure about the name. It's getting process ids
jln (very slow on Chromium)
2012/08/09 16:59:12
Done.
| |
269 switch (sysno) { | 280 switch (sysno) { |
270 // case __NR_capget: | 281 // case __NR_capget: |
271 case __NR_getegid: | 282 case __NR_getegid: |
272 case __NR_geteuid: | 283 case __NR_geteuid: |
273 case __NR_getgid: | 284 case __NR_getgid: |
274 // case __NR_getgroups: | 285 case __NR_getgroups: |
275 // case __NR_getpid: | 286 case __NR_getpid: |
276 // case __NR_getppid: | 287 case __NR_getppid: |
277 // case __NR_getresgid: | 288 case __NR_getresgid: |
278 // case __NR_getresuid: | 289 case __NR_getresuid: |
279 // case __NR_getsid: | 290 case __NR_getsid: |
280 case __NR_gettid: | 291 case __NR_gettid: |
281 case __NR_getuid: | 292 case __NR_getuid: |
282 return true; | 293 return true; |
283 default: | 294 default: |
284 return false; | 295 return false; |
285 } | 296 } |
286 } | 297 } |
287 | 298 |
288 bool IsProcessPrivilegeChange(int sysno) { | 299 bool IsProcessPrivilegeChange(int sysno) { |
289 switch (sysno) { | 300 switch (sysno) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 return true; | 344 return true; |
334 default: | 345 default: |
335 return false; | 346 return false; |
336 } | 347 } |
337 } | 348 } |
338 | 349 |
339 bool IsOperationOnFd(int sysno) { | 350 bool IsOperationOnFd(int sysno) { |
340 switch (sysno) { | 351 switch (sysno) { |
341 case __NR_close: | 352 case __NR_close: |
342 case __NR_dup: | 353 case __NR_dup: |
343 // case __NR_dup2: | 354 case __NR_dup2: |
344 // case __NR_dup3: | 355 case __NR_dup3: |
345 case __NR_fcntl: | 356 case __NR_fcntl: |
Chris Evans
2012/08/09 07:09:15
Might as well add the TODO on fcntl() arg lockdown
jln (very slow on Chromium)
2012/08/09 16:59:12
Yeah, not on the top of the list but worth investi
| |
346 case __NR_shutdown: | 357 case __NR_shutdown: |
347 return true; | 358 return true; |
348 default: | 359 default: |
349 return false; | 360 return false; |
350 } | 361 } |
351 } | 362 } |
352 | 363 |
353 bool IsKernelInteralApi(int sysno) { | 364 bool IsKernelInteralApi(int sysno) { |
354 switch (sysno) { | 365 switch (sysno) { |
355 case __NR_restart_syscall: | 366 case __NR_restart_syscall: |
356 return true; | 367 return true; |
357 default: | 368 default: |
358 return false; | 369 return false; |
359 } | 370 } |
360 } | 371 } |
361 | 372 |
373 // This should be thought through in conjunction with IsFutex(). | |
362 bool IsAllowedProcessStartOrDeath(int sysno) { | 374 bool IsAllowedProcessStartOrDeath(int sysno) { |
363 switch (sysno) { | 375 switch (sysno) { |
364 case __NR_clone: // TODO(jln): restrict flags. | 376 case __NR_clone: // TODO(jln): restrict flags. |
365 case __NR_exit: | 377 case __NR_exit: |
366 case __NR_exit_group: | 378 case __NR_exit_group: |
Chris Evans
2012/08/09 07:09:15
Just an observation: in the generic case, it'll pr
jln (very slow on Chromium)
2012/08/09 16:59:12
I would think the only one we may want to restrict
| |
367 // case __NR_fork: | 379 // case __NR_fork: |
368 // case __NR_get_thread_area: | 380 // case __NR_get_thread_area: |
369 // case __NR_set_thread_area: | 381 // case __NR_set_thread_area: |
370 // case __NR_set_tid_address: | 382 // case __NR_set_tid_address: |
371 // case __NR_unshare: | 383 // case __NR_unshare: |
372 // case __NR_vfork: | 384 // case __NR_vfork: |
373 // case __NR_wait4: | 385 case __NR_wait4: |
374 // case __NR_waitid: | 386 case __NR_waitid: |
375 return true; | 387 return true; |
376 case __NR_setns: // Privileged. | 388 case __NR_setns: // Privileged. |
377 default: | 389 default: |
378 return false; | 390 return false; |
379 } | 391 } |
380 } | 392 } |
381 | 393 |
394 bool IsFutex(int sysno) { | |
395 switch (sysno) { | |
396 case __NR_futex: | |
397 // case __NR_get_robust_list: | |
398 case __NR_set_robust_list: | |
399 return true; | |
400 default: | |
401 return false; | |
402 } | |
403 } | |
404 | |
382 bool IsAllowedEpoll(int sysno) { | 405 bool IsAllowedEpoll(int sysno) { |
383 switch (sysno) { | 406 switch (sysno) { |
384 case __NR_epoll_create: | 407 case __NR_epoll_create: |
385 // case __NR_epoll_create1: | 408 // case __NR_epoll_create1: |
386 case __NR_epoll_ctl: | 409 case __NR_epoll_ctl: |
387 // case __NR_epoll_ctl_old: | 410 // case __NR_epoll_ctl_old: |
388 // case __NR_epoll_pwait: | 411 // case __NR_epoll_pwait: |
389 case __NR_epoll_wait: | 412 case __NR_epoll_wait: |
390 // case __NR_epoll_wait_old: | 413 // case __NR_epoll_wait_old: |
391 return true; | 414 return true; |
(...skipping 12 matching lines...) Expand all Loading... | |
404 case __NR_accept: | 427 case __NR_accept: |
405 case __NR_accept4: | 428 case __NR_accept4: |
406 case __NR_bind: | 429 case __NR_bind: |
407 case __NR_connect: | 430 case __NR_connect: |
408 case __NR_socket: | 431 case __NR_socket: |
409 case __NR_listen: | 432 case __NR_listen: |
410 return false; | 433 return false; |
411 } | 434 } |
412 } | 435 } |
413 | 436 |
414 bool IsNetworkSocketInformation(int sysno) { | 437 bool IsNetworkSocketInformation(int sysno) { |
Chris Evans
2012/08/09 07:09:15
Did the old policies really allow all of these sys
jln (very slow on Chromium)
2012/08/09 16:59:12
None of them is allowed at the moment.
| |
415 switch (sysno) { | 438 switch (sysno) { |
416 case __NR_getpeername: | 439 case __NR_getpeername: |
417 case __NR_getsockname: | 440 case __NR_getsockname: |
418 case __NR_getsockopt: | 441 case __NR_getsockopt: |
419 case __NR_setsockopt: | 442 case __NR_setsockopt: |
Chris Evans
2012/08/09 07:09:15
Ew, need to add a TODO to restrict get/setsockopt.
jln (very slow on Chromium)
2012/08/09 16:59:12
It's not allowed. It's in the "Watched" list.
| |
420 return true; | 443 return true; |
421 default: | 444 default: |
422 return false; | 445 return false; |
423 } | 446 } |
424 } | 447 } |
425 | 448 |
426 bool IsFutex(int sysno) { | |
427 switch (sysno) { | |
428 case __NR_futex: | |
429 // case __NR_get_robust_list: | |
430 case __NR_set_robust_list: | |
431 return true; | |
432 default: | |
433 return false; | |
434 } | |
435 } | |
436 | |
437 bool IsAllowedAddressSpaceAccess(int sysno) { | 449 bool IsAllowedAddressSpaceAccess(int sysno) { |
438 switch (sysno) { | 450 switch (sysno) { |
439 case __NR_brk: | 451 case __NR_brk: |
440 case __NR_madvise: | 452 case __NR_madvise: |
441 // case __NR_mincore: | 453 // case __NR_mincore: |
442 // case __NR_mlock: | 454 case __NR_mlock: |
443 // case __NR_mlockall: | 455 // case __NR_mlockall: |
444 case __NR_mmap: | 456 case __NR_mmap: |
Chris Evans
2012/08/09 07:09:15
TODO: restrict flags etc :)
jln (very slow on Chromium)
2012/08/09 16:59:12
Done.
| |
445 // case __NR_modify_ldt: | 457 // case __NR_modify_ldt: |
446 case __NR_mprotect: | 458 case __NR_mprotect: |
447 // case __NR_mremap: | 459 // case __NR_mremap: |
448 // case __NR_msync: | 460 // case __NR_msync: |
449 // case __NR_munlock: | 461 case __NR_munlock: |
450 // case __NR_munlockall: | 462 // case __NR_munlockall: |
451 case __NR_munmap: | 463 case __NR_munmap: |
452 // case __NR_readahead: | 464 // case __NR_readahead: |
453 // case __NR_remap_file_pages: | 465 // case __NR_remap_file_pages: |
454 return true; | 466 return true; |
455 default: | 467 default: |
456 return false; | 468 return false; |
457 } | 469 } |
458 } | 470 } |
459 | 471 |
460 bool IsAllowedGeneralIo(int sysno) { | 472 bool IsAllowedGeneralIo(int sysno) { |
461 switch (sysno) { | 473 switch (sysno) { |
462 case __NR_lseek: | 474 case __NR_lseek: |
463 // case __NR_poll: | 475 case __NR_poll: |
464 // case __NR_ppoll: | 476 case __NR_ppoll: |
465 // case __NR_pread64: | 477 // case __NR_pread64: |
466 // case __NR_preadv: | 478 // case __NR_preadv: |
467 // case __NR_pselect6: | 479 case __NR_pselect6: |
468 // case __NR_pwrite64: | 480 // case __NR_pwrite64: |
469 // case __NR_pwritev: | 481 // case __NR_pwritev: |
470 case __NR_read: | 482 case __NR_read: |
471 // case __NR_readv: | 483 case __NR_readv: |
472 // case __NR_recvfrom: // Could specify source. | 484 case __NR_recvfrom: // Could specify source. |
Chris Evans
2012/08/09 07:09:15
Did you mean to enable recvfrom?
jln (very slow on Chromium)
2012/08/09 16:59:12
There is a comment in the very first iteration of
| |
473 // case __NR_recvmmsg: // Could specify source. | 485 // case __NR_recvmmsg: // Could specify source. |
474 case __NR_recvmsg: // Could specify source. | 486 case __NR_recvmsg: // Could specify source. |
475 // case __NR_select: | 487 case __NR_select: |
476 // case __NR_sendfile: | 488 // case __NR_sendfile: |
477 // case __NR_sendmmsg: // Could specify destination. | 489 // case __NR_sendmmsg: // Could specify destination. |
478 case __NR_sendmsg: // Could specify destination. | 490 case __NR_sendmsg: // Could specify destination. |
479 // case __NR_sendto: // Could specify destination. | 491 case __NR_sendto: // Could specify destination. |
480 // case __NR_splice: | 492 // case __NR_splice: |
481 // case __NR_tee: | 493 // case __NR_tee: |
482 // case __NR_vmsplice: | 494 // case __NR_vmsplice: |
483 case __NR_write: | 495 case __NR_write: |
484 // case __NR_writev: | 496 case __NR_writev: |
485 return true; | 497 return true; |
486 default: | 498 default: |
487 case __NR_ioctl: // Can be very powerful. | 499 case __NR_ioctl: // Can be very powerful. |
488 return false; | 500 return false; |
489 } | 501 } |
490 } | 502 } |
491 | 503 |
492 bool IsAllowedPrctl(int sysno) { | 504 bool IsAllowedPrctl(int sysno) { |
493 switch (sysno) { | 505 switch (sysno) { |
494 case __NR_prctl: | 506 case __NR_prctl: |
495 // case __NR_arch_prctl: | 507 // case __NR_arch_prctl: |
496 return true; | 508 return true; |
497 default: | 509 default: |
498 return false; | 510 return false; |
499 } | 511 } |
500 } | 512 } |
501 | 513 |
502 bool IsAllowedBasicScheduler(int sysno) { | 514 bool IsAllowedBasicScheduler(int sysno) { |
503 switch (sysno) { | 515 switch (sysno) { |
504 case __NR_sched_yield: | 516 case __NR_sched_yield: |
505 // case __NR_pause: | 517 case __NR_pause: |
506 // case __NR_nanosleep: | 518 case __NR_nanosleep: |
507 // case __NR_getpriority: | 519 // case __NR_getpriority: |
508 return true; | 520 return true; |
509 case __NR_setpriority: | 521 case __NR_setpriority: |
510 default: | 522 default: |
511 return false; | 523 return false; |
512 } | 524 } |
513 } | 525 } |
514 | 526 |
515 bool IsAdminOperation(int sysno) { | 527 bool IsAdminOperation(int sysno) { |
516 switch (sysno) { | 528 switch (sysno) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 case __NR_uname: | 638 case __NR_uname: |
627 return true; | 639 return true; |
628 default: | 640 default: |
629 return false; | 641 return false; |
630 } | 642 } |
631 } | 643 } |
632 | 644 |
633 bool IsEventFd(int sysno) { | 645 bool IsEventFd(int sysno) { |
634 switch (sysno) { | 646 switch (sysno) { |
635 case __NR_eventfd: | 647 case __NR_eventfd: |
636 // case __NR_eventfd2: | 648 case __NR_eventfd2: |
637 return true; | 649 return true; |
638 default: | 650 default: |
639 return false; | 651 return false; |
640 } | 652 } |
641 } | 653 } |
642 | 654 |
643 // Asynchronous I/O API. | 655 // Asynchronous I/O API. |
644 bool IsAsyncIo(int sysno) { | 656 bool IsAsyncIo(int sysno) { |
645 switch (sysno) { | 657 switch (sysno) { |
646 case __NR_io_cancel: | 658 case __NR_io_cancel: |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
808 case __NR_vserver: | 820 case __NR_vserver: |
809 return true; | 821 return true; |
810 default: | 822 default: |
811 return false; | 823 return false; |
812 } | 824 } |
813 } | 825 } |
814 | 826 |
815 // End of the system call sets section. | 827 // End of the system call sets section. |
816 | 828 |
817 // x86_64 only because it references system calls that are multiplexed on IA32. | 829 // x86_64 only because it references system calls that are multiplexed on IA32. |
818 bool IsGpuAndFlashPolicyAllowed_x86_64(int sysno) { | 830 bool IsBaselinePolicyAllowed_x86_64(int sysno) { |
819 if (IsAllowedAddressSpaceAccess(sysno) || | 831 if (IsAllowedAddressSpaceAccess(sysno) || |
820 IsAllowedBasicScheduler(sysno) || | 832 IsAllowedBasicScheduler(sysno) || |
821 IsAllowedEpoll(sysno) || | 833 IsAllowedEpoll(sysno) || |
822 IsAllowedFileSystemCapabilitySyscall(sysno) || | 834 IsAllowedFileSystemCapabilitySyscall(sysno) || |
823 IsAllowedGeneralIo(sysno) || | 835 IsAllowedGeneralIo(sysno) || |
824 IsAllowedGetOrModifySocket(sysno) || | 836 IsAllowedGetOrModifySocket(sysno) || |
825 IsAllowedGettimeSyscall(sysno) || | 837 IsAllowedGettimeSyscall(sysno) || |
826 IsAllowedPrctl(sysno) || | 838 IsAllowedPrctl(sysno) || |
827 IsAllowedProcessStartOrDeath(sysno) || | 839 IsAllowedProcessStartOrDeath(sysno) || |
828 IsAllowedSignalHandling(sysno) || | 840 IsAllowedSignalHandling(sysno) || |
829 IsFutex(sysno) || | 841 IsFutex(sysno) || |
830 IsGetProcessIdSyscall(sysno) || | 842 IsGetProcessIdSyscall(sysno) || |
831 IsKernelInteralApi(sysno) || | 843 IsKernelInteralApi(sysno) || |
832 IsKillSyscall(sysno) || | 844 IsKillSyscall(sysno) || |
833 IsOperationOnFd(sysno)) { | 845 IsOperationOnFd(sysno)) { |
834 return true; | 846 return true; |
835 } else { | 847 } else { |
836 return false; | 848 return false; |
837 } | 849 } |
838 } | 850 } |
839 | 851 |
840 // System calls that will trigger the crashing sigsys handler. | 852 // System calls that will trigger the crashing sigsys handler. |
841 bool IsGpuAndFlashPolicyWatched_x86_64(int sysno) { | 853 bool IsBaselinePolicyWatched_x86_64(int sysno) { |
842 if (IsAdminOperation(sysno) || | 854 if (IsAdminOperation(sysno) || |
843 IsAdvancedScheduler(sysno) || | 855 IsAdvancedScheduler(sysno) || |
844 IsAdvancedTimer(sysno) || | 856 IsAdvancedTimer(sysno) || |
845 IsAsyncIo(sysno) || | 857 IsAsyncIo(sysno) || |
846 IsDebug(sysno) || | 858 IsDebug(sysno) || |
847 IsEventFd(sysno) || | 859 IsEventFd(sysno) || |
848 IsExtendedAttributes(sysno) || | 860 IsExtendedAttributes(sysno) || |
849 IsFaNotify(sysno) || | 861 IsFaNotify(sysno) || |
850 IsFsControl(sysno) || | 862 IsFsControl(sysno) || |
851 IsGlobalFSViewChange(sysno) || | 863 IsGlobalFSViewChange(sysno) || |
(...skipping 11 matching lines...) Expand all Loading... | |
863 IsSystemVMessageQueue(sysno) || | 875 IsSystemVMessageQueue(sysno) || |
864 IsSystemVSemaphores(sysno) || | 876 IsSystemVSemaphores(sysno) || |
865 IsSystemVSharedMemory(sysno) || | 877 IsSystemVSharedMemory(sysno) || |
866 IsTimer(sysno)) { | 878 IsTimer(sysno)) { |
867 return true; | 879 return true; |
868 } else { | 880 } else { |
869 return false; | 881 return false; |
870 } | 882 } |
871 } | 883 } |
872 | 884 |
885 playground2::Sandbox::ErrorCode BaselinePolicy_x86_64(int sysno) { | |
886 if (IsBaselinePolicyAllowed_x86_64(sysno)) { | |
887 return playground2::Sandbox::SB_ALLOWED; | |
888 } | |
889 // TODO(jln): some system calls in those sets are not supposed to | |
890 // return ENOENT. Return the appropriate error. | |
891 if (IsFileSystemSyscall(sysno) || IsAmbientFileSystemSyscall(sysno)) { | |
892 return ENOENT; | |
893 } | |
894 | |
895 if (IsDeniedFileSystemCapabilitySyscall(sysno)) { | |
896 return EPERM; | |
897 } | |
898 | |
899 if (IsBaselinePolicyWatched_x86_64(sysno)) { | |
900 // Previously unseen syscalls. TODO(jln): some of these should | |
901 // be denied gracefully right away. | |
902 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); | |
903 } | |
904 // In any other case crash the program with our SIGSYS handler | |
905 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); | |
906 } | |
907 | |
873 // x86_64 only because it references system calls that are multiplexed on IA32. | 908 // x86_64 only because it references system calls that are multiplexed on IA32. |
874 playground2::Sandbox::ErrorCode GpuProcessPolicy_x86_64(int sysno) { | 909 playground2::Sandbox::ErrorCode GpuProcessPolicy_x86_64(int sysno) { |
875 switch(sysno) { | 910 switch(sysno) { |
876 case __NR_getpid: // Nvidia binary driver. | |
877 case __NR_getppid: // ATI binary driver. | |
878 case __NR_ioctl: | 911 case __NR_ioctl: |
879 case __NR_mlock: | |
880 case __NR_munlock: | |
881 case __NR_poll: | |
882 case __NR_recvfrom: | |
883 case __NR_writev: | |
884 return playground2::Sandbox::SB_ALLOWED; | 912 return playground2::Sandbox::SB_ALLOWED; |
885 case __NR_socket: | 913 case __NR_socket: |
886 return EACCES; // Nvidia binary driver. | 914 return EACCES; // Nvidia binary driver. |
887 case __NR_fchmod: | |
888 return EPERM; // ATI binary driver. | |
889 case __NR_open: | 915 case __NR_open: |
890 // Accelerated video decode is enabled by default only on Chrome OS. | 916 // Accelerated video decode is enabled by default only on Chrome OS. |
891 if (IsAcceleratedVideoDecodeEnabled()) { | 917 if (IsAcceleratedVideoDecodeEnabled()) { |
892 // Accelerated video decode needs to open /dev/dri/card0, and | 918 // Accelerated video decode needs to open /dev/dri/card0, and |
893 // dup()'ing an already open file descriptor does not work. | 919 // dup()'ing an already open file descriptor does not work. |
894 // Allow open() even though it severely weakens the sandbox, | 920 // Allow open() even though it severely weakens the sandbox, |
895 // to test the sandboxing mechanism in general. | 921 // to test the sandboxing mechanism in general. |
896 // TODO(jorgelo): remove this once we solve the libva issue. | 922 // TODO(jorgelo): remove this once we solve the libva issue. |
897 return playground2::Sandbox::SB_ALLOWED; | 923 return playground2::Sandbox::SB_ALLOWED; |
898 } else { | 924 } else { |
899 // Hook open() in the GPU process to allow opening /etc/drirc, | 925 // Hook open() in the GPU process to allow opening /etc/drirc, |
900 // needed by Mesa. | 926 // needed by Mesa. |
901 // The hook needs dup(), lseek(), and close() to be allowed. | 927 // The hook needs dup(), lseek(), and close() to be allowed. |
902 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL); | 928 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL); |
903 } | 929 } |
904 default: | 930 default: |
905 if (IsGpuAndFlashPolicyAllowed_x86_64(sysno) || IsEventFd(sysno)) { | 931 if (IsEventFd(sysno)) |
906 return playground2::Sandbox::SB_ALLOWED; | 932 return playground2::Sandbox::SB_ALLOWED; |
907 } | |
908 // Generally, filename-based syscalls will fail with ENOENT to behave | |
909 // similarly to a possible future setuid sandbox. | |
910 if (IsFileSystemSyscall(sysno) || IsAmbientFileSystemSyscall(sysno)) { | |
911 return ENOENT; | |
912 } | |
913 | 933 |
914 if (IsGpuAndFlashPolicyWatched_x86_64(sysno)) { | 934 // Default on the baseline policy. |
915 // Previously unseen syscalls. TODO(jln): some of these should | 935 return BaselinePolicy_x86_64(sysno); |
916 // be denied gracefully right away. | |
917 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); | |
918 } | |
919 // In any other case crash the program with our SIGSYS handler | |
920 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); | |
921 } | 936 } |
922 } | 937 } |
923 | 938 |
924 // x86_64 only because it references system calls that are multiplexed on IA32. | 939 // x86_64 only because it references system calls that are multiplexed on IA32. |
925 playground2::Sandbox::ErrorCode FlashProcessPolicy_x86_64(int sysno) { | 940 playground2::Sandbox::ErrorCode FlashProcessPolicy_x86_64(int sysno) { |
926 switch (sysno) { | 941 switch (sysno) { |
927 case __NR_sched_getaffinity: | 942 case __NR_sched_getaffinity: |
928 case __NR_sched_setscheduler: | 943 case __NR_sched_setscheduler: |
929 // These are under investigation, and hopefully not here for the long term. | |
930 case __NR_times: | 944 case __NR_times: |
931 case __NR_wait4: | |
932 return playground2::Sandbox::SB_ALLOWED; | 945 return playground2::Sandbox::SB_ALLOWED; |
933 case __NR_ioctl: | 946 case __NR_ioctl: |
934 return ENOTTY; // Flash Access. | 947 return ENOTTY; // Flash Access. |
935 case __NR_socket: | 948 case __NR_socket: |
936 return EACCES; | 949 return EACCES; |
937 default: | 950 default: |
938 if (IsGpuAndFlashPolicyAllowed_x86_64(sysno) || | 951 // These are under investigation, and hopefully not here for the long |
939 IsSystemVSharedMemory(sysno)) { | 952 // term. |
953 if (IsSystemVSharedMemory(sysno)) | |
940 return playground2::Sandbox::SB_ALLOWED; | 954 return playground2::Sandbox::SB_ALLOWED; |
941 } | 955 |
942 if (IsFileSystemSyscall(sysno) || IsAmbientFileSystemSyscall(sysno)) { | 956 // Default on the baseline policy. |
943 return ENOENT; | 957 return BaselinePolicy_x86_64(sysno); |
944 } | |
945 if (IsGpuAndFlashPolicyWatched_x86_64(sysno)) { | |
946 // Previously unseen syscalls. TODO(jln): some of these should | |
947 // be denied gracefully right away. | |
948 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); | |
949 } | |
950 // In any other case crash the program with our SIGSYS handler. | |
951 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); | |
952 } | 958 } |
953 } | 959 } |
954 #endif | 960 #endif |
955 | 961 |
956 playground2::Sandbox::ErrorCode BlacklistPtracePolicy(int sysno) { | 962 playground2::Sandbox::ErrorCode BlacklistPtracePolicy(int sysno) { |
957 if (sysno < static_cast<int>(MIN_SYSCALL) || | 963 if (sysno < static_cast<int>(MIN_SYSCALL) || |
958 sysno > static_cast<int>(MAX_SYSCALL)) { | 964 sysno > static_cast<int>(MAX_SYSCALL)) { |
959 // TODO(jln) we should not have to do that in a trivial policy. | 965 // TODO(jln) we should not have to do that in a trivial policy. |
960 return ENOSYS; | 966 return ENOSYS; |
961 } | 967 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1097 // Process-specific policy. | 1103 // Process-specific policy. |
1098 ShouldEnableSeccompBpf(process_type) && | 1104 ShouldEnableSeccompBpf(process_type) && |
1099 SupportsSandbox()) { | 1105 SupportsSandbox()) { |
1100 return StartBpfSandbox_x86(command_line, process_type); | 1106 return StartBpfSandbox_x86(command_line, process_type); |
1101 } | 1107 } |
1102 #endif | 1108 #endif |
1103 return false; | 1109 return false; |
1104 } | 1110 } |
1105 | 1111 |
1106 } // namespace content | 1112 } // namespace content |
OLD | NEW |