[PATCH 01/11] signal: Compute the exit_code in get_signal
From: Eric W. Biederman
Date: Fri Jun 26 2026 - 13:20:31 EST
Update get_signal so it calls do_group_exit with the correct
exit_code.
Make the default exit_code 0, so that the special case for threads
killed by de_thread falls out naturally.
Update do_group_exit to trust the exit_code passed in except when
SIGNAL_GROUP_EXIT is set.
Moving the computation of exit_code into get_signal makes other
cleanups possible.
---
kernel/exit.c | 4 ++--
kernel/signal.c | 12 ++++++++----
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/kernel/exit.c b/kernel/exit.c
index f50d73c272d6..ae143be7c831 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1098,7 +1098,7 @@ do_group_exit(int exit_code)
if (sig->flags & SIGNAL_GROUP_EXIT)
exit_code = sig->group_exit_code;
else if (sig->group_exec_task)
- exit_code = 0;
+ ;
else {
struct sighand_struct *const sighand = current->sighand;
@@ -1107,7 +1107,7 @@ do_group_exit(int exit_code)
/* Another thread got here before we took the lock. */
exit_code = sig->group_exit_code;
else if (sig->group_exec_task)
- exit_code = 0;
+ ;
else {
sig->group_exit_code = exit_code;
sig->flags = SIGNAL_GROUP_EXIT;
diff --git a/kernel/signal.c b/kernel/signal.c
index 9c2b32c4d755..39fbf9c9474a 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2865,10 +2865,13 @@ bool get_signal(struct ksignal *ksig)
for (;;) {
struct k_sigaction *ka;
enum pid_type type;
+ int exit_code = 0;
/* Has this task already been marked for death? */
if ((signal->flags & SIGNAL_GROUP_EXIT) ||
signal->group_exec_task) {
+ if (signal->flags & SIGNAL_GROUP_EXIT)
+ exit_code = signal->group_exit_code;
signr = SIGKILL;
sigdelset(¤t->pending.signal, SIGKILL);
trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
@@ -2998,14 +3001,15 @@ bool get_signal(struct ksignal *ksig)
continue;
}
+ /*
+ * Anything else is fatal, maybe with a core dump.
+ */
+ exit_code = signr;
fatal:
spin_unlock_irq(&sighand->siglock);
if (unlikely(cgroup_task_frozen(current)))
cgroup_leave_frozen(true);
- /*
- * Anything else is fatal, maybe with a core dump.
- */
current->flags |= PF_SIGNALED;
if (sig_kernel_coredump(signr)) {
@@ -3035,7 +3039,7 @@ bool get_signal(struct ksignal *ksig)
/*
* Death signals, no core dump.
*/
- do_group_exit(signr);
+ do_group_exit(exit_code);
/* NOTREACHED */
}
spin_unlock_irq(&sighand->siglock);
--
2.41.0