Skip to content
Merged
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
15 changes: 10 additions & 5 deletions driver/modern_bpf/programs/attached/events/signal_deliver.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,34 @@ int BPF_PROG(signal_deliver, int sig, struct kernel_siginfo *info, struct k_siga
/* Try to find the source pid */
pid_t spid = 0;

/* Signal tracepoints can receive the `SEND_SIG_NOINFO` (0) and
* `SEND_SIG_PRIV` (1) sentinels instead of a real pointer, so newer kernels
* expose `info` as a scalar and the verifier rejects direct accesses.
* `BPF_CORE_READ` works with both the scalar and the BTF pointer.
*/
if(info != NULL) {
switch(sig) {
case SIGKILL:
spid = info->_sifields._kill._pid;
spid = BPF_CORE_READ(info, _sifields._kill._pid);
break;

case SIGTERM:
case SIGHUP:
case SIGINT:
case SIGTSTP:
case SIGQUIT: {
int si_code = info->si_code;
int si_code = BPF_CORE_READ(info, si_code);
if(si_code == SI_USER || si_code == SI_QUEUE || si_code <= 0) {
/* This is equivalent to `info->si_pid` where
* `si_pid` is a macro `_sifields._kill._pid`
*/
spid = info->_sifields._kill._pid;
spid = BPF_CORE_READ(info, _sifields._kill._pid);
}
break;
}

case SIGCHLD:
spid = info->_sifields._sigchld._pid;
spid = BPF_CORE_READ(info, _sifields._sigchld._pid);
break;

default:
Expand All @@ -61,7 +66,7 @@ int BPF_PROG(signal_deliver, int sig, struct kernel_siginfo *info, struct k_siga
}

if(sig >= SIGRTMIN && sig <= SIGRTMAX) {
spid = info->_sifields._rt._pid;
spid = BPF_CORE_READ(info, _sifields._rt._pid);
}
}

Expand Down
Loading