Home | History | Annotate | Download | only in seccomp-bpf-helpers
      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.
      4 
      5 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h"
      6 
      7 #include "build/build_config.h"
      8 #include "sandbox/linux/services/linux_syscalls.h"
      9 
     10 namespace sandbox {
     11 
     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
     15 // system calls.
     16 
     17 // TODO(jln) we need to restrict the first parameter!
     18 bool SyscallSets::IsKill(int sysno) {
     19   switch (sysno) {
     20     case __NR_kill:
     21     case __NR_tkill:
     22     case __NR_tgkill:
     23       return true;
     24     default:
     25       return false;
     26   }
     27 }
     28 
     29 bool SyscallSets::IsAllowedGettime(int sysno) {
     30   switch (sysno) {
     31     case __NR_clock_gettime:
     32     case __NR_gettimeofday:
     33 #if defined(__i386__) || defined(__x86_64__)
     34     case __NR_time:
     35 #endif
     36       return true;
     37     case __NR_adjtimex:         // Privileged.
     38     case __NR_clock_adjtime:    // Privileged.
     39     case __NR_clock_getres:     // Could be allowed.
     40     case __NR_clock_nanosleep:  // Could be allowed.
     41     case __NR_clock_settime:    // Privileged.
     42 #if defined(__i386__)
     43     case __NR_ftime:  // Obsolete.
     44 #endif
     45     case __NR_settimeofday:  // Privileged.
     46 #if defined(__i386__)
     47     case __NR_stime:
     48 #endif
     49     default:
     50       return false;
     51   }
     52 }
     53 
     54 bool SyscallSets::IsCurrentDirectory(int sysno) {
     55   switch (sysno) {
     56     case __NR_getcwd:
     57     case __NR_chdir:
     58     case __NR_fchdir:
     59       return true;
     60     default:
     61       return false;
     62   }
     63 }
     64 
     65 bool SyscallSets::IsUmask(int sysno) {
     66   switch (sysno) {
     67     case __NR_umask:
     68       return true;
     69     default:
     70       return false;
     71   }
     72 }
     73 
     74 // System calls that directly access the file system. They might acquire
     75 // a new file descriptor or otherwise perform an operation directly
     76 // via a path.
     77 // Both EPERM and ENOENT are valid errno unless otherwise noted in comment.
     78 bool SyscallSets::IsFileSystem(int sysno) {
     79   switch (sysno) {
     80     case __NR_access:  // EPERM not a valid errno.
     81     case __NR_chmod:
     82     case __NR_chown:
     83 #if defined(__i386__) || defined(__arm__)
     84     case __NR_chown32:
     85 #endif
     86     case __NR_creat:
     87     case __NR_execve:
     88     case __NR_faccessat:  // EPERM not a valid errno.
     89     case __NR_fchmodat:
     90     case __NR_fchownat:  // Should be called chownat ?
     91 #if defined(__x86_64__)
     92     case __NR_newfstatat:  // fstatat(). EPERM not a valid errno.
     93 #elif defined(__i386__) || defined(__arm__)
     94     case __NR_fstatat64:
     95 #endif
     96     case __NR_futimesat:  // Should be called utimesat ?
     97     case __NR_lchown:
     98 #if defined(__i386__) || defined(__arm__)
     99     case __NR_lchown32:
    100 #endif
    101     case __NR_link:
    102     case __NR_linkat:
    103     case __NR_lookup_dcookie:  // ENOENT not a valid errno.
    104     case __NR_lstat:           // EPERM not a valid errno.
    105 #if defined(__i386__)
    106     case __NR_oldlstat:
    107 #endif
    108 #if defined(__i386__) || defined(__arm__)
    109     case __NR_lstat64:
    110 #endif
    111     case __NR_mkdir:
    112     case __NR_mkdirat:
    113     case __NR_mknod:
    114     case __NR_mknodat:
    115     case __NR_open:
    116     case __NR_openat:
    117     case __NR_readlink:  // EPERM not a valid errno.
    118     case __NR_readlinkat:
    119     case __NR_rename:
    120     case __NR_renameat:
    121     case __NR_rmdir:
    122     case __NR_stat:  // EPERM not a valid errno.
    123 #if defined(__i386__)
    124     case __NR_oldstat:
    125 #endif
    126 #if defined(__i386__) || defined(__arm__)
    127     case __NR_stat64:
    128 #endif
    129     case __NR_statfs:  // EPERM not a valid errno.
    130 #if defined(__i386__) || defined(__arm__)
    131     case __NR_statfs64:
    132 #endif
    133     case __NR_symlink:
    134     case __NR_symlinkat:
    135     case __NR_truncate:
    136 #if defined(__i386__) || defined(__arm__)
    137     case __NR_truncate64:
    138 #endif
    139     case __NR_unlink:
    140     case __NR_unlinkat:
    141     case __NR_uselib:  // Neither EPERM, nor ENOENT are valid errno.
    142     case __NR_ustat:   // Same as above. Deprecated.
    143 #if defined(__i386__) || defined(__x86_64__)
    144     case __NR_utime:
    145 #endif
    146     case __NR_utimensat:  // New.
    147     case __NR_utimes:
    148       return true;
    149     default:
    150       return false;
    151   }
    152 }
    153 
    154 bool SyscallSets::IsAllowedFileSystemAccessViaFd(int sysno) {
    155   switch (sysno) {
    156     case __NR_fstat:
    157 #if defined(__i386__) || defined(__arm__)
    158     case __NR_fstat64:
    159 #endif
    160       return true;
    161 // TODO(jln): these should be denied gracefully as well (moved below).
    162 #if defined(__i386__) || defined(__x86_64__)
    163     case __NR_fadvise64:  // EPERM not a valid errno.
    164 #endif
    165 #if defined(__i386__)
    166     case __NR_fadvise64_64:
    167 #endif
    168 #if defined(__arm__)
    169     case __NR_arm_fadvise64_64:
    170 #endif
    171     case __NR_fdatasync:  // EPERM not a valid errno.
    172     case __NR_flock:      // EPERM not a valid errno.
    173     case __NR_fstatfs:    // Give information about the whole filesystem.
    174 #if defined(__i386__) || defined(__arm__)
    175     case __NR_fstatfs64:
    176 #endif
    177     case __NR_fsync:  // EPERM not a valid errno.
    178 #if defined(__i386__)
    179     case __NR_oldfstat:
    180 #endif
    181 #if defined(__i386__) || defined(__x86_64__)
    182     case __NR_sync_file_range:  // EPERM not a valid errno.
    183 #elif defined(__arm__)
    184     case __NR_arm_sync_file_range:  // EPERM not a valid errno.
    185 #endif
    186     default:
    187       return false;
    188   }
    189 }
    190 
    191 // EPERM is a good errno for any of these.
    192 bool SyscallSets::IsDeniedFileSystemAccessViaFd(int sysno) {
    193   switch (sysno) {
    194     case __NR_fallocate:
    195     case __NR_fchmod:
    196     case __NR_fchown:
    197     case __NR_ftruncate:
    198 #if defined(__i386__) || defined(__arm__)
    199     case __NR_fchown32:
    200     case __NR_ftruncate64:
    201 #endif
    202     case __NR_getdents:    // EPERM not a valid errno.
    203     case __NR_getdents64:  // EPERM not a valid errno.
    204 #if defined(__i386__)
    205     case __NR_readdir:
    206 #endif
    207       return true;
    208     default:
    209       return false;
    210   }
    211 }
    212 
    213 bool SyscallSets::IsGetSimpleId(int sysno) {
    214   switch (sysno) {
    215     case __NR_capget:
    216     case __NR_getegid:
    217     case __NR_geteuid:
    218     case __NR_getgid:
    219     case __NR_getgroups:
    220     case __NR_getpid:
    221     case __NR_getppid:
    222     case __NR_getresgid:
    223     case __NR_getsid:
    224     case __NR_gettid:
    225     case __NR_getuid:
    226     case __NR_getresuid:
    227 #if defined(__i386__) || defined(__arm__)
    228     case __NR_getegid32:
    229     case __NR_geteuid32:
    230     case __NR_getgid32:
    231     case __NR_getgroups32:
    232     case __NR_getresgid32:
    233     case __NR_getresuid32:
    234     case __NR_getuid32:
    235 #endif
    236       return true;
    237     default:
    238       return false;
    239   }
    240 }
    241 
    242 bool SyscallSets::IsProcessPrivilegeChange(int sysno) {
    243   switch (sysno) {
    244     case __NR_capset:
    245 #if defined(__i386__) || defined(__x86_64__)
    246     case __NR_ioperm:  // Intel privilege.
    247     case __NR_iopl:    // Intel privilege.
    248 #endif
    249     case __NR_setfsgid:
    250     case __NR_setfsuid:
    251     case __NR_setgid:
    252     case __NR_setgroups:
    253     case __NR_setregid:
    254     case __NR_setresgid:
    255     case __NR_setresuid:
    256     case __NR_setreuid:
    257     case __NR_setuid:
    258 #if defined(__i386__) || defined(__arm__)
    259     case __NR_setfsgid32:
    260     case __NR_setfsuid32:
    261     case __NR_setgid32:
    262     case __NR_setgroups32:
    263     case __NR_setregid32:
    264     case __NR_setresgid32:
    265     case __NR_setresuid32:
    266     case __NR_setreuid32:
    267     case __NR_setuid32:
    268 #endif
    269       return true;
    270     default:
    271       return false;
    272   }
    273 }
    274 
    275 bool SyscallSets::IsProcessGroupOrSession(int sysno) {
    276   switch (sysno) {
    277     case __NR_setpgid:
    278     case __NR_getpgrp:
    279     case __NR_setsid:
    280     case __NR_getpgid:
    281       return true;
    282     default:
    283       return false;
    284   }
    285 }
    286 
    287 bool SyscallSets::IsAllowedSignalHandling(int sysno) {
    288   switch (sysno) {
    289     case __NR_rt_sigaction:
    290     case __NR_rt_sigprocmask:
    291     case __NR_rt_sigreturn:
    292 #if defined(__i386__) || defined(__arm__)
    293     case __NR_sigaction:
    294     case __NR_sigprocmask:
    295     case __NR_sigreturn:
    296 #endif
    297       return true;
    298     case __NR_rt_sigpending:
    299     case __NR_rt_sigqueueinfo:
    300     case __NR_rt_sigsuspend:
    301     case __NR_rt_sigtimedwait:
    302     case __NR_rt_tgsigqueueinfo:
    303     case __NR_sigaltstack:
    304     case __NR_signalfd:
    305     case __NR_signalfd4:
    306 #if defined(__i386__) || defined(__arm__)
    307     case __NR_sigpending:
    308     case __NR_sigsuspend:
    309 #endif
    310 #if defined(__i386__)
    311     case __NR_signal:
    312     case __NR_sgetmask:  // Obsolete.
    313     case __NR_ssetmask:
    314 #endif
    315     default:
    316       return false;
    317   }
    318 }
    319 
    320 bool SyscallSets::IsAllowedOperationOnFd(int sysno) {
    321   switch (sysno) {
    322     case __NR_close:
    323     case __NR_dup:
    324     case __NR_dup2:
    325     case __NR_dup3:
    326 #if defined(__x86_64__) || defined(__arm__)
    327     case __NR_shutdown:
    328 #endif
    329       return true;
    330     case __NR_fcntl:
    331 #if defined(__i386__) || defined(__arm__)
    332     case __NR_fcntl64:
    333 #endif
    334     default:
    335       return false;
    336   }
    337 }
    338 
    339 bool SyscallSets::IsKernelInternalApi(int sysno) {
    340   switch (sysno) {
    341     case __NR_restart_syscall:
    342 #if defined(__arm__)
    343     case __ARM_NR_cmpxchg:
    344 #endif
    345       return true;
    346     default:
    347       return false;
    348   }
    349 }
    350 
    351 // This should be thought through in conjunction with IsFutex().
    352 bool SyscallSets::IsAllowedProcessStartOrDeath(int sysno) {
    353   switch (sysno) {
    354     case __NR_clone:  // TODO(jln): restrict flags.
    355     case __NR_exit:
    356     case __NR_exit_group:
    357     case __NR_wait4:
    358     case __NR_waitid:
    359 #if defined(__i386__)
    360     case __NR_waitpid:
    361 #endif
    362       return true;
    363     case __NR_setns:  // Privileged.
    364     case __NR_fork:
    365 #if defined(__i386__) || defined(__x86_64__)
    366     case __NR_get_thread_area:
    367     case __NR_set_thread_area:
    368 #endif
    369     case __NR_set_tid_address:
    370     case __NR_unshare:
    371     case __NR_vfork:
    372     default:
    373       return false;
    374   }
    375 }
    376 
    377 // It's difficult to restrict those, but there is attack surface here.
    378 bool SyscallSets::IsFutex(int sysno) {
    379   switch (sysno) {
    380     case __NR_futex:
    381     case __NR_get_robust_list:
    382     case __NR_set_robust_list:
    383       return true;
    384     default:
    385       return false;
    386   }
    387 }
    388 
    389 bool SyscallSets::IsAllowedEpoll(int sysno) {
    390   switch (sysno) {
    391     case __NR_epoll_create:
    392     case __NR_epoll_create1:
    393     case __NR_epoll_ctl:
    394     case __NR_epoll_wait:
    395       return true;
    396     default:
    397 #if defined(__x86_64__)
    398     case __NR_epoll_ctl_old:
    399 #endif
    400     case __NR_epoll_pwait:
    401 #if defined(__x86_64__)
    402     case __NR_epoll_wait_old:
    403 #endif
    404       return false;
    405   }
    406 }
    407 
    408 bool SyscallSets::IsAllowedGetOrModifySocket(int sysno) {
    409   switch (sysno) {
    410     case __NR_pipe:
    411     case __NR_pipe2:
    412       return true;
    413     default:
    414 #if defined(__x86_64__) || defined(__arm__)
    415     case __NR_socketpair:  // We will want to inspect its argument.
    416 #endif
    417       return false;
    418   }
    419 }
    420 
    421 bool SyscallSets::IsDeniedGetOrModifySocket(int sysno) {
    422   switch (sysno) {
    423 #if defined(__x86_64__) || defined(__arm__)
    424     case __NR_accept:
    425     case __NR_accept4:
    426     case __NR_bind:
    427     case __NR_connect:
    428     case __NR_socket:
    429     case __NR_listen:
    430       return true;
    431 #endif
    432     default:
    433       return false;
    434   }
    435 }
    436 
    437 #if defined(__i386__)
    438 // Big multiplexing system call for sockets.
    439 bool SyscallSets::IsSocketCall(int sysno) {
    440   switch (sysno) {
    441     case __NR_socketcall:
    442       return true;
    443     default:
    444       return false;
    445   }
    446 }
    447 #endif
    448 
    449 #if defined(__x86_64__) || defined(__arm__)
    450 bool SyscallSets::IsNetworkSocketInformation(int sysno) {
    451   switch (sysno) {
    452     case __NR_getpeername:
    453     case __NR_getsockname:
    454     case __NR_getsockopt:
    455     case __NR_setsockopt:
    456       return true;
    457     default:
    458       return false;
    459   }
    460 }
    461 #endif
    462 
    463 bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno) {
    464   switch (sysno) {
    465     case __NR_brk:
    466     case __NR_mlock:
    467     case __NR_munlock:
    468     case __NR_munmap:
    469       return true;
    470     case __NR_madvise:
    471     case __NR_mincore:
    472     case __NR_mlockall:
    473 #if defined(__i386__) || defined(__x86_64__)
    474     case __NR_mmap:
    475 #endif
    476 #if defined(__i386__) || defined(__arm__)
    477     case __NR_mmap2:
    478 #endif
    479 #if defined(__i386__) || defined(__x86_64__)
    480     case __NR_modify_ldt:
    481 #endif
    482     case __NR_mprotect:
    483     case __NR_mremap:
    484     case __NR_msync:
    485     case __NR_munlockall:
    486     case __NR_readahead:
    487     case __NR_remap_file_pages:
    488 #if defined(__i386__)
    489     case __NR_vm86:
    490     case __NR_vm86old:
    491 #endif
    492     default:
    493       return false;
    494   }
    495 }
    496 
    497 bool SyscallSets::IsAllowedGeneralIo(int sysno) {
    498   switch (sysno) {
    499     case __NR_lseek:
    500 #if defined(__i386__) || defined(__arm__)
    501     case __NR__llseek:
    502 #endif
    503     case __NR_poll:
    504     case __NR_ppoll:
    505     case __NR_pselect6:
    506     case __NR_read:
    507     case __NR_readv:
    508 #if defined(__arm__)
    509     case __NR_recv:
    510 #endif
    511 #if defined(__x86_64__) || defined(__arm__)
    512     case __NR_recvfrom:  // Could specify source.
    513     case __NR_recvmsg:   // Could specify source.
    514 #endif
    515 #if defined(__i386__) || defined(__x86_64__)
    516     case __NR_select:
    517 #endif
    518 #if defined(__i386__) || defined(__arm__)
    519     case __NR__newselect:
    520 #endif
    521 #if defined(__arm__)
    522     case __NR_send:
    523 #endif
    524 #if defined(__x86_64__) || defined(__arm__)
    525     case __NR_sendmsg:  // Could specify destination.
    526     case __NR_sendto:   // Could specify destination.
    527 #endif
    528     case __NR_write:
    529     case __NR_writev:
    530       return true;
    531     case __NR_ioctl:  // Can be very powerful.
    532     case __NR_pread64:
    533     case __NR_preadv:
    534     case __NR_pwrite64:
    535     case __NR_pwritev:
    536     case __NR_recvmmsg:  // Could specify source.
    537     case __NR_sendfile:
    538 #if defined(__i386__) || defined(__arm__)
    539     case __NR_sendfile64:
    540 #endif
    541     case __NR_sendmmsg:  // Could specify destination.
    542     case __NR_splice:
    543     case __NR_tee:
    544     case __NR_vmsplice:
    545     default:
    546       return false;
    547   }
    548 }
    549 
    550 bool SyscallSets::IsAllowedPrctl(int sysno) {
    551   switch (sysno) {
    552     case __NR_prctl:
    553       return true;
    554     default:
    555 #if defined(__x86_64__)
    556     case __NR_arch_prctl:
    557 #endif
    558       return false;
    559   }
    560 }
    561 
    562 bool SyscallSets::IsAllowedBasicScheduler(int sysno) {
    563   switch (sysno) {
    564     case __NR_sched_yield:
    565     case __NR_pause:
    566     case __NR_nanosleep:
    567       return true;
    568     case __NR_getpriority:
    569 #if defined(__i386__) || defined(__arm__)
    570     case __NR_nice:
    571 #endif
    572     case __NR_setpriority:
    573     default:
    574       return false;
    575   }
    576 }
    577 
    578 bool SyscallSets::IsAdminOperation(int sysno) {
    579   switch (sysno) {
    580 #if defined(__i386__) || defined(__arm__)
    581     case __NR_bdflush:
    582 #endif
    583     case __NR_kexec_load:
    584     case __NR_reboot:
    585     case __NR_setdomainname:
    586     case __NR_sethostname:
    587     case __NR_syslog:
    588       return true;
    589     default:
    590       return false;
    591   }
    592 }
    593 
    594 bool SyscallSets::IsKernelModule(int sysno) {
    595   switch (sysno) {
    596 #if defined(__i386__) || defined(__x86_64__)
    597     case __NR_create_module:
    598     case __NR_get_kernel_syms:  // Should ENOSYS.
    599     case __NR_query_module:
    600 #endif
    601     case __NR_delete_module:
    602     case __NR_init_module:
    603       return true;
    604     default:
    605       return false;
    606   }
    607 }
    608 
    609 bool SyscallSets::IsGlobalFSViewChange(int sysno) {
    610   switch (sysno) {
    611     case __NR_pivot_root:
    612     case __NR_chroot:
    613     case __NR_sync:
    614       return true;
    615     default:
    616       return false;
    617   }
    618 }
    619 
    620 bool SyscallSets::IsFsControl(int sysno) {
    621   switch (sysno) {
    622     case __NR_mount:
    623     case __NR_nfsservctl:
    624     case __NR_quotactl:
    625     case __NR_swapoff:
    626     case __NR_swapon:
    627 #if defined(__i386__)
    628     case __NR_umount:
    629 #endif
    630     case __NR_umount2:
    631       return true;
    632     default:
    633       return false;
    634   }
    635 }
    636 
    637 bool SyscallSets::IsNuma(int sysno) {
    638   switch (sysno) {
    639     case __NR_get_mempolicy:
    640     case __NR_getcpu:
    641     case __NR_mbind:
    642 #if defined(__i386__) || defined(__x86_64__)
    643     case __NR_migrate_pages:
    644 #endif
    645     case __NR_move_pages:
    646     case __NR_set_mempolicy:
    647       return true;
    648     default:
    649       return false;
    650   }
    651 }
    652 
    653 bool SyscallSets::IsMessageQueue(int sysno) {
    654   switch (sysno) {
    655     case __NR_mq_getsetattr:
    656     case __NR_mq_notify:
    657     case __NR_mq_open:
    658     case __NR_mq_timedreceive:
    659     case __NR_mq_timedsend:
    660     case __NR_mq_unlink:
    661       return true;
    662     default:
    663       return false;
    664   }
    665 }
    666 
    667 bool SyscallSets::IsGlobalProcessEnvironment(int sysno) {
    668   switch (sysno) {
    669     case __NR_acct:  // Privileged.
    670 #if defined(__i386__) || defined(__x86_64__)
    671     case __NR_getrlimit:
    672 #endif
    673 #if defined(__i386__) || defined(__arm__)
    674     case __NR_ugetrlimit:
    675 #endif
    676 #if defined(__i386__)
    677     case __NR_ulimit:
    678 #endif
    679     case __NR_getrusage:
    680     case __NR_personality:  // Can change its personality as well.
    681     case __NR_prlimit64:    // Like setrlimit / getrlimit.
    682     case __NR_setrlimit:
    683     case __NR_times:
    684       return true;
    685     default:
    686       return false;
    687   }
    688 }
    689 
    690 bool SyscallSets::IsDebug(int sysno) {
    691   switch (sysno) {
    692     case __NR_ptrace:
    693     case __NR_process_vm_readv:
    694     case __NR_process_vm_writev:
    695 #if defined(__i386__) || defined(__x86_64__)
    696     case __NR_kcmp:
    697 #endif
    698       return true;
    699     default:
    700       return false;
    701   }
    702 }
    703 
    704 bool SyscallSets::IsGlobalSystemStatus(int sysno) {
    705   switch (sysno) {
    706     case __NR__sysctl:
    707     case __NR_sysfs:
    708     case __NR_sysinfo:
    709     case __NR_uname:
    710 #if defined(__i386__)
    711     case __NR_olduname:
    712     case __NR_oldolduname:
    713 #endif
    714       return true;
    715     default:
    716       return false;
    717   }
    718 }
    719 
    720 bool SyscallSets::IsEventFd(int sysno) {
    721   switch (sysno) {
    722     case __NR_eventfd:
    723     case __NR_eventfd2:
    724       return true;
    725     default:
    726       return false;
    727   }
    728 }
    729 
    730 // Asynchronous I/O API.
    731 bool SyscallSets::IsAsyncIo(int sysno) {
    732   switch (sysno) {
    733     case __NR_io_cancel:
    734     case __NR_io_destroy:
    735     case __NR_io_getevents:
    736     case __NR_io_setup:
    737     case __NR_io_submit:
    738       return true;
    739     default:
    740       return false;
    741   }
    742 }
    743 
    744 bool SyscallSets::IsKeyManagement(int sysno) {
    745   switch (sysno) {
    746     case __NR_add_key:
    747     case __NR_keyctl:
    748     case __NR_request_key:
    749       return true;
    750     default:
    751       return false;
    752   }
    753 }
    754 
    755 #if defined(__x86_64__) || defined(__arm__)
    756 bool SyscallSets::IsSystemVSemaphores(int sysno) {
    757   switch (sysno) {
    758     case __NR_semctl:
    759     case __NR_semget:
    760     case __NR_semop:
    761     case __NR_semtimedop:
    762       return true;
    763     default:
    764       return false;
    765   }
    766 }
    767 #endif
    768 
    769 #if defined(__x86_64__) || defined(__arm__)
    770 // These give a lot of ambient authority and bypass the setuid sandbox.
    771 bool SyscallSets::IsSystemVSharedMemory(int sysno) {
    772   switch (sysno) {
    773     case __NR_shmat:
    774     case __NR_shmctl:
    775     case __NR_shmdt:
    776     case __NR_shmget:
    777       return true;
    778     default:
    779       return false;
    780   }
    781 }
    782 #endif
    783 
    784 #if defined(__x86_64__) || defined(__arm__)
    785 bool SyscallSets::IsSystemVMessageQueue(int sysno) {
    786   switch (sysno) {
    787     case __NR_msgctl:
    788     case __NR_msgget:
    789     case __NR_msgrcv:
    790     case __NR_msgsnd:
    791       return true;
    792     default:
    793       return false;
    794   }
    795 }
    796 #endif
    797 
    798 #if defined(__i386__)
    799 // Big system V multiplexing system call.
    800 bool SyscallSets::IsSystemVIpc(int sysno) {
    801   switch (sysno) {
    802     case __NR_ipc:
    803       return true;
    804     default:
    805       return false;
    806   }
    807 }
    808 #endif
    809 
    810 bool SyscallSets::IsAnySystemV(int sysno) {
    811 #if defined(__x86_64__) || defined(__arm__)
    812   return IsSystemVMessageQueue(sysno) || IsSystemVSemaphores(sysno) ||
    813          IsSystemVSharedMemory(sysno);
    814 #elif defined(__i386__)
    815   return IsSystemVIpc(sysno);
    816 #endif
    817 }
    818 
    819 bool SyscallSets::IsAdvancedScheduler(int sysno) {
    820   switch (sysno) {
    821     case __NR_ioprio_get:  // IO scheduler.
    822     case __NR_ioprio_set:
    823     case __NR_sched_get_priority_max:
    824     case __NR_sched_get_priority_min:
    825     case __NR_sched_getaffinity:
    826     case __NR_sched_getparam:
    827     case __NR_sched_getscheduler:
    828     case __NR_sched_rr_get_interval:
    829     case __NR_sched_setaffinity:
    830     case __NR_sched_setparam:
    831     case __NR_sched_setscheduler:
    832       return true;
    833     default:
    834       return false;
    835   }
    836 }
    837 
    838 bool SyscallSets::IsInotify(int sysno) {
    839   switch (sysno) {
    840     case __NR_inotify_add_watch:
    841     case __NR_inotify_init:
    842     case __NR_inotify_init1:
    843     case __NR_inotify_rm_watch:
    844       return true;
    845     default:
    846       return false;
    847   }
    848 }
    849 
    850 bool SyscallSets::IsFaNotify(int sysno) {
    851   switch (sysno) {
    852     case __NR_fanotify_init:
    853     case __NR_fanotify_mark:
    854       return true;
    855     default:
    856       return false;
    857   }
    858 }
    859 
    860 bool SyscallSets::IsTimer(int sysno) {
    861   switch (sysno) {
    862     case __NR_getitimer:
    863 #if defined(__i386__) || defined(__x86_64__)
    864     case __NR_alarm:
    865 #endif
    866     case __NR_setitimer:
    867       return true;
    868     default:
    869       return false;
    870   }
    871 }
    872 
    873 bool SyscallSets::IsAdvancedTimer(int sysno) {
    874   switch (sysno) {
    875     case __NR_timer_create:
    876     case __NR_timer_delete:
    877     case __NR_timer_getoverrun:
    878     case __NR_timer_gettime:
    879     case __NR_timer_settime:
    880     case __NR_timerfd_create:
    881     case __NR_timerfd_gettime:
    882     case __NR_timerfd_settime:
    883       return true;
    884     default:
    885       return false;
    886   }
    887 }
    888 
    889 bool SyscallSets::IsExtendedAttributes(int sysno) {
    890   switch (sysno) {
    891     case __NR_fgetxattr:
    892     case __NR_flistxattr:
    893     case __NR_fremovexattr:
    894     case __NR_fsetxattr:
    895     case __NR_getxattr:
    896     case __NR_lgetxattr:
    897     case __NR_listxattr:
    898     case __NR_llistxattr:
    899     case __NR_lremovexattr:
    900     case __NR_lsetxattr:
    901     case __NR_removexattr:
    902     case __NR_setxattr:
    903       return true;
    904     default:
    905       return false;
    906   }
    907 }
    908 
    909 // Various system calls that need to be researched.
    910 // TODO(jln): classify this better.
    911 bool SyscallSets::IsMisc(int sysno) {
    912   switch (sysno) {
    913     case __NR_name_to_handle_at:
    914     case __NR_open_by_handle_at:
    915     case __NR_perf_event_open:
    916     case __NR_syncfs:
    917     case __NR_vhangup:
    918 // The system calls below are not implemented.
    919 #if defined(__i386__) || defined(__x86_64__)
    920     case __NR_afs_syscall:
    921 #endif
    922 #if defined(__i386__)
    923     case __NR_break:
    924 #endif
    925 #if defined(__i386__) || defined(__x86_64__)
    926     case __NR_getpmsg:
    927 #endif
    928 #if defined(__i386__)
    929     case __NR_gtty:
    930     case __NR_idle:
    931     case __NR_lock:
    932     case __NR_mpx:
    933     case __NR_prof:
    934     case __NR_profil:
    935 #endif
    936 #if defined(__i386__) || defined(__x86_64__)
    937     case __NR_putpmsg:
    938 #endif
    939 #if defined(__x86_64__)
    940     case __NR_security:
    941 #endif
    942 #if defined(__i386__)
    943     case __NR_stty:
    944 #endif
    945 #if defined(__x86_64__)
    946     case __NR_tuxcall:
    947 #endif
    948     case __NR_vserver:
    949       return true;
    950     default:
    951       return false;
    952   }
    953 }
    954 
    955 #if defined(__arm__)
    956 bool SyscallSets::IsArmPciConfig(int sysno) {
    957   switch (sysno) {
    958     case __NR_pciconfig_iobase:
    959     case __NR_pciconfig_read:
    960     case __NR_pciconfig_write:
    961       return true;
    962     default:
    963       return false;
    964   }
    965 }
    966 
    967 bool SyscallSets::IsArmPrivate(int sysno) {
    968   switch (sysno) {
    969     case __ARM_NR_breakpoint:
    970     case __ARM_NR_cacheflush:
    971     case __ARM_NR_set_tls:
    972     case __ARM_NR_usr26:
    973     case __ARM_NR_usr32:
    974       return true;
    975     default:
    976       return false;
    977   }
    978 }
    979 #endif  // defined(__arm__)
    980 
    981 }  // namespace sandbox.
    982