Skip to content

Commit fd76875

Browse files
committed
seccomp: Rename SECCOMP_RET_KILL to SECCOMP_RET_KILL_THREAD
In preparation for adding SECCOMP_RET_KILL_PROCESS, rename SECCOMP_RET_KILL to the more accurate SECCOMP_RET_KILL_THREAD. The existing selftest values are intentionally left as SECCOMP_RET_KILL just to be sure we're exercising the alias. Signed-off-by: Kees Cook <[email protected]>
1 parent 59f5cf4 commit fd76875

File tree

7 files changed

+39
-32
lines changed

7 files changed

+39
-32
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/userspace-api/seccomp_filter.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ 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_THREAD`` will always take precedence.)
9191

9292
In precedence order, they are:
9393

94-
``SECCOMP_RET_KILL``:
94+
``SECCOMP_RET_KILL_THREAD``:
9595
Results in the task exiting immediately without executing the
9696
system call. The exit status of the task (``status & 0x7f``) will
9797
be ``SIGSYS``, not ``SIGKILL``.

include/uapi/linux/seccomp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
* The ordering ensures that a min_t() over composed return values always
2828
* selects the least permissive choice.
2929
*/
30-
#define SECCOMP_RET_KILL 0x00000000U /* kill the task immediately */
30+
#define SECCOMP_RET_KILL_THREAD 0x00000000U /* kill the thread */
31+
#define SECCOMP_RET_KILL SECCOMP_RET_KILL_THREAD
3132
#define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
3233
#define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
3334
#define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */

kernel/seccomp.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static u32 seccomp_run_filters(const struct seccomp_data *sd,
192192

193193
/* Ensure unexpected behavior doesn't result in failing open. */
194194
if (unlikely(WARN_ON(f == NULL)))
195-
return SECCOMP_RET_KILL;
195+
return SECCOMP_RET_KILL_THREAD;
196196

197197
if (!sd) {
198198
populate_seccomp_data(&sd_local);
@@ -529,15 +529,17 @@ static void seccomp_send_sigsys(int syscall, int reason)
529529
#endif /* CONFIG_SECCOMP_FILTER */
530530

531531
/* For use with seccomp_actions_logged */
532-
#define SECCOMP_LOG_KILL (1 << 0)
532+
#define SECCOMP_LOG_KILL_THREAD (1 << 0)
533533
#define SECCOMP_LOG_TRAP (1 << 2)
534534
#define SECCOMP_LOG_ERRNO (1 << 3)
535535
#define SECCOMP_LOG_TRACE (1 << 4)
536536
#define SECCOMP_LOG_LOG (1 << 5)
537537
#define SECCOMP_LOG_ALLOW (1 << 6)
538538

539-
static u32 seccomp_actions_logged = SECCOMP_LOG_KILL | SECCOMP_LOG_TRAP |
540-
SECCOMP_LOG_ERRNO | SECCOMP_LOG_TRACE |
539+
static u32 seccomp_actions_logged = SECCOMP_LOG_KILL_THREAD |
540+
SECCOMP_LOG_TRAP |
541+
SECCOMP_LOG_ERRNO |
542+
SECCOMP_LOG_TRACE |
541543
SECCOMP_LOG_LOG;
542544

543545
static inline void seccomp_log(unsigned long syscall, long signr, u32 action,
@@ -560,13 +562,13 @@ static inline void seccomp_log(unsigned long syscall, long signr, u32 action,
560562
case SECCOMP_RET_LOG:
561563
log = seccomp_actions_logged & SECCOMP_LOG_LOG;
562564
break;
563-
case SECCOMP_RET_KILL:
565+
case SECCOMP_RET_KILL_THREAD:
564566
default:
565-
log = seccomp_actions_logged & SECCOMP_LOG_KILL;
567+
log = seccomp_actions_logged & SECCOMP_LOG_KILL_THREAD;
566568
}
567569

568570
/*
569-
* Force an audit message to be emitted when the action is RET_KILL,
571+
* Force an audit message to be emitted when the action is RET_KILL_*,
570572
* RET_LOG, or the FILTER_FLAG_LOG bit was set and the action is
571573
* allowed to be logged by the admin.
572574
*/
@@ -605,7 +607,7 @@ static void __secure_computing_strict(int this_syscall)
605607
#ifdef SECCOMP_DEBUG
606608
dump_stack();
607609
#endif
608-
seccomp_log(this_syscall, SIGKILL, SECCOMP_RET_KILL, true);
610+
seccomp_log(this_syscall, SIGKILL, SECCOMP_RET_KILL_THREAD, true);
609611
do_exit(SIGKILL);
610612
}
611613

@@ -716,7 +718,7 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
716718
*/
717719
return 0;
718720

719-
case SECCOMP_RET_KILL:
721+
case SECCOMP_RET_KILL_THREAD:
720722
default:
721723
seccomp_log(this_syscall, SIGSYS, action, true);
722724
/* Dump core only if this is the last remaining thread. */
@@ -878,7 +880,7 @@ static long seccomp_get_action_avail(const char __user *uaction)
878880
return -EFAULT;
879881

880882
switch (action) {
881-
case SECCOMP_RET_KILL:
883+
case SECCOMP_RET_KILL_THREAD:
882884
case SECCOMP_RET_TRAP:
883885
case SECCOMP_RET_ERRNO:
884886
case SECCOMP_RET_TRACE:
@@ -1029,27 +1031,28 @@ long seccomp_get_filter(struct task_struct *task, unsigned long filter_off,
10291031
#ifdef CONFIG_SYSCTL
10301032

10311033
/* Human readable action names for friendly sysctl interaction */
1032-
#define SECCOMP_RET_KILL_NAME "kill"
1034+
#define SECCOMP_RET_KILL_THREAD_NAME "kill_thread"
10331035
#define SECCOMP_RET_TRAP_NAME "trap"
10341036
#define SECCOMP_RET_ERRNO_NAME "errno"
10351037
#define SECCOMP_RET_TRACE_NAME "trace"
10361038
#define SECCOMP_RET_LOG_NAME "log"
10371039
#define SECCOMP_RET_ALLOW_NAME "allow"
10381040

1039-
static const char seccomp_actions_avail[] = SECCOMP_RET_KILL_NAME " "
1040-
SECCOMP_RET_TRAP_NAME " "
1041-
SECCOMP_RET_ERRNO_NAME " "
1042-
SECCOMP_RET_TRACE_NAME " "
1043-
SECCOMP_RET_LOG_NAME " "
1044-
SECCOMP_RET_ALLOW_NAME;
1041+
static const char seccomp_actions_avail[] =
1042+
SECCOMP_RET_KILL_THREAD_NAME " "
1043+
SECCOMP_RET_TRAP_NAME " "
1044+
SECCOMP_RET_ERRNO_NAME " "
1045+
SECCOMP_RET_TRACE_NAME " "
1046+
SECCOMP_RET_LOG_NAME " "
1047+
SECCOMP_RET_ALLOW_NAME;
10451048

10461049
struct seccomp_log_name {
10471050
u32 log;
10481051
const char *name;
10491052
};
10501053

10511054
static const struct seccomp_log_name seccomp_log_names[] = {
1052-
{ SECCOMP_LOG_KILL, SECCOMP_RET_KILL_NAME },
1055+
{ SECCOMP_LOG_KILL_THREAD, SECCOMP_RET_KILL_THREAD_NAME },
10531056
{ SECCOMP_LOG_TRAP, SECCOMP_RET_TRAP_NAME },
10541057
{ SECCOMP_LOG_ERRNO, SECCOMP_RET_ERRNO_NAME },
10551058
{ SECCOMP_LOG_TRACE, SECCOMP_RET_TRACE_NAME },

samples/seccomp/bpf-direct.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static int install_filter(void)
129129
/* Check that read is only using stdin. */
130130
BPF_STMT(BPF_LD+BPF_W+BPF_ABS, syscall_arg(0)),
131131
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, STDIN_FILENO, 4, 0),
132-
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL),
132+
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL_THREAD),
133133

134134
/* Check that write is only using stdout */
135135
BPF_STMT(BPF_LD+BPF_W+BPF_ABS, syscall_arg(0)),
@@ -139,7 +139,7 @@ static int install_filter(void)
139139

140140
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW),
141141
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_TRAP),
142-
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL),
142+
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL_THREAD),
143143
};
144144
struct sock_fprog prog = {
145145
.len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),

samples/seccomp/bpf-helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void seccomp_bpf_print(struct sock_filter *filter, size_t count);
4444
#define ALLOW \
4545
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW)
4646
#define DENY \
47-
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL)
47+
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL_THREAD)
4848
#define JUMP(labels, label) \
4949
BPF_JUMP(BPF_JMP+BPF_JA, FIND_LABEL((labels), (label)), \
5050
JUMP_JT, JUMP_JF)

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,18 @@
6868
#define SECCOMP_MODE_FILTER 2
6969
#endif
7070

71+
#ifndef SECCOMP_RET_KILL_THREAD
72+
#define SECCOMP_RET_KILL_THREAD 0x00000000U /* kill the thread */
73+
#endif
7174
#ifndef SECCOMP_RET_KILL
72-
#define SECCOMP_RET_KILL 0x00000000U /* kill the task immediately */
73-
#define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
74-
#define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
75-
#define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
76-
#define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
75+
#define SECCOMP_RET_KILL SECCOMP_RET_KILL_THREAD
76+
#define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
77+
#define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
78+
#define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
79+
#define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
7780
#endif
7881
#ifndef SECCOMP_RET_LOG
79-
#define SECCOMP_RET_LOG 0x7ffc0000U /* allow after logging */
82+
#define SECCOMP_RET_LOG 0x7ffc0000U /* allow after logging */
8083
#endif
8184

8285
#ifndef SECCOMP_RET_ACTION
@@ -2696,7 +2699,7 @@ TEST_SIGNAL(filter_flag_log, SIGSYS)
26962699

26972700
TEST(get_action_avail)
26982701
{
2699-
__u32 actions[] = { SECCOMP_RET_KILL, SECCOMP_RET_TRAP,
2702+
__u32 actions[] = { SECCOMP_RET_KILL_THREAD, SECCOMP_RET_TRAP,
27002703
SECCOMP_RET_ERRNO, SECCOMP_RET_TRACE,
27012704
SECCOMP_RET_LOG, SECCOMP_RET_ALLOW };
27022705
__u32 unknown_action = 0x10000000U;

0 commit comments

Comments
 (0)