-
Notifications
You must be signed in to change notification settings - Fork 4.1k
tools/killsnoop: migrate to tracepoints #5546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ekyooo
merged 3 commits into
iovisor:master
from
codebyangelo:fix-killsnoop-tracepoints
Aug 27, 2026
+37
−8
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,8 @@ | |
| BPF_HASH(infotmp, u32, struct val_t); | ||
| BPF_PERF_OUTPUT(events); | ||
|
|
||
| int syscall__kill(struct pt_regs *ctx, int tpid, int sig) | ||
|
|
||
| static int probe_entry(u32 tpid, int sig) | ||
| { | ||
| u64 pid_tgid = bpf_get_current_pid_tgid(); | ||
| u32 pid = pid_tgid >> 32; | ||
|
|
@@ -85,9 +86,24 @@ | |
| } | ||
|
|
||
| return 0; | ||
| }; | ||
| } | ||
|
|
||
| TRACEPOINT_PROBE(syscalls, sys_enter_kill) | ||
| { | ||
| return probe_entry(args->pid, args->sig); | ||
| } | ||
|
|
||
| TRACEPOINT_PROBE(syscalls, sys_enter_tkill) | ||
| { | ||
| return probe_entry(args->pid, args->sig); | ||
| } | ||
|
|
||
| TRACEPOINT_PROBE(syscalls, sys_enter_tgkill) | ||
| { | ||
| return probe_entry(args->pid, args->sig); | ||
| } | ||
|
|
||
| int do_ret_sys_kill(struct pt_regs *ctx) | ||
| static int probe_exit(void *ctx, int ret) | ||
| { | ||
| struct data_t data = {}; | ||
| struct val_t *valp; | ||
|
|
@@ -104,14 +120,32 @@ | |
| bpf_probe_read_kernel(&data.comm, sizeof(data.comm), valp->comm); | ||
| data.pid = pid; | ||
| data.tpid = valp->tpid; | ||
| data.ret = PT_REGS_RC(ctx); | ||
| data.ret = ret; | ||
| data.sig = valp->sig; | ||
|
|
||
| events.perf_submit(ctx, &data, sizeof(data)); | ||
| infotmp.delete(&tid); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| TRACEPOINT_PROBE(syscalls, sys_exit_kill) | ||
| { | ||
| return probe_exit(args, args->ret); | ||
| } | ||
|
|
||
| TRACEPOINT_PROBE(syscalls, sys_exit_tkill) | ||
| { | ||
| return probe_exit(args, args->ret); | ||
| } | ||
|
|
||
| TRACEPOINT_PROBE(syscalls, sys_exit_tgkill) | ||
| { | ||
| return probe_exit(args, args->ret); | ||
| } | ||
| ; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the extra blank lines and semicolon.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the guidance. Done. |
||
|
|
||
|
|
||
| """ | ||
|
|
||
| if args.tpid: | ||
|
|
@@ -141,9 +175,6 @@ | |
|
|
||
| # initialize BPF | ||
| b = BPF(text=bpf_text) | ||
| kill_fnname = b.get_syscall_fnname("kill") | ||
| b.attach_kprobe(event=kill_fnname, fn_name="syscall__kill") | ||
| b.attach_kretprobe(event=kill_fnname, fn_name="do_ret_sys_kill") | ||
|
|
||
| # detect the length of PID column | ||
| pid_bytes = 6 | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TRACEPOINT_PROBE-based BPF programs require Linux 4.7 or later. Please update the test_killsnoop() kernel gate from 4.4 to 4.7, consistent with the existing tracepoint tests.
for example,