Skip to content

Commit c044a95

Browse files
oleg-nesterovbrauner
authored andcommitted
signal: fill in si_code in prepare_kill_siginfo()
So that do_tkill() can use this helper too. This also simplifies the next patch. TODO: perhaps we can kill prepare_kill_siginfo() and change the callers to use SEND_SIG_NOINFO, but this needs some changes in __send_signal_locked() and TP_STORE_SIGINFO(). Reviewed-by: Tycho Andersen <[email protected]> Signed-off-by: Oleg Nesterov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent f0ece18 commit c044a95

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

kernel/signal.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,12 +3793,13 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time32, compat_sigset_t __user *, uthese,
37933793
#endif
37943794
#endif
37953795

3796-
static inline void prepare_kill_siginfo(int sig, struct kernel_siginfo *info)
3796+
static void prepare_kill_siginfo(int sig, struct kernel_siginfo *info,
3797+
enum pid_type type)
37973798
{
37983799
clear_siginfo(info);
37993800
info->si_signo = sig;
38003801
info->si_errno = 0;
3801-
info->si_code = SI_USER;
3802+
info->si_code = (type == PIDTYPE_PID) ? SI_TKILL : SI_USER;
38023803
info->si_pid = task_tgid_vnr(current);
38033804
info->si_uid = from_kuid_munged(current_user_ns(), current_uid());
38043805
}
@@ -3812,7 +3813,7 @@ SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
38123813
{
38133814
struct kernel_siginfo info;
38143815

3815-
prepare_kill_siginfo(sig, &info);
3816+
prepare_kill_siginfo(sig, &info, PIDTYPE_TGID);
38163817

38173818
return kill_something_info(sig, &info, pid);
38183819
}
@@ -3925,7 +3926,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
39253926
(kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL))
39263927
goto err;
39273928
} else {
3928-
prepare_kill_siginfo(sig, &kinfo);
3929+
prepare_kill_siginfo(sig, &kinfo, PIDTYPE_TGID);
39293930
}
39303931

39313932
/* TODO: respect PIDFD_THREAD */
@@ -3970,12 +3971,7 @@ static int do_tkill(pid_t tgid, pid_t pid, int sig)
39703971
{
39713972
struct kernel_siginfo info;
39723973

3973-
clear_siginfo(&info);
3974-
info.si_signo = sig;
3975-
info.si_errno = 0;
3976-
info.si_code = SI_TKILL;
3977-
info.si_pid = task_tgid_vnr(current);
3978-
info.si_uid = from_kuid_munged(current_user_ns(), current_uid());
3974+
prepare_kill_siginfo(sig, &info, PIDTYPE_PID);
39793975

39803976
return do_send_specific(tgid, pid, sig, &info);
39813977
}

0 commit comments

Comments
 (0)