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 #if !defined(__aarch64__)
80 case __NR_access
: // EPERM not a valid errno.
83 #if defined(__i386__) || defined(__arm__)
87 case __NR_futimesat
: // Should be called utimesat ?
90 case __NR_lstat
: // EPERM not a valid errno.
94 case __NR_readlink
: // EPERM not a valid errno.
97 case __NR_stat
: // EPERM not a valid errno.
100 case __NR_uselib
: // Neither EPERM, nor ENOENT are valid errno.
101 case __NR_ustat
: // Same as above. Deprecated.
103 #endif // !defined(__aarch64__)
106 case __NR_faccessat
: // EPERM not a valid errno.
108 case __NR_fchownat
: // Should be called chownat ?
109 #if defined(__x86_64__) || defined(__aarch64__)
110 case __NR_newfstatat
: // fstatat(). EPERM not a valid errno.
111 #elif defined(__i386__) || defined(__arm__) || defined(__mips__)
114 #if defined(__i386__) || defined(__arm__)
118 case __NR_lookup_dcookie
: // ENOENT not a valid errno.
120 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
123 #if defined(__i386__) || defined(__arm__) || defined(__x86_64__)
124 case __NR_memfd_create
:
128 #if defined(__i386__)
133 case __NR_readlinkat
:
136 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
139 case __NR_statfs
: // EPERM not a valid errno.
140 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
145 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
146 case __NR_truncate64
:
149 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
152 case __NR_utimensat
: // New.
159 bool SyscallSets::IsAllowedFileSystemAccessViaFd(int sysno
) {
162 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
166 // TODO(jln): these should be denied gracefully as well (moved below).
167 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
168 case __NR_fadvise64
: // EPERM not a valid errno.
170 #if defined(__i386__)
171 case __NR_fadvise64_64
:
174 case __NR_arm_fadvise64_64
:
176 case __NR_fdatasync
: // EPERM not a valid errno.
177 case __NR_flock
: // EPERM not a valid errno.
178 case __NR_fstatfs
: // Give information about the whole filesystem.
179 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
182 case __NR_fsync
: // EPERM not a valid errno.
183 #if defined(__i386__)
186 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) || \
188 case __NR_sync_file_range
: // EPERM not a valid errno.
189 #elif defined(__arm__)
190 case __NR_arm_sync_file_range
: // EPERM not a valid errno.
197 // EPERM is a good errno for any of these.
198 bool SyscallSets::IsDeniedFileSystemAccessViaFd(int sysno
) {
204 #if defined(__i386__) || defined(__arm__)
207 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
208 case __NR_ftruncate64
:
210 #if !defined(__aarch64__)
211 case __NR_getdents
: // EPERM not a valid errno.
213 case __NR_getdents64
: // EPERM not a valid errno.
214 #if defined(__i386__) || defined(__mips__)
223 bool SyscallSets::IsGetSimpleId(int sysno
) {
237 #if defined(__i386__) || defined(__arm__)
241 case __NR_getgroups32
:
242 case __NR_getresgid32
:
243 case __NR_getresuid32
:
252 bool SyscallSets::IsProcessPrivilegeChange(int sysno
) {
255 #if defined(__i386__) || defined(__x86_64__)
256 case __NR_ioperm
: // Intel privilege.
257 case __NR_iopl
: // Intel privilege.
268 #if defined(__i386__) || defined(__arm__)
269 case __NR_setfsgid32
:
270 case __NR_setfsuid32
:
272 case __NR_setgroups32
:
273 case __NR_setregid32
:
274 case __NR_setresgid32
:
275 case __NR_setresuid32
:
276 case __NR_setreuid32
:
285 bool SyscallSets::IsProcessGroupOrSession(int sysno
) {
288 #if !defined(__aarch64__)
299 bool SyscallSets::IsAllowedSignalHandling(int sysno
) {
301 case __NR_rt_sigaction
:
302 case __NR_rt_sigprocmask
:
303 case __NR_rt_sigreturn
:
304 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
306 case __NR_sigprocmask
:
310 case __NR_rt_sigpending
:
311 case __NR_rt_sigqueueinfo
:
312 case __NR_rt_sigsuspend
:
313 case __NR_rt_sigtimedwait
:
314 case __NR_rt_tgsigqueueinfo
:
315 case __NR_sigaltstack
:
316 #if !defined(__aarch64__)
320 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
321 case __NR_sigpending
:
322 case __NR_sigsuspend
:
324 #if defined(__i386__) || defined(__mips__)
326 case __NR_sgetmask
: // Obsolete.
334 bool SyscallSets::IsAllowedOperationOnFd(int sysno
) {
338 #if !defined(__aarch64__)
342 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
348 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
356 bool SyscallSets::IsKernelInternalApi(int sysno
) {
358 case __NR_restart_syscall
:
360 case __ARM_NR_cmpxchg
:
368 // This should be thought through in conjunction with IsFutex().
369 bool SyscallSets::IsAllowedProcessStartOrDeath(int sysno
) {
372 case __NR_exit_group
:
375 #if defined(__i386__)
379 case __NR_clone
: // Should be parameter-restricted.
380 case __NR_setns
: // Privileged.
381 #if !defined(__aarch64__)
384 #if defined(__i386__) || defined(__x86_64__)
385 case __NR_get_thread_area
:
387 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
388 case __NR_set_thread_area
:
390 case __NR_set_tid_address
:
392 #if !defined(__mips__) && !defined(__aarch64__)
400 // It's difficult to restrict those, but there is attack surface here.
401 bool SyscallSets::IsAllowedFutex(int sysno
) {
403 case __NR_get_robust_list
:
404 case __NR_set_robust_list
:
412 bool SyscallSets::IsAllowedEpoll(int sysno
) {
414 #if !defined(__aarch64__)
415 case __NR_epoll_create
:
416 case __NR_epoll_wait
:
418 case __NR_epoll_create1
:
422 #if defined(__x86_64__)
423 case __NR_epoll_ctl_old
:
425 case __NR_epoll_pwait
:
426 #if defined(__x86_64__)
427 case __NR_epoll_wait_old
:
433 bool SyscallSets::IsAllowedGetOrModifySocket(int sysno
) {
435 #if !defined(__aarch64__)
441 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
443 case __NR_socketpair
: // We will want to inspect its argument.
449 bool SyscallSets::IsDeniedGetOrModifySocket(int sysno
) {
451 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
466 #if defined(__i386__) || defined(__mips__)
467 // Big multiplexing system call for sockets.
468 bool SyscallSets::IsSocketCall(int sysno
) {
470 case __NR_socketcall
:
478 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
479 bool SyscallSets::IsNetworkSocketInformation(int sysno
) {
481 case __NR_getpeername
:
482 case __NR_getsockname
:
483 case __NR_getsockopt
:
484 case __NR_setsockopt
:
492 bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno
) {
502 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) || \
506 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
509 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
510 case __NR_modify_ldt
:
515 case __NR_munlockall
:
517 case __NR_remap_file_pages
:
518 #if defined(__i386__)
527 bool SyscallSets::IsAllowedGeneralIo(int sysno
) {
530 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
533 #if !defined(__aarch64__)
540 #if defined(__arm__) || defined(__mips__)
543 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
545 case __NR_recvfrom
: // Could specify source.
546 case __NR_recvmsg
: // Could specify source.
548 #if defined(__i386__) || defined(__x86_64__)
551 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
552 case __NR__newselect
:
557 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
559 case __NR_sendmsg
: // Could specify destination.
560 case __NR_sendto
: // Could specify destination.
565 case __NR_ioctl
: // Can be very powerful.
570 case __NR_recvmmsg
: // Could specify source.
572 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
573 case __NR_sendfile64
:
575 case __NR_sendmmsg
: // Could specify destination.
584 bool SyscallSets::IsPrctl(int sysno
) {
586 #if defined(__x86_64__)
587 case __NR_arch_prctl
:
596 bool SyscallSets::IsSeccomp(int sysno
) {
605 bool SyscallSets::IsAllowedBasicScheduler(int sysno
) {
607 case __NR_sched_yield
:
608 #if !defined(__aarch64__)
613 case __NR_getpriority
:
614 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
617 case __NR_setpriority
:
623 bool SyscallSets::IsAdminOperation(int sysno
) {
625 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
628 case __NR_kexec_load
:
630 case __NR_setdomainname
:
631 case __NR_sethostname
:
639 bool SyscallSets::IsKernelModule(int sysno
) {
641 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
642 case __NR_create_module
:
643 case __NR_get_kernel_syms
: // Should ENOSYS.
644 case __NR_query_module
:
646 case __NR_delete_module
:
647 case __NR_init_module
:
648 case __NR_finit_module
:
655 bool SyscallSets::IsGlobalFSViewChange(int sysno
) {
657 case __NR_pivot_root
:
666 bool SyscallSets::IsFsControl(int sysno
) {
669 case __NR_nfsservctl
:
673 #if defined(__i386__) || defined(__mips__)
683 bool SyscallSets::IsNuma(int sysno
) {
685 case __NR_get_mempolicy
:
688 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) || \
690 case __NR_migrate_pages
:
692 case __NR_move_pages
:
693 case __NR_set_mempolicy
:
700 bool SyscallSets::IsMessageQueue(int sysno
) {
702 case __NR_mq_getsetattr
:
705 case __NR_mq_timedreceive
:
706 case __NR_mq_timedsend
:
714 bool SyscallSets::IsGlobalProcessEnvironment(int sysno
) {
716 case __NR_acct
: // Privileged.
717 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) || \
721 #if defined(__i386__) || defined(__arm__)
722 case __NR_ugetrlimit
:
724 #if defined(__i386__) || defined(__mips__)
728 case __NR_personality
: // Can change its personality as well.
729 case __NR_prlimit64
: // Like setrlimit / getrlimit.
738 bool SyscallSets::IsDebug(int sysno
) {
741 case __NR_process_vm_readv
:
742 case __NR_process_vm_writev
:
750 bool SyscallSets::IsGlobalSystemStatus(int sysno
) {
752 #if !defined(__aarch64__)
758 #if defined(__i386__)
760 case __NR_oldolduname
:
768 bool SyscallSets::IsEventFd(int sysno
) {
770 #if !defined(__aarch64__)
780 // Asynchronous I/O API.
781 bool SyscallSets::IsAsyncIo(int sysno
) {
784 case __NR_io_destroy
:
785 case __NR_io_getevents
:
794 bool SyscallSets::IsKeyManagement(int sysno
) {
798 case __NR_request_key
:
805 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
806 bool SyscallSets::IsSystemVSemaphores(int sysno
) {
811 case __NR_semtimedop
:
819 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
820 // These give a lot of ambient authority and bypass the setuid sandbox.
821 bool SyscallSets::IsSystemVSharedMemory(int sysno
) {
834 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
835 bool SyscallSets::IsSystemVMessageQueue(int sysno
) {
848 #if defined(__i386__) || defined(__mips__)
849 // Big system V multiplexing system call.
850 bool SyscallSets::IsSystemVIpc(int sysno
) {
860 bool SyscallSets::IsAnySystemV(int sysno
) {
861 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
862 return IsSystemVMessageQueue(sysno
) || IsSystemVSemaphores(sysno
) ||
863 IsSystemVSharedMemory(sysno
);
864 #elif defined(__i386__) || defined(__mips__)
865 return IsSystemVIpc(sysno
);
869 bool SyscallSets::IsAdvancedScheduler(int sysno
) {
871 case __NR_ioprio_get
: // IO scheduler.
872 case __NR_ioprio_set
:
873 case __NR_sched_get_priority_max
:
874 case __NR_sched_get_priority_min
:
875 case __NR_sched_getaffinity
:
876 case __NR_sched_getattr
:
877 case __NR_sched_getparam
:
878 case __NR_sched_getscheduler
:
879 case __NR_sched_rr_get_interval
:
880 case __NR_sched_setaffinity
:
881 case __NR_sched_setattr
:
882 case __NR_sched_setparam
:
883 case __NR_sched_setscheduler
:
890 bool SyscallSets::IsInotify(int sysno
) {
892 case __NR_inotify_add_watch
:
893 #if !defined(__aarch64__)
894 case __NR_inotify_init
:
896 case __NR_inotify_init1
:
897 case __NR_inotify_rm_watch
:
904 bool SyscallSets::IsFaNotify(int sysno
) {
906 case __NR_fanotify_init
:
907 case __NR_fanotify_mark
:
914 bool SyscallSets::IsTimer(int sysno
) {
917 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
927 bool SyscallSets::IsAdvancedTimer(int sysno
) {
929 case __NR_timer_create
:
930 case __NR_timer_delete
:
931 case __NR_timer_getoverrun
:
932 case __NR_timer_gettime
:
933 case __NR_timer_settime
:
934 case __NR_timerfd_create
:
935 case __NR_timerfd_gettime
:
936 case __NR_timerfd_settime
:
943 bool SyscallSets::IsExtendedAttributes(int sysno
) {
946 case __NR_flistxattr
:
947 case __NR_fremovexattr
:
952 case __NR_llistxattr
:
953 case __NR_lremovexattr
:
955 case __NR_removexattr
:
963 // Various system calls that need to be researched.
964 // TODO(jln): classify this better.
965 bool SyscallSets::IsMisc(int sysno
) {
967 #if !defined(__mips__)
970 case __NR_name_to_handle_at
:
971 case __NR_open_by_handle_at
:
972 case __NR_perf_event_open
:
975 // The system calls below are not implemented.
976 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
977 case __NR_afs_syscall
:
979 #if defined(__i386__) || defined(__mips__)
982 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
985 #if defined(__i386__) || defined(__mips__)
993 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
996 #if defined(__x86_64__)
999 #if defined(__i386__) || defined(__mips__)
1002 #if defined(__x86_64__)
1005 #if !defined(__aarch64__)
1014 #if defined(__arm__)
1015 bool SyscallSets::IsArmPciConfig(int sysno
) {
1017 case __NR_pciconfig_iobase
:
1018 case __NR_pciconfig_read
:
1019 case __NR_pciconfig_write
:
1026 bool SyscallSets::IsArmPrivate(int sysno
) {
1028 case __ARM_NR_breakpoint
:
1029 case __ARM_NR_cacheflush
:
1030 case __ARM_NR_set_tls
:
1031 case __ARM_NR_usr26
:
1032 case __ARM_NR_usr32
:
1038 #endif // defined(__arm__)
1040 #if defined(__mips__)
1041 bool SyscallSets::IsMipsPrivate(int sysno
) {
1043 case __NR_cacheflush
:
1051 bool SyscallSets::IsMipsMisc(int sysno
) {
1054 case __NR_unused150
:
1060 #endif // defined(__mips__)
1061 } // namespace sandbox.