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
3 // found in the LICENSE file.
5 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h"
7 #include "build/build_config.h"
8 #include "sandbox/linux/services/linux_syscalls.h"
12 // The functions below cover all existing i386, x86_64, and ARM system calls;
13 // excluding syscalls made obsolete in ARM EABI.
14 // The implicitly defined sets form a partition of the sets of
17 bool SyscallSets::IsKill(int sysno) {
21 case __NR_tkill: // Deprecated.
28 bool SyscallSets::IsAllowedGettime(int sysno) {
30 case __NR_clock_gettime:
31 case __NR_gettimeofday:
32 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
36 case __NR_adjtimex: // Privileged.
37 case __NR_clock_adjtime: // Privileged.
38 case __NR_clock_getres: // Could be allowed.
39 case __NR_clock_nanosleep: // Could be allowed.
40 case __NR_clock_settime: // Privileged.
41 #if defined(__i386__) || defined(__mips__)
42 case __NR_ftime: // Obsolete.
44 case __NR_settimeofday: // Privileged.
45 #if defined(__i386__) || defined(__mips__)
53 bool SyscallSets::IsCurrentDirectory(int sysno) {
64 bool SyscallSets::IsUmask(int sysno) {
73 // System calls that directly access the file system. They might acquire
74 // a new file descriptor or otherwise perform an operation directly
76 // Both EPERM and ENOENT are valid errno unless otherwise noted in comment.
77 bool SyscallSets::IsFileSystem(int sysno) {
79 case __NR_access: // EPERM not a valid errno.
82 #if defined(__i386__) || defined(__arm__)
87 case __NR_faccessat: // EPERM not a valid errno.
89 case __NR_fchownat: // Should be called chownat ?
90 #if defined(__x86_64__)
91 case __NR_newfstatat: // fstatat(). EPERM not a valid errno.
92 #elif defined(__i386__) || defined(__arm__) || defined(__mips__)
95 case __NR_futimesat: // Should be called utimesat ?
97 #if defined(__i386__) || defined(__arm__)
102 case __NR_lookup_dcookie: // ENOENT not a valid errno.
103 case __NR_lstat: // EPERM not a valid errno.
104 #if defined(__i386__)
107 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
116 case __NR_readlink: // EPERM not a valid errno.
117 case __NR_readlinkat:
121 case __NR_stat: // EPERM not a valid errno.
122 #if defined(__i386__)
125 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
128 case __NR_statfs: // EPERM not a valid errno.
129 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
135 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
136 case __NR_truncate64:
140 case __NR_uselib: // Neither EPERM, nor ENOENT are valid errno.
141 case __NR_ustat: // Same as above. Deprecated.
142 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
145 case __NR_utimensat: // New.
153 bool SyscallSets::IsAllowedFileSystemAccessViaFd(int sysno) {
156 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
160 // TODO(jln): these should be denied gracefully as well (moved below).
161 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
162 case __NR_fadvise64: // EPERM not a valid errno.
164 #if defined(__i386__)
165 case __NR_fadvise64_64:
168 case __NR_arm_fadvise64_64:
170 case __NR_fdatasync: // EPERM not a valid errno.
171 case __NR_flock: // EPERM not a valid errno.
172 case __NR_fstatfs: // Give information about the whole filesystem.
173 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
176 case __NR_fsync: // EPERM not a valid errno.
177 #if defined(__i386__)
180 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
181 case __NR_sync_file_range: // EPERM not a valid errno.
182 #elif defined(__arm__)
183 case __NR_arm_sync_file_range: // EPERM not a valid errno.
190 // EPERM is a good errno for any of these.
191 bool SyscallSets::IsDeniedFileSystemAccessViaFd(int sysno) {
197 #if defined(__i386__) || defined(__arm__)
200 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
201 case __NR_ftruncate64:
203 case __NR_getdents: // EPERM not a valid errno.
204 case __NR_getdents64: // EPERM not a valid errno.
205 #if defined(__i386__) || defined(__mips__)
214 bool SyscallSets::IsGetSimpleId(int sysno) {
228 #if defined(__i386__) || defined(__arm__)
232 case __NR_getgroups32:
233 case __NR_getresgid32:
234 case __NR_getresuid32:
243 bool SyscallSets::IsProcessPrivilegeChange(int sysno) {
246 #if defined(__i386__) || defined(__x86_64__)
247 case __NR_ioperm: // Intel privilege.
248 case __NR_iopl: // Intel privilege.
259 #if defined(__i386__) || defined(__arm__)
260 case __NR_setfsgid32:
261 case __NR_setfsuid32:
263 case __NR_setgroups32:
264 case __NR_setregid32:
265 case __NR_setresgid32:
266 case __NR_setresuid32:
267 case __NR_setreuid32:
276 bool SyscallSets::IsProcessGroupOrSession(int sysno) {
288 bool SyscallSets::IsAllowedSignalHandling(int sysno) {
290 case __NR_rt_sigaction:
291 case __NR_rt_sigprocmask:
292 case __NR_rt_sigreturn:
293 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
295 case __NR_sigprocmask:
299 case __NR_rt_sigpending:
300 case __NR_rt_sigqueueinfo:
301 case __NR_rt_sigsuspend:
302 case __NR_rt_sigtimedwait:
303 case __NR_rt_tgsigqueueinfo:
304 case __NR_sigaltstack:
307 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
308 case __NR_sigpending:
309 case __NR_sigsuspend:
311 #if defined(__i386__) || defined(__mips__)
313 case __NR_sgetmask: // Obsolete.
321 bool SyscallSets::IsAllowedOperationOnFd(int sysno) {
327 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
332 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
340 bool SyscallSets::IsKernelInternalApi(int sysno) {
342 case __NR_restart_syscall:
344 case __ARM_NR_cmpxchg:
352 // This should be thought through in conjunction with IsFutex().
353 bool SyscallSets::IsAllowedProcessStartOrDeath(int sysno) {
356 case __NR_exit_group:
359 #if defined(__i386__)
363 case __NR_clone: // Should be parameter-restricted.
364 case __NR_setns: // Privileged.
366 #if defined(__i386__) || defined(__x86_64__)
367 case __NR_get_thread_area:
369 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
370 case __NR_set_thread_area:
372 case __NR_set_tid_address:
374 #if !defined(__mips__)
382 // It's difficult to restrict those, but there is attack surface here.
383 bool SyscallSets::IsAllowedFutex(int sysno) {
385 case __NR_get_robust_list:
386 case __NR_set_robust_list:
394 bool SyscallSets::IsAllowedEpoll(int sysno) {
396 case __NR_epoll_create:
397 case __NR_epoll_create1:
399 case __NR_epoll_wait:
402 #if defined(__x86_64__)
403 case __NR_epoll_ctl_old:
405 case __NR_epoll_pwait:
406 #if defined(__x86_64__)
407 case __NR_epoll_wait_old:
413 bool SyscallSets::IsAllowedGetOrModifySocket(int sysno) {
419 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
420 case __NR_socketpair: // We will want to inspect its argument.
426 bool SyscallSets::IsDeniedGetOrModifySocket(int sysno) {
428 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
442 #if defined(__i386__) || defined(__mips__)
443 // Big multiplexing system call for sockets.
444 bool SyscallSets::IsSocketCall(int sysno) {
446 case __NR_socketcall:
454 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
455 bool SyscallSets::IsNetworkSocketInformation(int sysno) {
457 case __NR_getpeername:
458 case __NR_getsockname:
459 case __NR_getsockopt:
460 case __NR_setsockopt:
468 bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno) {
478 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
481 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
484 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
485 case __NR_modify_ldt:
490 case __NR_munlockall:
492 case __NR_remap_file_pages:
493 #if defined(__i386__)
502 bool SyscallSets::IsAllowedGeneralIo(int sysno) {
505 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
513 #if defined(__arm__) || defined(__mips__)
516 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
517 case __NR_recvfrom: // Could specify source.
518 case __NR_recvmsg: // Could specify source.
520 #if defined(__i386__) || defined(__x86_64__)
523 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
524 case __NR__newselect:
529 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
530 case __NR_sendmsg: // Could specify destination.
531 case __NR_sendto: // Could specify destination.
536 case __NR_ioctl: // Can be very powerful.
541 case __NR_recvmmsg: // Could specify source.
543 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
544 case __NR_sendfile64:
546 case __NR_sendmmsg: // Could specify destination.
555 bool SyscallSets::IsPrctl(int sysno) {
557 #if defined(__x86_64__)
558 case __NR_arch_prctl:
567 bool SyscallSets::IsAllowedBasicScheduler(int sysno) {
569 case __NR_sched_yield:
573 case __NR_getpriority:
574 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
577 case __NR_setpriority:
583 bool SyscallSets::IsAdminOperation(int sysno) {
585 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
588 case __NR_kexec_load:
590 case __NR_setdomainname:
591 case __NR_sethostname:
599 bool SyscallSets::IsKernelModule(int sysno) {
601 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
602 case __NR_create_module:
603 case __NR_get_kernel_syms: // Should ENOSYS.
604 case __NR_query_module:
606 case __NR_delete_module:
607 case __NR_init_module:
614 bool SyscallSets::IsGlobalFSViewChange(int sysno) {
616 case __NR_pivot_root:
625 bool SyscallSets::IsFsControl(int sysno) {
628 case __NR_nfsservctl:
632 #if defined(__i386__) || defined(__mips__)
642 bool SyscallSets::IsNuma(int sysno) {
644 case __NR_get_mempolicy:
647 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
648 case __NR_migrate_pages:
650 case __NR_move_pages:
651 case __NR_set_mempolicy:
658 bool SyscallSets::IsMessageQueue(int sysno) {
660 case __NR_mq_getsetattr:
663 case __NR_mq_timedreceive:
664 case __NR_mq_timedsend:
672 bool SyscallSets::IsGlobalProcessEnvironment(int sysno) {
674 case __NR_acct: // Privileged.
675 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
678 #if defined(__i386__) || defined(__arm__)
679 case __NR_ugetrlimit:
681 #if defined(__i386__) || defined(__mips__)
685 case __NR_personality: // Can change its personality as well.
686 case __NR_prlimit64: // Like setrlimit / getrlimit.
695 bool SyscallSets::IsDebug(int sysno) {
698 case __NR_process_vm_readv:
699 case __NR_process_vm_writev:
700 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
709 bool SyscallSets::IsGlobalSystemStatus(int sysno) {
715 #if defined(__i386__)
717 case __NR_oldolduname:
725 bool SyscallSets::IsEventFd(int sysno) {
735 // Asynchronous I/O API.
736 bool SyscallSets::IsAsyncIo(int sysno) {
739 case __NR_io_destroy:
740 case __NR_io_getevents:
749 bool SyscallSets::IsKeyManagement(int sysno) {
753 case __NR_request_key:
760 #if defined(__x86_64__) || defined(__arm__)
761 bool SyscallSets::IsSystemVSemaphores(int sysno) {
766 case __NR_semtimedop:
774 #if defined(__x86_64__) || defined(__arm__)
775 // These give a lot of ambient authority and bypass the setuid sandbox.
776 bool SyscallSets::IsSystemVSharedMemory(int sysno) {
789 #if defined(__x86_64__) || defined(__arm__)
790 bool SyscallSets::IsSystemVMessageQueue(int sysno) {
803 #if defined(__i386__) || defined(__mips__)
804 // Big system V multiplexing system call.
805 bool SyscallSets::IsSystemVIpc(int sysno) {
815 bool SyscallSets::IsAnySystemV(int sysno) {
816 #if defined(__x86_64__) || defined(__arm__)
817 return IsSystemVMessageQueue(sysno) || IsSystemVSemaphores(sysno) ||
818 IsSystemVSharedMemory(sysno);
819 #elif defined(__i386__) || defined(__mips__)
820 return IsSystemVIpc(sysno);
824 bool SyscallSets::IsAdvancedScheduler(int sysno) {
826 case __NR_ioprio_get: // IO scheduler.
827 case __NR_ioprio_set:
828 case __NR_sched_get_priority_max:
829 case __NR_sched_get_priority_min:
830 case __NR_sched_getaffinity:
831 case __NR_sched_getparam:
832 case __NR_sched_getscheduler:
833 case __NR_sched_rr_get_interval:
834 case __NR_sched_setaffinity:
835 case __NR_sched_setparam:
836 case __NR_sched_setscheduler:
843 bool SyscallSets::IsInotify(int sysno) {
845 case __NR_inotify_add_watch:
846 case __NR_inotify_init:
847 case __NR_inotify_init1:
848 case __NR_inotify_rm_watch:
855 bool SyscallSets::IsFaNotify(int sysno) {
857 case __NR_fanotify_init:
858 case __NR_fanotify_mark:
865 bool SyscallSets::IsTimer(int sysno) {
868 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
878 bool SyscallSets::IsAdvancedTimer(int sysno) {
880 case __NR_timer_create:
881 case __NR_timer_delete:
882 case __NR_timer_getoverrun:
883 case __NR_timer_gettime:
884 case __NR_timer_settime:
885 case __NR_timerfd_create:
886 case __NR_timerfd_gettime:
887 case __NR_timerfd_settime:
894 bool SyscallSets::IsExtendedAttributes(int sysno) {
897 case __NR_flistxattr:
898 case __NR_fremovexattr:
903 case __NR_llistxattr:
904 case __NR_lremovexattr:
906 case __NR_removexattr:
914 // Various system calls that need to be researched.
915 // TODO(jln): classify this better.
916 bool SyscallSets::IsMisc(int sysno) {
918 case __NR_name_to_handle_at:
919 case __NR_open_by_handle_at:
920 case __NR_perf_event_open:
923 // The system calls below are not implemented.
924 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
925 case __NR_afs_syscall:
927 #if defined(__i386__) || defined(__mips__)
930 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
933 #if defined(__i386__) || defined(__mips__)
941 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
944 #if defined(__x86_64__)
947 #if defined(__i386__) || defined(__mips__)
950 #if defined(__x86_64__)
961 bool SyscallSets::IsArmPciConfig(int sysno) {
963 case __NR_pciconfig_iobase:
964 case __NR_pciconfig_read:
965 case __NR_pciconfig_write:
972 bool SyscallSets::IsArmPrivate(int sysno) {
974 case __ARM_NR_breakpoint:
975 case __ARM_NR_cacheflush:
976 case __ARM_NR_set_tls:
984 #endif // defined(__arm__)
986 #if defined(__mips__)
987 bool SyscallSets::IsMipsPrivate(int sysno) {
989 case __NR_cacheflush:
997 bool SyscallSets::IsMipsMisc(int sysno) {
1000 case __NR_unused150:
1006 #endif // defined(__mips__)
1007 } // namespace sandbox.