Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <keescook@chromium.org>

+7 -2
+7 -2
samples/seccomp/dropper.c
··· 25 25 #include <sys/prctl.h> 26 26 #include <unistd.h> 27 27 28 - static int install_filter(int nr, int arch, int error) 28 + static int install_filter(int arch, int nr, int error) 29 29 { 30 30 struct sock_filter filter[] = { 31 31 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, ··· 42 42 .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])), 43 43 .filter = filter, 44 44 }; 45 + if (error == -1) { 46 + struct sock_filter kill = BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL); 47 + filter[4] = kill; 48 + } 45 49 if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { 46 50 perror("prctl(NO_NEW_PRIVS)"); 47 51 return 1; ··· 61 57 { 62 58 if (argc < 5) { 63 59 fprintf(stderr, "Usage:\n" 64 - "dropper <syscall_nr> <arch> <errno> <prog> [<args>]\n" 60 + "dropper <arch> <syscall_nr> <errno> <prog> [<args>]\n" 65 61 "Hint: AUDIT_ARCH_I386: 0x%X\n" 66 62 " AUDIT_ARCH_X86_64: 0x%X\n" 63 + " errno == -1 means SECCOMP_RET_KILL\n" 67 64 "\n", AUDIT_ARCH_I386, AUDIT_ARCH_X86_64); 68 65 return 1; 69 66 }