Skip to content

Commit f8ea989

Browse files
committed
exec_ptrace: kill process if architecture does not match
Previously, we did not try to trap execve() in processes where the architecture did not match the native or one of the compat architecture. Now the filter will kill the process instead. This is safer, though perhaps less convenient for the user.
1 parent 839be2a commit f8ea989

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/exec_ptrace.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@
6565
# define COMPAT_FLAG 0x00
6666
# endif
6767

68+
/* SECCOMP_RET_KILL_PROCESS was added in Linux 4.14. */
69+
# ifndef SECCOMP_RET_KILL_PROCESS
70+
# define SECCOMP_RET_KILL_PROCESS SECCOMP_RET_KILL
71+
# endif
72+
6873
static int seccomp_trap_supported = -1;
69-
#ifdef HAVE_PROCESS_VM_READV
74+
# ifdef HAVE_PROCESS_VM_READV
7075
static size_t page_size;
71-
#endif
76+
# endif
7277
static size_t arg_max;
7378

7479
/* Register getters and setters. */
@@ -1186,8 +1191,9 @@ set_exec_filter(void)
11861191
/* Trace execve(2)/execveat(2) syscalls (w/ compat flag) */
11871192
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_TRACE | COMPAT_FLAG),
11881193
# endif /* SECCOMP_AUDIT_ARCH_COMPAT */
1189-
/* Jump to the end unless the architecture matches. */
1190-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SECCOMP_AUDIT_ARCH, 0, 6),
1194+
/* Kill the process unless the (native) architecture matches. */
1195+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SECCOMP_AUDIT_ARCH, 1, 0),
1196+
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)
11911197
/* Load syscall number into the accumulator. */
11921198
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
11931199
/* Jump to trace for execve(2)/execveat(2), else allow. */

0 commit comments

Comments
 (0)