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/system_headers/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_gettimeofday
:
31 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
35 case __NR_adjtimex
: // Privileged.
36 case __NR_clock_adjtime
: // Privileged.
37 case __NR_clock_getres
: // Could be allowed.
38 case __NR_clock_gettime
:
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
:
411 bool SyscallSets::IsAllowedEpoll(int sysno
) {
413 #if !defined(__aarch64__)
414 case __NR_epoll_create
:
415 case __NR_epoll_wait
:
417 case __NR_epoll_create1
:
421 #if defined(__x86_64__)
422 case __NR_epoll_ctl_old
:
424 case __NR_epoll_pwait
:
425 #if defined(__x86_64__)
426 case __NR_epoll_wait_old
:
432 bool SyscallSets::IsAllowedGetOrModifySocket(int sysno
) {
434 #if !defined(__aarch64__)
440 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
442 case __NR_socketpair
: // We will want to inspect its argument.
448 bool SyscallSets::IsDeniedGetOrModifySocket(int sysno
) {
450 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
465 #if defined(__i386__) || defined(__mips__)
466 // Big multiplexing system call for sockets.
467 bool SyscallSets::IsSocketCall(int sysno
) {
469 case __NR_socketcall
:
477 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
478 bool SyscallSets::IsNetworkSocketInformation(int sysno
) {
480 case __NR_getpeername
:
481 case __NR_getsockname
:
482 case __NR_getsockopt
:
483 case __NR_setsockopt
:
491 bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno
) {
501 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) || \
505 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
508 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
509 case __NR_modify_ldt
:
514 case __NR_munlockall
:
516 case __NR_remap_file_pages
:
517 #if defined(__i386__)
526 bool SyscallSets::IsAllowedGeneralIo(int sysno
) {
529 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
532 #if !defined(__aarch64__)
539 #if defined(__arm__) || defined(__mips__)
542 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
544 case __NR_recvfrom
: // Could specify source.
545 case __NR_recvmsg
: // Could specify source.
547 #if defined(__i386__) || defined(__x86_64__)
550 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
551 case __NR__newselect
:
556 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
558 case __NR_sendmsg
: // Could specify destination.
559 case __NR_sendto
: // Could specify destination.
564 case __NR_ioctl
: // Can be very powerful.
569 case __NR_recvmmsg
: // Could specify source.
571 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
572 case __NR_sendfile64
:
574 case __NR_sendmmsg
: // Could specify destination.
583 bool SyscallSets::IsPrctl(int sysno
) {
585 #if defined(__x86_64__)
586 case __NR_arch_prctl
:
595 bool SyscallSets::IsSeccomp(int sysno
) {
604 bool SyscallSets::IsAllowedBasicScheduler(int sysno
) {
606 case __NR_sched_yield
:
607 #if !defined(__aarch64__)
612 case __NR_getpriority
:
613 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
616 case __NR_setpriority
:
622 bool SyscallSets::IsAdminOperation(int sysno
) {
624 #if defined(__i386__) || defined(__arm__) || defined(__mips__)
627 case __NR_kexec_load
:
629 case __NR_setdomainname
:
630 case __NR_sethostname
:
638 bool SyscallSets::IsKernelModule(int sysno
) {
640 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
641 case __NR_create_module
:
642 case __NR_get_kernel_syms
: // Should ENOSYS.
643 case __NR_query_module
:
645 case __NR_delete_module
:
646 case __NR_init_module
:
647 case __NR_finit_module
:
654 bool SyscallSets::IsGlobalFSViewChange(int sysno
) {
656 case __NR_pivot_root
:
665 bool SyscallSets::IsFsControl(int sysno
) {
668 case __NR_nfsservctl
:
672 #if defined(__i386__) || defined(__mips__)
682 bool SyscallSets::IsNuma(int sysno
) {
684 case __NR_get_mempolicy
:
687 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) || \
689 case __NR_migrate_pages
:
691 case __NR_move_pages
:
692 case __NR_set_mempolicy
:
699 bool SyscallSets::IsMessageQueue(int sysno
) {
701 case __NR_mq_getsetattr
:
704 case __NR_mq_timedreceive
:
705 case __NR_mq_timedsend
:
713 bool SyscallSets::IsGlobalProcessEnvironment(int sysno
) {
715 case __NR_acct
: // Privileged.
716 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) || \
720 #if defined(__i386__) || defined(__arm__)
721 case __NR_ugetrlimit
:
723 #if defined(__i386__) || defined(__mips__)
727 case __NR_personality
: // Can change its personality as well.
728 case __NR_prlimit64
: // Like setrlimit / getrlimit.
737 bool SyscallSets::IsDebug(int sysno
) {
740 case __NR_process_vm_readv
:
741 case __NR_process_vm_writev
:
749 bool SyscallSets::IsGlobalSystemStatus(int sysno
) {
751 #if !defined(__aarch64__)
757 #if defined(__i386__)
759 case __NR_oldolduname
:
767 bool SyscallSets::IsEventFd(int sysno
) {
769 #if !defined(__aarch64__)
779 // Asynchronous I/O API.
780 bool SyscallSets::IsAsyncIo(int sysno
) {
783 case __NR_io_destroy
:
784 case __NR_io_getevents
:
793 bool SyscallSets::IsKeyManagement(int sysno
) {
797 case __NR_request_key
:
804 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
805 bool SyscallSets::IsSystemVSemaphores(int sysno
) {
810 case __NR_semtimedop
:
818 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
819 // These give a lot of ambient authority and bypass the setuid sandbox.
820 bool SyscallSets::IsSystemVSharedMemory(int sysno
) {
833 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
834 bool SyscallSets::IsSystemVMessageQueue(int sysno
) {
847 #if defined(__i386__) || defined(__mips__)
848 // Big system V multiplexing system call.
849 bool SyscallSets::IsSystemVIpc(int sysno
) {
859 bool SyscallSets::IsAnySystemV(int sysno
) {
860 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
861 return IsSystemVMessageQueue(sysno
) || IsSystemVSemaphores(sysno
) ||
862 IsSystemVSharedMemory(sysno
);
863 #elif defined(__i386__) || defined(__mips__)
864 return IsSystemVIpc(sysno
);
868 bool SyscallSets::IsAdvancedScheduler(int sysno
) {
870 case __NR_ioprio_get
: // IO scheduler.
871 case __NR_ioprio_set
:
872 case __NR_sched_get_priority_max
:
873 case __NR_sched_get_priority_min
:
874 case __NR_sched_getaffinity
:
875 case __NR_sched_getattr
:
876 case __NR_sched_getparam
:
877 case __NR_sched_getscheduler
:
878 case __NR_sched_rr_get_interval
:
879 case __NR_sched_setaffinity
:
880 case __NR_sched_setattr
:
881 case __NR_sched_setparam
:
882 case __NR_sched_setscheduler
:
889 bool SyscallSets::IsInotify(int sysno
) {
891 case __NR_inotify_add_watch
:
892 #if !defined(__aarch64__)
893 case __NR_inotify_init
:
895 case __NR_inotify_init1
:
896 case __NR_inotify_rm_watch
:
903 bool SyscallSets::IsFaNotify(int sysno
) {
905 case __NR_fanotify_init
:
906 case __NR_fanotify_mark
:
913 bool SyscallSets::IsTimer(int sysno
) {
916 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
926 bool SyscallSets::IsAdvancedTimer(int sysno
) {
928 case __NR_timer_create
:
929 case __NR_timer_delete
:
930 case __NR_timer_getoverrun
:
931 case __NR_timer_gettime
:
932 case __NR_timer_settime
:
933 case __NR_timerfd_create
:
934 case __NR_timerfd_gettime
:
935 case __NR_timerfd_settime
:
942 bool SyscallSets::IsExtendedAttributes(int sysno
) {
945 case __NR_flistxattr
:
946 case __NR_fremovexattr
:
951 case __NR_llistxattr
:
952 case __NR_lremovexattr
:
954 case __NR_removexattr
:
962 // Various system calls that need to be researched.
963 // TODO(jln): classify this better.
964 bool SyscallSets::IsMisc(int sysno
) {
966 #if !defined(__mips__)
969 case __NR_name_to_handle_at
:
970 case __NR_open_by_handle_at
:
971 case __NR_perf_event_open
:
974 // The system calls below are not implemented.
975 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
976 case __NR_afs_syscall
:
978 #if defined(__i386__) || defined(__mips__)
981 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
984 #if defined(__i386__) || defined(__mips__)
992 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
995 #if defined(__x86_64__)
998 #if defined(__i386__) || defined(__mips__)
1001 #if defined(__x86_64__)
1004 #if !defined(__aarch64__)
1013 #if defined(__arm__)
1014 bool SyscallSets::IsArmPciConfig(int sysno
) {
1016 case __NR_pciconfig_iobase
:
1017 case __NR_pciconfig_read
:
1018 case __NR_pciconfig_write
:
1025 bool SyscallSets::IsArmPrivate(int sysno
) {
1027 case __ARM_NR_breakpoint
:
1028 case __ARM_NR_cacheflush
:
1029 case __ARM_NR_set_tls
:
1030 case __ARM_NR_usr26
:
1031 case __ARM_NR_usr32
:
1037 #endif // defined(__arm__)
1039 #if defined(__mips__)
1040 bool SyscallSets::IsMipsPrivate(int sysno
) {
1042 case __NR_cacheflush
:
1050 bool SyscallSets::IsMipsMisc(int sysno
) {
1053 case __NR_unused150
:
1059 #endif // defined(__mips__)
1060 } // namespace sandbox.