From: Jann Horn Date: Sat, 30 Mar 2019 02:12:32 +0000 (+0100) Subject: UPSTREAM: signal: don't silently convert SI_USER signals to non-current pidfd X-Git-Tag: MMI-RSA31.Q1-48-36-11~12 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1f0f50600cb7448c7981c145beca165e0cdfc229;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git UPSTREAM: 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: 3eb39f47934f ("signal: add pidfd_send_signal() syscall") Signed-off-by: Jann Horn Signed-off-by: Christian Brauner (cherry picked from commit 556a888a14afe27164191955618990fb3ccc9aad) Mot-CRs-fixed: (CR) Bug: 135608568 Test: test program using syscall(__NR_pidfd_send_signal,..) to send SIGKILL Change-Id: I493af671b82c43bff1425ee24550d2fb9aa6d961 Signed-off-by: Suren Baghdasaryan Reviewed-on: https://gerrit.mot.com/1505848 Tested-by: Jira Key SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Reviewed-by: Wang Wang Reviewed-by: Yonghui Jia Submit-Approved: Jira Key Reviewed-on: https://gerrit.mot.com/1796156 Reviewed-by: Xiangpo Zhao --- diff --git a/kernel/signal.c b/kernel/signal.c index 037c24780dad..23ff00fe1d09 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3157,16 +3157,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, if (unlikely(sig != kinfo.si_signo)) goto err; + /* Only allow sending arbitrary signals to yourself. */ + ret = -EPERM; if ((task_pid(current) != pid) && - (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) { - /* Only allow sending arbitrary signals to yourself. */ - ret = -EPERM; - if (kinfo.si_code != SI_USER) - goto err; - - /* Turn this into a regular kill signal. */ - prepare_kill_siginfo(sig, &kinfo); - } + (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) + goto err; } else { prepare_kill_siginfo(sig, &kinfo); }