path: root/kernel/sys.c
diff options
authorWill Drewry <>2012-04-12 16:47:57 -0500
committerJames Morris <>2012-04-14 11:13:20 +1000
commite2cfabdfd075648216f99c2c03821cf3f47c1727 (patch)
treed207e062d5b0bbd421aace9f7dfdc144aab4ed18 /kernel/sys.c
parentb7456536cf9466b402b540c5588d79a4177c723a (diff)
seccomp: add system call filtering using BPF
[This patch depends on's no_new_privs patch: The whole series including Andrew's patches can be found here: Complete diff here: ] This patch adds support for seccomp mode 2. Mode 2 introduces the ability for unprivileged processes to install system call filtering policy expressed in terms of a Berkeley Packet Filter (BPF) program. This program will be evaluated in the kernel for each system call the task makes and computes a result based on data in the format of struct seccomp_data. A filter program may be installed by calling: struct sock_fprog fprog = { ... }; ... prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &fprog); The return value of the filter program determines if the system call is allowed to proceed or denied. If the first filter program installed allows prctl(2) calls, then the above call may be made repeatedly by a task to further reduce its access to the kernel. All attached programs must be evaluated before a system call will be allowed to proceed. Filter programs will be inherited across fork/clone and execve. However, if the task attaching the filter is unprivileged (!CAP_SYS_ADMIN) the no_new_privs bit will be set on the task. This ensures that unprivileged tasks cannot attach filters that affect privileged tasks (e.g., setuid binary). There are a number of benefits to this approach. A few of which are as follows: - BPF has been exposed to userland for a long time - BPF optimization (and JIT'ing) are well understood - Userland already knows its ABI: system call numbers and desired arguments - No time-of-check-time-of-use vulnerable data accesses are possible. - system call arguments are loaded on access only to minimize copying required for system call policy decisions. Mode 2 support is restricted to architectures that enable HAVE_ARCH_SECCOMP_FILTER. In this patch, the primary dependency is on syscall_get_arguments(). The full desired scope of this feature will add a few minor additional requirements expressed later in this series. Based on discussion, SECCOMP_RET_ERRNO and SECCOMP_RET_TRACE seem to be the desired additional functionality. No architectures are enabled in this patch. Signed-off-by: Will Drewry <> Acked-by: Serge Hallyn <> Reviewed-by: Indan Zupancic <> Acked-by: Eric Paris <> Reviewed-by: Kees Cook <> v18: - rebase to v3.4-rc2 - s/chk/check/ (, - allocate with GFP_KERNEL|__GFP_NOWARN ( - add a comment for get_u32 regarding endianness (akpm@) - fix other typos, style mistakes (akpm@) - added acked-by v17: - properly guard seccomp filter needed headers ( - tighten return mask to 0x7fff0000 v16: - no change v15: - add a 4 instr penalty when counting a path to account for seccomp_filter size ( - drop the max insns to 256KB ( - return ENOMEM if the max insns limit has been hit ( - move IP checks after args ( - drop !user_filter check ( - only allow explicit bpf codes ( - exit_code -> exit_sig v14: - put/get_seccomp_filter takes struct task_struct (, - adds seccomp_chk_filter and drops general bpf_run/chk_filter user - add seccomp_bpf_load for use by net/core/filter.c - lower max per-process/per-hierarchy: 1MB - moved nnp/capability check prior to allocation (all of the above: v13: - rebase on to 88ebdda6159ffc15699f204c33feb3e431bf9bdc v12: - added a maximum instruction count per path (, - removed copy_seccomp (, - reworded the prctl_set_seccomp comment ( v11: - reorder struct seccomp_data to allow future args expansion ( - style clean up, @compat dropped, compat_sock_fprog32 ( - do_exit(SIGSYS) (, - pare down Kconfig doc reference. - extra comment clean up v10: - seccomp_data has changed again to be more aesthetically pleasing ( - calling convention is noted in a new u32 field using syscall_get_arch. This allows for cross-calling convention tasks to use seccomp filters. ( - lots of clean up (thanks, Indan!) v9: - n/a v8: - use bpf_chk_filter, bpf_run_filter. update load_fns - Lots of fixes courtesy of -- fix up load behavior, compat fixups, and merge alloc code, -- renamed pc and dropped __packed, use bool compat. -- Added a hidden CONFIG_SECCOMP_FILTER to synthesize non-arch dependencies v7: (massive overhaul thanks to Indan, others) - added CONFIG_HAVE_ARCH_SECCOMP_FILTER - merged into seccomp.c - minimal seccomp_filter.h - no config option (part of seccomp) - no new prctl - doesn't break seccomp on systems without asm/syscall.h (works but arg access always fails) - dropped seccomp_init_task, extra free functions, ... - dropped the no-asm/syscall.h code paths - merges with network sk_run_filter and sk_chk_filter v6: - fix memory leak on attach compat check failure - require no_new_privs || CAP_SYS_ADMIN prior to filter installation. ( - s/seccomp_struct_/seccomp_/ for macros/functions ( - cleaned up Kconfig ( - on block, note if the call was compat (so the # means something) v5: - uses syscall_get_arguments (,, - uses union-based arg storage with hi/lo struct to handle endianness. Compromises between the two alternate proposals to minimize extra arg shuffling and account for endianness assuming userspace uses offsetof(). (, - update Kconfig description - add include/seccomp_filter.h and add its installation - (naive) on-demand syscall argument loading - drop seccomp_t ( v4: - adjusted prctl to make room for PR_[SG]ET_NO_NEW_PRIVS - now uses current->no_new_privs (, - assign names to seccomp modes ( - fix style issues ( - reworded Kconfig entry ( v3: - macros to inline ( - init_task behavior fixed ( - drop creator entry and extra NULL check ( - alloc returns -EINVAL on bad sizing ( - adds tentative use of "always_unprivileged" as per and v2: - (patch 2 only) Signed-off-by: James Morris <>
Diffstat (limited to 'kernel/sys.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/sys.c b/kernel/sys.c
index b82568b7d201..ba0ae8eea6fb 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1908,7 +1908,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
error = prctl_get_seccomp();
- error = prctl_set_seccomp(arg2);
+ error = prctl_set_seccomp(arg2, (char __user *)arg3);
case PR_GET_TSC:
error = GET_TSC_CTL(arg2);