Skip to content

Commit

Permalink
Fix libbpf-tools/sigsnoop segment fault (iovisor#4228)
Browse files Browse the repository at this point in the history
Running without -n:

  [rongtao@RT-NUC libbpf-tools]$ sudo ./sigsnoop
  TIME     PID     COMM             SIG       TPID    RESULT
  ...
  16:32:48 0       swapper/1        34        2658    0

Running with -n, access sig_name[34] cause SEGV, this patch fix it, check that
whether sig_name access is OOB, if yes, print signal number instead:

  [rongtao@RT-NUC libbpf-tools]$ sudo ./sigsnoop -n
  TIME     PID     COMM             SIG       TPID    RESULT
  19:01:38 0       swapper/11       34        2658    0
  19:01:46 50019   id               SIGCHLD   50018   0

Signed-off-by: Rong Tao <[email protected]>
  • Loading branch information
Rtoax committed Sep 9, 2022
1 parent c30c418 commit a92c2bd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libbpf-tools/sigsnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define PERF_BUFFER_PAGES 16
#define PERF_POLL_TIMEOUT_MS 100
#define warn(...) fprintf(stderr, __VA_ARGS__)
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

static volatile sig_atomic_t exiting = 0;

Expand Down Expand Up @@ -165,7 +166,7 @@ static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
if (signal_name)
if (signal_name && e->sig < ARRAY_SIZE(sig_name))
printf("%-8s %-7d %-16s %-9s %-7d %-6d\n",
ts, e->pid, e->comm, sig_name[e->sig], e->tpid, e->ret);
else
Expand Down

0 comments on commit a92c2bd

Please sign in to comment.