iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.58k stars 3.88k forks source link

update killsnoop to use tracepoints #3592

Open brendangregg opened 3 years ago

brendangregg commented 3 years ago

This is a request for help.

I wrote killsnoop back in 2015 before tracepoint support, and so I kprobe'd sys_kill(). It still does some derivation of that. But now there's a report it no longer works on Linux 5.11: https://github.com/iovisor/bcc/pull/3572#issuecomment-900357032 CC @chenhengqi

Can someone please update killsnoop (both Python and libbpf-tools) to use tracepoints instead of kprobes (if it works as expected). All of these:

  syscalls:sys_enter_kill                            [Tracepoint event]
  syscalls:sys_enter_tgkill                          [Tracepoint event]
  syscalls:sys_enter_tkill                           [Tracepoint event]
  syscalls:sys_exit_kill                             [Tracepoint event]
  syscalls:sys_exit_tgkill                           [Tracepoint event]
  syscalls:sys_exit_tkill                            [Tracepoint event]
chenhengqi commented 3 years ago

I made a mistake. I think the behavior of killsnoop.py is correct.

The manpage of kill(2) has the following description:

If sig is 0, then no signal is sent, but existence and permission checks are still  performed;  this  can  be
used to check for the existence of a process ID or process group ID that the caller is permitted to signal.

And using strace also confirmed this:

kill(1240, 0)                           = -1 EPERM (Operation not permitted)
kill(2733, 0)                           = -1 EPERM (Operation not permitted)
kill(1396, 0)                           = 0
kill(11199, 0)                          = -1 EPERM (Operation not permitted)
kill(685, 0)                            = -1 EPERM (Operation not permitted)
kill(757, 0)                            = 0
kill(1449, 0)                           = -1 EPERM (Operation not permitted)
kill(839, 0)                            = 0
kill(686, 0)                            = -1 EPERM (Operation not permitted)
kill(715, 0)                            = -1 EPERM (Operation not permitted)
kill(721, 0)                            = 0
kill(1148, 0)                           = -1 EPERM (Operation not permitted)
kill(1168, 0)                           = -1 EPERM (Operation not permitted)
kill(754, 0)                            = 0
kill(758, 0)                            = 0
kill(1173, 0)                           = -1 EPERM (Operation not permitted)
kill(8680, 0)                           = -1 EPERM (Operation not permitted)
kill(11327, 0)                          = -1 EPERM (Operation not permitted)
kill(1162, 0)                           = -1 EPERM (Operation not permitted)
kill(38592, 0)                          = -1 EPERM (Operation not permitted)
brendangregg commented 3 years ago

Yeah, the 0 signal (which has no name) is valid and used by a lot of software, and should be shown by killsnoop/sigsnoop.

irenge commented 2 years ago

is the issue closed ? im looking for issue to work on

chenhengqi commented 2 years ago

@irenge Just assign it to you.

irenge commented 2 years ago

Thanks, I will work on it

matthew-olson-intel commented 1 year ago

As far as a libbpf implementation of killsnoop with tracepoints, I've noticed that sigsnoop (which uses tracepoints) implements that functionality with -k, so that's covered.

brendangregg commented 1 year ago

Thanks, so: