Skip to content

Commit 85eca32

Browse files
committed
api: doc: tests: Add SCMP_ACT_TRAPX()
Add a new action macro, SCMP_ACT_TRAPX(), which accepts user-specified data in the lower 16-bits. When a userspace signal handler has been specified, the Linux kernel populates the si_errno field in the siginfo structure with these lower 16-bits from the trap action. To maintain backward compatibility, redefine SCMP_ACT_TRAP to map to SCMP_ACT_TRAPX(0). This will guarantee that filters that utilize SCMP_ACT_TRAP will behave identically. Signed-off-by: Tom Hromatka <[email protected]>
1 parent 5491c4b commit 85eca32

File tree

11 files changed

+241
-61
lines changed

11 files changed

+241
-61
lines changed

doc/man/man3/seccomp_init.3

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,24 @@ The entire process will be terminated by the kernel with SIGSYS when it calls a
6767
syscall that does not match any of the configured seccomp filter rules.
6868
.TP
6969
.B SCMP_ACT_TRAP
70+
See
71+
.B SCMP_ACT_TRAPX
72+
.TP
73+
.B SCMP_ACT_TRAPX(unit16_t reason)
7074
The thread will be sent a SIGSYS signal when it calls a syscall that does not
7175
match any of the configured seccomp filter rules. It may catch this and change
7276
its behavior accordingly. When using SA_SIGINFO with
7377
.BR sigaction (2),
7478
si_code will be set to SYS_SECCOMP, si_syscall will be set to the syscall that
7579
failed the rules, and si_arch will be set to the AUDIT_ARCH for the active ABI.
80+
If
81+
.B SCMP_ACT_TRAPX
82+
is utilized,
83+
the si_errno field in
84+
.BR sigaction (2),
85+
will be set to
86+
.I reason
87+
.
7688
.TP
7789
.B SCMP_ACT_ERRNO(uint16_t errno)
7890
The thread will receive a return value of

doc/man/man3/seccomp_rule_add.3

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ the filter rule.
184184
The thread will throw a SIGSYS signal when it calls a syscall that matches the
185185
filter rule.
186186
.TP
187+
.B SCMP_ACT_TRAPX(uint16_t reason)
188+
The thread will throw a SIGSYS signal when it calls a syscall that matches the
189+
filter rule. When using SA_SIGINFO with
190+
.BR sigaction (2),
191+
.I reason
192+
will be populated in the si_errno field.
193+
.TP
187194
.B SCMP_ACT_ERRNO(uint16_t errno)
188195
The thread will receive a return value of
189196
.I errno

include/seccomp.h.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,12 @@ struct scmp_arg_cmp {
365365
#define SCMP_ACT_KILL SCMP_ACT_KILL_THREAD
366366
/**
367367
* Throw a SIGSYS signal
368+
*
369+
* The Linux kernel supports a 16-bit parameter for the TRAP action, but
370+
* libseccomp v2.6.x and older did not support or utilize this parameter.
368371
*/
369-
#define SCMP_ACT_TRAP 0x00030000U
372+
#define SCMP_ACT_TRAP SCMP_ACT_TRAPX(0)
373+
#define SCMP_ACT_TRAPX(x) (0x00030000U | ((x) & 0x0000ffffU))
370374
/**
371375
* Notifies userspace
372376
*/

src/gen_pfc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ static void _pfc_action(FILE *fds, uint32_t action)
135135
case SCMP_ACT_KILL_THREAD:
136136
fprintf(fds, "action KILL;\n");
137137
break;
138-
case SCMP_ACT_TRAP:
139-
fprintf(fds, "action TRAP;\n");
138+
case SCMP_ACT_TRAPX(0):
139+
fprintf(fds, "action TRAP(%u);\n", (action & 0x0000ffff));
140140
break;
141141
case SCMP_ACT_ERRNO(0):
142142
fprintf(fds, "action ERRNO(%u);\n", (action & 0x0000ffff));

src/system.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ int sys_chk_seccomp_action(uint32_t action)
196196
return state.sup_kill_process;
197197
} else if (action == SCMP_ACT_KILL_THREAD) {
198198
return 1;
199-
} else if (action == SCMP_ACT_TRAP) {
199+
} else if (action == SCMP_ACT_TRAPX(action & 0x0000ffff)) {
200200
return 1;
201201
} else if ((action == SCMP_ACT_ERRNO(action & 0x0000ffff)) &&
202202
((action & 0x0000ffff) < MAX_ERRNO)) {

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ util.pyc
7070
60-sim-precompute
7171
61-sim-transactions
7272
62-sim-arch_transactions
73+
63-live-trapx

0 commit comments

Comments
 (0)