security: fix BPF C code injection in 43 Python tools + unsafe directory perms#5465
Open
SleuthCo wants to merge 4 commits intoiovisor:masterfrom
Open
security: fix BPF C code injection in 43 Python tools + unsafe directory perms#5465SleuthCo wants to merge 4 commits intoiovisor:masterfrom
SleuthCo wants to merge 4 commits intoiovisor:masterfrom
Conversation
Add positive_int, positive_nonzero_int, and positive_int_list argparse type validators for secure input validation of CLI arguments that get interpolated into BPF C source code. These prevent code injection via malicious non-numeric argument values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CLI arguments (PIDs, TIDs, UIDs, signals) were passed as raw strings
and interpolated directly into BPF C source via bpf_text.replace().
An attacker could inject arbitrary C code into kernel BPF programs.
Fix: add type=int (or type=positive_int_list for killsnoop --signal)
to all vulnerable argparse arguments. This ensures argparse rejects
non-numeric input before it reaches string interpolation.
Special cases:
- execsnoop.py: --max-args default "20" -> 20, replacement uses str()
- killsnoop.py: --signal uses positive_int_list validator, removes
manual .split(',') parsing
- ttysnoop.py: --datasize/--datacount defaults "256"/"16" -> 256/16,
replacements use str()
Affects 29 tools in tools/ and 14 tools in tools/old/.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Change mkdir() mode from 0777 to 0700 for BCC_PROG_TAG_DIR and per-program subdirectories to prevent local users from tampering with cached BPF program sources - Add O_NOFOLLOW to all open() calls to prevent symlink attacks - Check write() return values to detect I/O errors This prevents local privilege escalation via symlink attacks on the world-writable /var/tmp/bcc directory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add comprehensive test coverage for the security fixes: - tests/python/test_utils.py: Unit tests for positive_int, positive_nonzero_int, and positive_int_list validators - tests/python/test_tool_args_validation.py: Integration tests that verify all 43 fixed tools reject malicious non-integer input via subprocess invocation (~60 test methods). Does not require root. - SECURITY.md: Security reporting policy and advisories for BCC-2026-001 (BPF code injection) and BCC-2026-002 (world-writable directory permissions) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Friendly ping — this PR fixes a BPF C code injection vulnerability across 43 Python tools where unsanitized user input (PIDs, device names, function names, etc.) is interpolated directly into BPF C source before compilation. The fix uses a consistent allowlist-based validation pattern. Happy to address any feedback or split the PR if that's easier to review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bpf_text.replace(). A local attacker can inject arbitrary C code into kernel-loaded BPF programs. Fixed by addingtype=int(or a custompositive_int_listvalidator) to all vulnerableargparsearguments.bpf_module.cccreates/var/tmp/bcc/with mode0777, enabling symlink attacks for arbitrary file overwrites as root. Fixed by using mode0700, addingO_NOFOLLOW, and checkingwrite()return values.positive_int,positive_nonzero_int,positive_int_list) tobcc.utilsSECURITY.mdwith reporting policy and advisoriesCommits (4)
security: add shared input validators to bcc.utils—positive_int,positive_nonzero_int,positive_int_listargparse type validatorssecurity: add type=int to 43 Python tools to prevent BPF code injection— fixes 29 tools intools/and 14 intools/old/security: fix world-writable directory and unsafe file operations—bpf_module.cchardening (0700, O_NOFOLLOW, write checks)security: add tests and security advisory for BPF injection fixes— test_utils.py, test_tool_args_validation.py (~60 test methods), SECURITY.mdAffected tools
tcptop,tcpconnlat,tcplife,tcpaccept,tcpconnect,capable,cpudist,statsnoop,filelife,filegone,compactsnoop,vfsstat,ext4dist,shmsnoop,sofdsnoop,numasched,klockstat,opensnoop,drsnoop,bindsnoop,nfsslower,xfsslower,zfsslower,ext4slower,btrfsslower,f2fsslower,execsnoop,killsnoop,ttysnoop, and 14 tools intools/old/.Test plan
python -m pytest tests/python/test_utils.py— unit tests for validatorspython -m pytest tests/python/test_tool_args_validation.py— integration tests that all 43 tools reject injection payloads (does not require root)sudo tcptop -p "1; } evil(); if(0"is rejected at argparse witherror: argument -p: invalid int value/var/tmp/bcc/directories are created with0700not0777🤖 Generated with Claude Code