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__)
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.
42 case __NR_ftime: // Obsolete.
44 case __NR_settimeofday: // Privileged.
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__)
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__)
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__)
128 case __NR_statfs: // EPERM not a valid errno.
129 #if defined(__i386__) || defined(__arm__)
135 #if defined(__i386__) || defined(__arm__)
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__)
145 case __NR_utimensat: // New.
153 bool SyscallSets::IsAllowedFileSystemAccessViaFd(int sysno) {
156 #if defined(__i386__) || defined(__arm__)
160 // TODO(jln): these should be denied gracefully as well (moved below).
161 #if defined(__i386__) || defined(__x86_64__)
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__)
176 case __NR_fsync: // EPERM not a valid errno.
177 #if defined(__i386__)
180 #if defined(__i386__) || defined(__x86_64__)
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__)
199 case __NR_ftruncate64:
201 case __NR_getdents: // EPERM not a valid errno.
202 case __NR_getdents64: // EPERM not a valid errno.
203 #if defined(__i386__)
212 bool SyscallSets::IsGetSimpleId(int sysno) {
226 #if defined(__i386__) || defined(__arm__)
230 case __NR_getgroups32:
231 case __NR_getresgid32:
232 case __NR_getresuid32:
241 bool SyscallSets::IsProcessPrivilegeChange(int sysno) {
244 #if defined(__i386__) || defined(__x86_64__)
245 case __NR_ioperm: // Intel privilege.
246 case __NR_iopl: // Intel privilege.
257 #if defined(__i386__) || defined(__arm__)
258 case __NR_setfsgid32:
259 case __NR_setfsuid32:
261 case __NR_setgroups32:
262 case __NR_setregid32:
263 case __NR_setresgid32:
264 case __NR_setresuid32:
265 case __NR_setreuid32:
274 bool SyscallSets::IsProcessGroupOrSession(int sysno) {
286 bool SyscallSets::IsAllowedSignalHandling(int sysno) {
288 case __NR_rt_sigaction:
289 case __NR_rt_sigprocmask:
290 case __NR_rt_sigreturn:
291 #if defined(__i386__) || defined(__arm__)
293 case __NR_sigprocmask:
297 case __NR_rt_sigpending:
298 case __NR_rt_sigqueueinfo:
299 case __NR_rt_sigsuspend:
300 case __NR_rt_sigtimedwait:
301 case __NR_rt_tgsigqueueinfo:
302 case __NR_sigaltstack:
305 #if defined(__i386__) || defined(__arm__)
306 case __NR_sigpending:
307 case __NR_sigsuspend:
309 #if defined(__i386__)
311 case __NR_sgetmask: // Obsolete.
319 bool SyscallSets::IsAllowedOperationOnFd(int sysno) {
325 #if defined(__x86_64__) || defined(__arm__)
330 #if defined(__i386__) || defined(__arm__)
338 bool SyscallSets::IsKernelInternalApi(int sysno) {
340 case __NR_restart_syscall:
342 case __ARM_NR_cmpxchg:
350 // This should be thought through in conjunction with IsFutex().
351 bool SyscallSets::IsAllowedProcessStartOrDeath(int sysno) {
354 case __NR_exit_group:
357 #if defined(__i386__)
361 case __NR_clone: // Should be parameter-restricted.
362 case __NR_setns: // Privileged.
364 #if defined(__i386__) || defined(__x86_64__)
365 case __NR_get_thread_area:
366 case __NR_set_thread_area:
368 case __NR_set_tid_address:
376 // It's difficult to restrict those, but there is attack surface here.
377 bool SyscallSets::IsFutex(int sysno) {
380 case __NR_get_robust_list:
381 case __NR_set_robust_list:
388 bool SyscallSets::IsAllowedEpoll(int sysno) {
390 case __NR_epoll_create:
391 case __NR_epoll_create1:
393 case __NR_epoll_wait:
396 #if defined(__x86_64__)
397 case __NR_epoll_ctl_old:
399 case __NR_epoll_pwait:
400 #if defined(__x86_64__)
401 case __NR_epoll_wait_old:
407 bool SyscallSets::IsAllowedGetOrModifySocket(int sysno) {
413 #if defined(__x86_64__) || defined(__arm__)
414 case __NR_socketpair: // We will want to inspect its argument.
420 bool SyscallSets::IsDeniedGetOrModifySocket(int sysno) {
422 #if defined(__x86_64__) || defined(__arm__)
436 #if defined(__i386__)
437 // Big multiplexing system call for sockets.
438 bool SyscallSets::IsSocketCall(int sysno) {
440 case __NR_socketcall:
448 #if defined(__x86_64__) || defined(__arm__)
449 bool SyscallSets::IsNetworkSocketInformation(int sysno) {
451 case __NR_getpeername:
452 case __NR_getsockname:
453 case __NR_getsockopt:
454 case __NR_setsockopt:
462 bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno) {
472 #if defined(__i386__) || defined(__x86_64__)
475 #if defined(__i386__) || defined(__arm__)
478 #if defined(__i386__) || defined(__x86_64__)
479 case __NR_modify_ldt:
484 case __NR_munlockall:
486 case __NR_remap_file_pages:
487 #if defined(__i386__)
496 bool SyscallSets::IsAllowedGeneralIo(int sysno) {
499 #if defined(__i386__) || defined(__arm__)
510 #if defined(__x86_64__) || defined(__arm__)
511 case __NR_recvfrom: // Could specify source.
512 case __NR_recvmsg: // Could specify source.
514 #if defined(__i386__) || defined(__x86_64__)
517 #if defined(__i386__) || defined(__arm__)
518 case __NR__newselect:
523 #if defined(__x86_64__) || defined(__arm__)
524 case __NR_sendmsg: // Could specify destination.
525 case __NR_sendto: // Could specify destination.
530 case __NR_ioctl: // Can be very powerful.
535 case __NR_recvmmsg: // Could specify source.
537 #if defined(__i386__) || defined(__arm__)
538 case __NR_sendfile64:
540 case __NR_sendmmsg: // Could specify destination.
549 bool SyscallSets::IsAllowedPrctl(int sysno) {
554 #if defined(__x86_64__)
555 case __NR_arch_prctl:
561 bool SyscallSets::IsAllowedBasicScheduler(int sysno) {
563 case __NR_sched_yield:
567 case __NR_getpriority:
568 #if defined(__i386__) || defined(__arm__)
571 case __NR_setpriority:
577 bool SyscallSets::IsAdminOperation(int sysno) {
579 #if defined(__i386__) || defined(__arm__)
582 case __NR_kexec_load:
584 case __NR_setdomainname:
585 case __NR_sethostname:
593 bool SyscallSets::IsKernelModule(int sysno) {
595 #if defined(__i386__) || defined(__x86_64__)
596 case __NR_create_module:
597 case __NR_get_kernel_syms: // Should ENOSYS.
598 case __NR_query_module:
600 case __NR_delete_module:
601 case __NR_init_module:
608 bool SyscallSets::IsGlobalFSViewChange(int sysno) {
610 case __NR_pivot_root:
619 bool SyscallSets::IsFsControl(int sysno) {
622 case __NR_nfsservctl:
626 #if defined(__i386__)
636 bool SyscallSets::IsNuma(int sysno) {
638 case __NR_get_mempolicy:
641 #if defined(__i386__) || defined(__x86_64__)
642 case __NR_migrate_pages:
644 case __NR_move_pages:
645 case __NR_set_mempolicy:
652 bool SyscallSets::IsMessageQueue(int sysno) {
654 case __NR_mq_getsetattr:
657 case __NR_mq_timedreceive:
658 case __NR_mq_timedsend:
666 bool SyscallSets::IsGlobalProcessEnvironment(int sysno) {
668 case __NR_acct: // Privileged.
669 #if defined(__i386__) || defined(__x86_64__)
672 #if defined(__i386__) || defined(__arm__)
673 case __NR_ugetrlimit:
675 #if defined(__i386__)
679 case __NR_personality: // Can change its personality as well.
680 case __NR_prlimit64: // Like setrlimit / getrlimit.
689 bool SyscallSets::IsDebug(int sysno) {
692 case __NR_process_vm_readv:
693 case __NR_process_vm_writev:
694 #if defined(__i386__) || defined(__x86_64__)
703 bool SyscallSets::IsGlobalSystemStatus(int sysno) {
709 #if defined(__i386__)
711 case __NR_oldolduname:
719 bool SyscallSets::IsEventFd(int sysno) {
729 // Asynchronous I/O API.
730 bool SyscallSets::IsAsyncIo(int sysno) {
733 case __NR_io_destroy:
734 case __NR_io_getevents:
743 bool SyscallSets::IsKeyManagement(int sysno) {
747 case __NR_request_key:
754 #if defined(__x86_64__) || defined(__arm__)
755 bool SyscallSets::IsSystemVSemaphores(int sysno) {
760 case __NR_semtimedop:
768 #if defined(__x86_64__) || defined(__arm__)
769 // These give a lot of ambient authority and bypass the setuid sandbox.
770 bool SyscallSets::IsSystemVSharedMemory(int sysno) {
783 #if defined(__x86_64__) || defined(__arm__)
784 bool SyscallSets::IsSystemVMessageQueue(int sysno) {
797 #if defined(__i386__)
798 // Big system V multiplexing system call.
799 bool SyscallSets::IsSystemVIpc(int sysno) {
809 bool SyscallSets::IsAnySystemV(int sysno) {
810 #if defined(__x86_64__) || defined(__arm__)
811 return IsSystemVMessageQueue(sysno) || IsSystemVSemaphores(sysno) ||
812 IsSystemVSharedMemory(sysno);
813 #elif defined(__i386__)
814 return IsSystemVIpc(sysno);
818 bool SyscallSets::IsAdvancedScheduler(int sysno) {
820 case __NR_ioprio_get: // IO scheduler.
821 case __NR_ioprio_set:
822 case __NR_sched_get_priority_max:
823 case __NR_sched_get_priority_min:
824 case __NR_sched_getaffinity:
825 case __NR_sched_getparam:
826 case __NR_sched_getscheduler:
827 case __NR_sched_rr_get_interval:
828 case __NR_sched_setaffinity:
829 case __NR_sched_setparam:
830 case __NR_sched_setscheduler:
837 bool SyscallSets::IsInotify(int sysno) {
839 case __NR_inotify_add_watch:
840 case __NR_inotify_init:
841 case __NR_inotify_init1:
842 case __NR_inotify_rm_watch:
849 bool SyscallSets::IsFaNotify(int sysno) {
851 case __NR_fanotify_init:
852 case __NR_fanotify_mark:
859 bool SyscallSets::IsTimer(int sysno) {
862 #if defined(__i386__) || defined(__x86_64__)
872 bool SyscallSets::IsAdvancedTimer(int sysno) {
874 case __NR_timer_create:
875 case __NR_timer_delete:
876 case __NR_timer_getoverrun:
877 case __NR_timer_gettime:
878 case __NR_timer_settime:
879 case __NR_timerfd_create:
880 case __NR_timerfd_gettime:
881 case __NR_timerfd_settime:
888 bool SyscallSets::IsExtendedAttributes(int sysno) {
891 case __NR_flistxattr:
892 case __NR_fremovexattr:
897 case __NR_llistxattr:
898 case __NR_lremovexattr:
900 case __NR_removexattr:
908 // Various system calls that need to be researched.
909 // TODO(jln): classify this better.
910 bool SyscallSets::IsMisc(int sysno) {
912 case __NR_name_to_handle_at:
913 case __NR_open_by_handle_at:
914 case __NR_perf_event_open:
917 // The system calls below are not implemented.
918 #if defined(__i386__) || defined(__x86_64__)
919 case __NR_afs_syscall:
921 #if defined(__i386__)
924 #if defined(__i386__) || defined(__x86_64__)
927 #if defined(__i386__)
935 #if defined(__i386__) || defined(__x86_64__)
938 #if defined(__x86_64__)
941 #if defined(__i386__)
944 #if defined(__x86_64__)
955 bool SyscallSets::IsArmPciConfig(int sysno) {
957 case __NR_pciconfig_iobase:
958 case __NR_pciconfig_read:
959 case __NR_pciconfig_write:
966 bool SyscallSets::IsArmPrivate(int sysno) {
968 case __ARM_NR_breakpoint:
969 case __ARM_NR_cacheflush:
970 case __ARM_NR_set_tls:
978 #endif // defined(__arm__)
980 } // namespace sandbox.