Skip to content

seccomp: return from each filter match instead of a far shared return - #364

Open
congwang-mk wants to merge 1 commit into
mainfrom
bpf-jump-offset-truncation
Open

congwang-mk wants to merge 1 commit into
mainfrom
bpf-jump-offset-truncation

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

Problem

assemble_filter sent every notif and deny match to shared return instructions at the end of the program, and cast the distance to cBPF's u8 jump offset. The first notif entry jumps notif + deny instructions, so once the two lists together pass 255 entries the offset wraps. A syscall meant to be notified or denied then lands on an unrelated instruction and can be allowed.

The default lists stay well under that, but extra_deny_syscalls (including group names) and handler syscalls are caller-controlled and can reach it. The only guard was the 4096-instruction cap, which does not cover the u8 arithmetic.

Fix

Each match is now a JEQ nr,0,1; RET <action> pair, with RET ALLOW as the final fall-through. No jump distance depends on list length.

The program uses two instructions per listed syscall instead of one. The 4096-instruction cap is still enforced, which now allows roughly 2000 listed syscalls.

Tests

  • New actions_hold_past_the_u8_jump_range: 200 notif plus 200 deny syscalls evaluated through the filter interpreter, checking every action.
  • test_default_allow_is_the_fall_through replaces the test that assumed three trailing returns.
  • The oversize test uses 2048 deny entries so it still exceeds the cap.

🤖 Generated with Claude Code

The notif and deny lists jumped to shared return instructions at the end
of the program, with the distance cast to cBPF's u8 jump offset. Once the
two lists together passed 255 entries, which extra_deny_syscalls and
handler syscalls can reach, the offset wrapped and a syscall meant to be
notified or denied landed on an unrelated instruction and could be
allowed. Each match now returns from the instruction after it, so no
jump depends on the list length.

Signed-off-by: Cong Wang <cwang@multikernel.io>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant