Skip to content

Commit 84fe4cc

Browse files
committed
signal: Don't send signals to tasks that don't exist
Recently syzbot reported crashes in send_sigio_to_task and send_sigurg_to_task in linux-next. Despite finding a reproducer syzbot apparently did not bisected this or otherwise track down the offending commit in linux-next. I happened to see this report and examined the code because I had recently changed these functions as part of making PIDTYPE_TGID a real pid type so that fork would does not need to restart when receiving a signal. By examination I see that I spotted a bug in the code that could explain the reported crashes. When I took Oleg's suggestion and optimized send_sigurg and send_sigio to only send to a single task when type is PIDTYPE_PID or PIDTYPE_TGID I failed to handle pids that no longer point to tasks. The macro do_each_pid_task simply iterates for zero iterations. With pid_task an explicit NULL test is needed. Update the code to include the missing NULL test. Fixes: 0191913 ("signal: Use PIDTYPE_TGID to clearly store where file signals will be sent") Reported-by: [email protected] Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent c3ad2c3 commit 84fe4cc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/fcntl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ void send_sigio(struct fown_struct *fown, int fd, int band)
791791
if (type <= PIDTYPE_TGID) {
792792
rcu_read_lock();
793793
p = pid_task(pid, PIDTYPE_PID);
794-
send_sigio_to_task(p, fown, fd, band, type);
794+
if (p)
795+
send_sigio_to_task(p, fown, fd, band, type);
795796
rcu_read_unlock();
796797
} else {
797798
read_lock(&tasklist_lock);
@@ -830,7 +831,8 @@ int send_sigurg(struct fown_struct *fown)
830831
if (type <= PIDTYPE_TGID) {
831832
rcu_read_lock();
832833
p = pid_task(pid, PIDTYPE_PID);
833-
send_sigurg_to_task(p, fown, type);
834+
if (p)
835+
send_sigurg_to_task(p, fown, type);
834836
rcu_read_unlock();
835837
} else {
836838
read_lock(&tasklist_lock);

0 commit comments

Comments
 (0)