Skip to content

Commit eed09ad

Browse files
committed
samples/seccomp: Adjust sample to also provide kill option
As a quick way to test SECCOMP_RET_KILL, have a negative errno mean to kill the process. While we're in here, also swap the arch and syscall arguments so they're ordered more like how seccomp filters order them. Signed-off-by: Kees Cook <[email protected]>
1 parent 495ac30 commit eed09ad

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

samples/seccomp/dropper.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <sys/prctl.h>
2626
#include <unistd.h>
2727

28-
static int install_filter(int nr, int arch, int error)
28+
static int install_filter(int arch, int nr, int error)
2929
{
3030
struct sock_filter filter[] = {
3131
BPF_STMT(BPF_LD+BPF_W+BPF_ABS,
@@ -42,6 +42,10 @@ static int install_filter(int nr, int arch, int error)
4242
.len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
4343
.filter = filter,
4444
};
45+
if (error == -1) {
46+
struct sock_filter kill = BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL);
47+
filter[4] = kill;
48+
}
4549
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
4650
perror("prctl(NO_NEW_PRIVS)");
4751
return 1;
@@ -57,9 +61,10 @@ int main(int argc, char **argv)
5761
{
5862
if (argc < 5) {
5963
fprintf(stderr, "Usage:\n"
60-
"dropper <syscall_nr> <arch> <errno> <prog> [<args>]\n"
64+
"dropper <arch> <syscall_nr> <errno> <prog> [<args>]\n"
6165
"Hint: AUDIT_ARCH_I386: 0x%X\n"
6266
" AUDIT_ARCH_X86_64: 0x%X\n"
67+
" errno == -1 means SECCOMP_RET_KILL\n"
6368
"\n", AUDIT_ARCH_I386, AUDIT_ARCH_X86_64);
6469
return 1;
6570
}

0 commit comments

Comments
 (0)