Skip to content

Commit c0a3a64

Browse files
committed
Merge tag 'seccomp-v4.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull seccomp updates from Kees Cook: "Major additions: - sysctl and seccomp operation to discover available actions (tyhicks) - new per-filter configurable logging infrastructure and sysctl (tyhicks) - SECCOMP_RET_LOG to log allowed syscalls (tyhicks) - SECCOMP_RET_KILL_PROCESS as the new strictest possible action - self-tests for new behaviors" [ This is the seccomp part of the security pull request during the merge window that was nixed due to unrelated problems - Linus ] * tag 'seccomp-v4.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: samples: Unrename SECCOMP_RET_KILL selftests/seccomp: Test thread vs process killing seccomp: Implement SECCOMP_RET_KILL_PROCESS action seccomp: Introduce SECCOMP_RET_KILL_PROCESS seccomp: Rename SECCOMP_RET_KILL to SECCOMP_RET_KILL_THREAD seccomp: Action to log before allowing seccomp: Filter flag to log all actions except SECCOMP_RET_ALLOW seccomp: Selftest for detection of filter flag support seccomp: Sysctl to configure actions that are allowed to be logged seccomp: Operation for checking if an action is available seccomp: Sysctl to display available actions seccomp: Provide matching filter for introspection selftests/seccomp: Refactor RET_ERRNO tests selftests/seccomp: Add simple seccomp overhead benchmark selftests/seccomp: Add tests for basic ptrace actions
2 parents 69c902f + 6849243 commit c0a3a64

File tree

10 files changed

+1006
-129
lines changed

10 files changed

+1006
-129
lines changed

Documentation/networking/filter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ Examples for low-level BPF:
337337
jeq #14, good /* __NR_rt_sigprocmask */
338338
jeq #13, good /* __NR_rt_sigaction */
339339
jeq #35, good /* __NR_nanosleep */
340-
bad: ret #0 /* SECCOMP_RET_KILL */
340+
bad: ret #0 /* SECCOMP_RET_KILL_THREAD */
341341
good: ret #0x7fff0000 /* SECCOMP_RET_ALLOW */
342342

343343
The above example code can be placed into a file (here called "foo"), and

Documentation/sysctl/kernel.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ show up in /proc/sys/kernel:
7575
- reboot-cmd [ SPARC only ]
7676
- rtsig-max
7777
- rtsig-nr
78+
- seccomp/ ==> Documentation/userspace-api/seccomp_filter.rst
7879
- sem
7980
- sem_next_id [ sysv ipc ]
8081
- sg-big-buff [ generic SCSI device (sg) ]

Documentation/userspace-api/seccomp_filter.rst

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,16 @@ Return values
8787
A seccomp filter may return any of the following values. If multiple
8888
filters exist, the return value for the evaluation of a given system
8989
call will always use the highest precedent value. (For example,
90-
``SECCOMP_RET_KILL`` will always take precedence.)
90+
``SECCOMP_RET_KILL_PROCESS`` will always take precedence.)
9191

9292
In precedence order, they are:
9393

94-
``SECCOMP_RET_KILL``:
94+
``SECCOMP_RET_KILL_PROCESS``:
95+
Results in the entire process exiting immediately without executing
96+
the system call. The exit status of the task (``status & 0x7f``)
97+
will be ``SIGSYS``, not ``SIGKILL``.
98+
99+
``SECCOMP_RET_KILL_THREAD``:
95100
Results in the task exiting immediately without executing the
96101
system call. The exit status of the task (``status & 0x7f``) will
97102
be ``SIGSYS``, not ``SIGKILL``.
@@ -141,6 +146,15 @@ In precedence order, they are:
141146
allow use of ptrace, even of other sandboxed processes, without
142147
extreme care; ptracers can use this mechanism to escape.)
143148

149+
``SECCOMP_RET_LOG``:
150+
Results in the system call being executed after it is logged. This
151+
should be used by application developers to learn which syscalls their
152+
application needs without having to iterate through multiple test and
153+
development cycles to build the list.
154+
155+
This action will only be logged if "log" is present in the
156+
actions_logged sysctl string.
157+
144158
``SECCOMP_RET_ALLOW``:
145159
Results in the system call being executed.
146160

@@ -169,7 +183,41 @@ The ``samples/seccomp/`` directory contains both an x86-specific example
169183
and a more generic example of a higher level macro interface for BPF
170184
program generation.
171185

186+
Sysctls
187+
=======
172188

189+
Seccomp's sysctl files can be found in the ``/proc/sys/kernel/seccomp/``
190+
directory. Here's a description of each file in that directory:
191+
192+
``actions_avail``:
193+
A read-only ordered list of seccomp return values (refer to the
194+
``SECCOMP_RET_*`` macros above) in string form. The ordering, from
195+
left-to-right, is the least permissive return value to the most
196+
permissive return value.
197+
198+
The list represents the set of seccomp return values supported
199+
by the kernel. A userspace program may use this list to
200+
determine if the actions found in the ``seccomp.h``, when the
201+
program was built, differs from the set of actions actually
202+
supported in the current running kernel.
203+
204+
``actions_logged``:
205+
A read-write ordered list of seccomp return values (refer to the
206+
``SECCOMP_RET_*`` macros above) that are allowed to be logged. Writes
207+
to the file do not need to be in ordered form but reads from the file
208+
will be ordered in the same way as the actions_avail sysctl.
209+
210+
It is important to note that the value of ``actions_logged`` does not
211+
prevent certain actions from being logged when the audit subsystem is
212+
configured to audit a task. If the action is not found in
213+
``actions_logged`` list, the final decision on whether to audit the
214+
action for that task is ultimately left up to the audit subsystem to
215+
decide for all seccomp return values other than ``SECCOMP_RET_ALLOW``.
216+
217+
The ``allow`` string is not accepted in the ``actions_logged`` sysctl
218+
as it is not possible to log ``SECCOMP_RET_ALLOW`` actions. Attempting
219+
to write ``allow`` to the sysctl will result in an EINVAL being
220+
returned.
173221

174222
Adding architecture support
175223
===========================

include/linux/audit.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,7 @@ void audit_core_dumps(long signr);
314314

315315
static inline void audit_seccomp(unsigned long syscall, long signr, int code)
316316
{
317-
if (!audit_enabled)
318-
return;
319-
320-
/* Force a record to be reported if a signal was delivered. */
321-
if (signr || unlikely(!audit_dummy_context()))
317+
if (audit_enabled && unlikely(!audit_dummy_context()))
322318
__audit_seccomp(syscall, signr, code);
323319
}
324320

include/linux/seccomp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
#include <uapi/linux/seccomp.h>
55

6-
#define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC)
6+
#define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC | \
7+
SECCOMP_FILTER_FLAG_LOG)
78

89
#ifdef CONFIG_SECCOMP
910

include/uapi/linux/seccomp.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,34 @@
1111
#define SECCOMP_MODE_FILTER 2 /* uses user-supplied filter. */
1212

1313
/* Valid operations for seccomp syscall. */
14-
#define SECCOMP_SET_MODE_STRICT 0
15-
#define SECCOMP_SET_MODE_FILTER 1
14+
#define SECCOMP_SET_MODE_STRICT 0
15+
#define SECCOMP_SET_MODE_FILTER 1
16+
#define SECCOMP_GET_ACTION_AVAIL 2
1617

1718
/* Valid flags for SECCOMP_SET_MODE_FILTER */
1819
#define SECCOMP_FILTER_FLAG_TSYNC 1
20+
#define SECCOMP_FILTER_FLAG_LOG 2
1921

2022
/*
2123
* All BPF programs must return a 32-bit value.
2224
* The bottom 16-bits are for optional return data.
23-
* The upper 16-bits are ordered from least permissive values to most.
25+
* The upper 16-bits are ordered from least permissive values to most,
26+
* as a signed value (so 0x8000000 is negative).
2427
*
2528
* The ordering ensures that a min_t() over composed return values always
2629
* selects the least permissive choice.
2730
*/
28-
#define SECCOMP_RET_KILL 0x00000000U /* kill the task immediately */
29-
#define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
30-
#define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
31-
#define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
32-
#define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
31+
#define SECCOMP_RET_KILL_PROCESS 0x80000000U /* kill the process */
32+
#define SECCOMP_RET_KILL_THREAD 0x00000000U /* kill the thread */
33+
#define SECCOMP_RET_KILL SECCOMP_RET_KILL_THREAD
34+
#define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
35+
#define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
36+
#define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
37+
#define SECCOMP_RET_LOG 0x7ffc0000U /* allow after logging */
38+
#define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
3339

3440
/* Masks for the return value sections. */
41+
#define SECCOMP_RET_ACTION_FULL 0xffff0000U
3542
#define SECCOMP_RET_ACTION 0x7fff0000U
3643
#define SECCOMP_RET_DATA 0x0000ffffU
3744

0 commit comments

Comments
 (0)