Skip to content

Commit 556a888

Browse files
thejhbrauner
authored andcommitted
signal: don't silently convert SI_USER signals to non-current pidfd
The current sys_pidfd_send_signal() silently turns signals with explicit SI_USER context that are sent to non-current tasks into signals with kernel-generated siginfo. This is unlike do_rt_sigqueueinfo(), which returns -EPERM in this case. If a user actually wants to send a signal with kernel-provided siginfo, they can do that with pidfd_send_signal(pidfd, sig, NULL, 0); so allowing this case is unnecessary. Instead of silently replacing the siginfo, just bail out with an error; this is consistent with other interfaces and avoids special-casing behavior based on security checks. Fixes: 3eb39f4 ("signal: add pidfd_send_signal() syscall") Signed-off-by: Jann Horn <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 79a3aaa commit 556a888

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

kernel/signal.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3605,16 +3605,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
36053605
if (unlikely(sig != kinfo.si_signo))
36063606
goto err;
36073607

3608+
/* Only allow sending arbitrary signals to yourself. */
3609+
ret = -EPERM;
36083610
if ((task_pid(current) != pid) &&
3609-
(kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) {
3610-
/* Only allow sending arbitrary signals to yourself. */
3611-
ret = -EPERM;
3612-
if (kinfo.si_code != SI_USER)
3613-
goto err;
3614-
3615-
/* Turn this into a regular kill signal. */
3616-
prepare_kill_siginfo(sig, &kinfo);
3617-
}
3611+
(kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL))
3612+
goto err;
36183613
} else {
36193614
prepare_kill_siginfo(sig, &kinfo);
36203615
}

0 commit comments

Comments
 (0)