Skip to content

Commit

Permalink
fix(modern_bpf): fix NULL dereference in signal_deliver filler
Browse files Browse the repository at this point in the history
The `signal_deliver` filler can be called with info=NULL
(`SEND_SIG_NOINFO`). Despite all I've been led to believe with eBPF,
this does cause an actual NULL dereference in the kernel,
promptly killing the machine (as the offending thread dies while
holding the spinlock in get_signal).

So let's check the pointer before we dereference it.

Signed-off-by: Grzegorz Nosek <[email protected]>
Co-Authored-By: Andrea Terzolo <[email protected]>
  • Loading branch information
2 people authored and poiana committed Jul 28, 2023
1 parent afd8903 commit 7390661
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions driver/modern_bpf/programs/attached/events/signal_deliver.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,46 @@ int BPF_PROG(signal_deliver,
/* Try to find the source pid */
pid_t spid = 0;

switch(sig)
if(info != NULL)
{
case SIGKILL:
spid = info->_sifields._kill._pid;
break;

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

case SIGTERM:
case SIGHUP:
case SIGINT:
case SIGTSTP:
case SIGQUIT:
{
int si_code = 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;
}
break;
}
break;
}

case SIGCHLD:
spid = info->_sifields._sigchld._pid;
break;
case SIGCHLD:
spid = info->_sifields._sigchld._pid;
break;

default:
spid = 0;
break;
}
default:
spid = 0;
break;
}

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

/* Parameter 1: spid (type: PT_PID) */
Expand Down

0 comments on commit 7390661

Please sign in to comment.