Skip to content

Commit

Permalink
Omit superfluous BPF unsigned short cast
Browse files Browse the repository at this point in the history
The BPF macros already contain the cast, we do not need to duplicate it.
  • Loading branch information
vimpostor committed Dec 22, 2024
1 parent c4802a2 commit ff1465e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/bin/seccomp/seccomp_trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ int user_trap_syscalls(const int *nrs, size_t length, unsigned int flags) {
filter[2] = (struct sock_filter) BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr));

// for the x32 ABI, all system call numbers have bit 30 set
filter[3] = (struct sock_filter) BPF_JUMP((unsigned short) BPF_JMP+BPF_JGE+BPF_K, X32_SYSCALL_BIT, 0, 1);
filter[3] = (struct sock_filter) BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, X32_SYSCALL_BIT, 0, 1);

// terminate the process if one of the earlier checks jumped here
filter[4] = (struct sock_filter) BPF_STMT((unsigned short) BPF_RET+BPF_K, SECCOMP_RET_KILL_PROCESS);
filter[4] = (struct sock_filter) BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL_PROCESS);

// now with the syscall nr still loaded, dynamically add checks for all syscall nrs we want to intercept
// Warning: If there are more nrs than MAX_FILTER_SIZE - 3, we may omit some system calls
Expand All @@ -134,10 +134,10 @@ int user_trap_syscalls(const int *nrs, size_t length, unsigned int flags) {
}

// didn't find a matching syscall, so return allow
filter[bpf_length - 2] = (struct sock_filter) BPF_STMT((unsigned short) BPF_RET+BPF_K, SECCOMP_RET_ALLOW);
filter[bpf_length - 2] = (struct sock_filter) BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW);

// this is the jump target. If we found a matching syscall, we return SECCOMP_RET_USER_NOTIF
filter[bpf_length - 1] = (struct sock_filter) BPF_STMT((unsigned short) BPF_RET+BPF_K, SECCOMP_RET_USER_NOTIF);
filter[bpf_length - 1] = (struct sock_filter) BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_USER_NOTIF);

struct sock_fprog prog = {
.len = (unsigned short) bpf_length,
Expand Down

0 comments on commit ff1465e

Please sign in to comment.