Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/python/test_tools_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_gethostlatency(self):
def test_hardirqs(self):
self.run_with_duration("hardirqs.py 1 1")

@skipUnless(kernel_version_ge(4,4), "requires kernel >= 4.4")
@skipUnless(kernel_version_ge(4,7), "requires kernel >= 4.7")
def test_killsnoop(self):
# Because killsnoop intercepts signals, if we send it a SIGINT we we
# we likely catch it while it is handling the data packet from the
Expand Down
43 changes: 36 additions & 7 deletions tools/killsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -85,9 +86,24 @@
}

return 0;
};
}

TRACEPOINT_PROBE(syscalls, sys_enter_kill)

Copy link
Copy Markdown
Collaborator

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,

--- a/tests/python/test_tools_smoke.py
+++ b/tests/python/test_tools_smoke.py
@@
-    @skipUnless(kernel_version_ge(4,4), "requires kernel >= 4.4")
+    @skipUnless(kernel_version_ge(4,7), "requires kernel >= 4.7")

{
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;
Expand All @@ -104,14 +120,30 @@
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);
}

"""

if args.tpid:
Expand Down Expand Up @@ -141,9 +173,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
Expand Down
Loading