From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Tejun Heo <tj@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH 16/17] signal: Record the exit_code when an exit is scheduled
Date: Tue, 18 Jun 2024 23:12:56 -0500 [thread overview]
Message-ID: <87y171efjr.fsf_-_@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500")
With ptrace_stop no longer using task->exit_code it is safe
to set task->exit_code when an exit is scheduled.
Use the bit JOBCTL_WILL_EXIT to detect when a exit is first scheduled
and only set exit_code the first time. Only use the code provided
to do_exit if the task has not yet been schedled to exit.
In get_signal and do_grup_exit when JOBCTL_WILL_EXIT is set read the
recored exit_code from current->exit_code, instead of assuming
exit_code will always be 0.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/exec.c | 2 +-
include/linux/sched/signal.h | 2 +-
kernel/exit.c | 9 +++++----
kernel/signal.c | 7 ++++---
4 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index 57d617917b1c..99ee1a850c37 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1097,7 +1097,7 @@ static int de_thread(struct task_struct *tsk)
if (t == tsk)
continue;
sig->notify_count++;
- schedule_task_exit_locked(t);
+ schedule_task_exit_locked(t, 0);
}
while (sig->notify_count) {
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index 54b2b924aaea..bc702fd94a1f 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -461,7 +461,7 @@ static inline void ptrace_signal_wake_up(struct task_struct *t, bool resume)
signal_wake_up_state(t, state);
}
-void schedule_task_exit_locked(struct task_struct *task);
+void schedule_task_exit_locked(struct task_struct *task, int exit_code);
void schedule_group_exit_locked(struct signal_struct *signal, int exit_code);
void task_join_group_stop(struct task_struct *task);
diff --git a/kernel/exit.c b/kernel/exit.c
index dc944e3c1493..2b4e57ff02a1 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -795,13 +795,14 @@ static void check_stack_usage(void)
static inline void check_stack_usage(void) {}
#endif
-static void synchronize_group_exit(struct task_struct *tsk, long code)
+static int synchronize_group_exit(struct task_struct *tsk, long code)
{
struct sighand_struct *sighand = tsk->sighand;
struct signal_struct *signal = tsk->signal;
spin_lock_irq(&sighand->siglock);
- schedule_task_exit_locked(tsk);
+ schedule_task_exit_locked(tsk, code);
+ code = tsk->exit_code;
signal->quick_threads--;
if ((signal->quick_threads == 0) &&
!(signal->flags & SIGNAL_GROUP_EXIT)) {
@@ -810,6 +811,7 @@ static void synchronize_group_exit(struct task_struct *tsk, long code)
signal->group_stop_count = 0;
}
spin_unlock_irq(&sighand->siglock);
+ return code;
}
void __noreturn do_exit(long code)
@@ -819,7 +821,7 @@ void __noreturn do_exit(long code)
WARN_ON(irqs_disabled());
- synchronize_group_exit(tsk, code);
+ code = synchronize_group_exit(tsk, code);
WARN_ON(tsk->plug);
@@ -856,7 +858,6 @@ void __noreturn do_exit(long code)
tty_audit_exit();
audit_free(tsk);
- tsk->exit_code = code;
taskstats_exit(tsk, group_dead);
exit_mm();
diff --git a/kernel/signal.c b/kernel/signal.c
index dc9ab998fa15..c8b896bc84bb 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1013,7 +1013,7 @@ void schedule_group_exit_locked(struct signal_struct *signal, int exit_code)
signal->group_exit_code = exit_code;
signal->group_stop_count = 0;
__for_each_thread(signal, t)
- schedule_task_exit_locked(t);
+ schedule_task_exit_locked(t, exit_code);
}
static void complete_signal(int sig, struct task_struct *p, enum pid_type type)
@@ -1373,11 +1373,12 @@ int force_sig_info(struct kernel_siginfo *info)
return force_sig_info_to_task(info, current, HANDLER_CURRENT);
}
-void schedule_task_exit_locked(struct task_struct *task)
+void schedule_task_exit_locked(struct task_struct *task, int exit_code)
{
if (!(task->jobctl & JOBCTL_WILL_EXIT)) {
task_clear_jobctl_pending(task, JOBCTL_PENDING_MASK);
task->jobctl |= JOBCTL_WILL_EXIT;
+ task->exit_code = exit_code;
signal_wake_up(task, true);
}
}
@@ -2749,7 +2750,7 @@ bool get_signal(struct ksignal *ksig)
if (signal->flags & SIGNAL_GROUP_EXIT)
exit_code = signal->group_exit_code;
else
- exit_code = 0;
+ exit_code = current->exit_code;
goto fatal;
}
--
2.41.0
next prev parent reply other threads:[~2024-06-19 4:13 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-09 14:23 [PATCH 0/1] exit: kill signal_struct->quick_threads Oleg Nesterov
2024-06-09 14:24 ` [PATCH 1/1] " Oleg Nesterov
2024-06-09 18:28 ` [PATCH 0/1] " Oleg Nesterov
2024-06-10 10:50 ` Q: css_task_iter_advance() && dying_tasks Oleg Nesterov
2024-06-10 11:08 ` Oleg Nesterov
2024-06-10 20:02 ` Tejun Heo
2024-06-10 20:00 ` Tejun Heo
2024-06-10 12:15 ` [PATCH 0/1] exit: kill signal_struct->quick_threads Eric W. Biederman
2024-06-10 15:29 ` Oleg Nesterov
2024-06-10 15:42 ` Oleg Nesterov
2024-06-10 16:18 ` Oleg Nesterov
2024-06-13 15:45 ` Oleg Nesterov
2024-06-15 14:53 ` Eric W. Biederman
2024-06-17 18:37 ` Oleg Nesterov
2024-06-19 3:48 ` Eric W. Biederman
2024-06-19 4:04 ` [PATCH 0/17] exit: complete synchronize_group_exit Eric W. Biederman
2024-06-19 4:05 ` [PATCH 01/17] signal: Make SIGKILL during coredumps an explicit special case Eric W. Biederman
2024-06-19 15:50 ` Oleg Nesterov
2024-06-19 18:09 ` Eric W. Biederman
2024-06-19 19:11 ` Oleg Nesterov
2024-06-21 5:46 ` Eric W. Biederman
2024-06-21 10:40 ` Oleg Nesterov
2024-06-21 16:30 ` Eric W. Biederman
2024-06-19 4:05 ` [PATCH 02/17] signal: Compute the process exit_code in get_signal Eric W. Biederman
2024-06-25 12:34 ` Oleg Nesterov
2024-06-19 4:06 ` [PATCH 03/17] coredump: Consolidate the work to allow SIGKILL during coredumps Eric W. Biederman
2024-06-25 12:34 ` Oleg Nesterov
2024-06-19 4:06 ` [PATCH 04/17] signal: In get_signal call do_exit when it is unnecessary to shoot down threads Eric W. Biederman
2024-06-25 12:35 ` Oleg Nesterov
2024-06-19 4:07 ` [PATCH 05/17] signal: Bring down all threads when handling a non-coredump fatal signal Eric W. Biederman
2024-06-25 12:56 ` Oleg Nesterov
2024-06-19 4:07 ` [PATCH 06/17] signal: Add JOBCTL_WILL_EXIT to mark exiting tasks Eric W. Biederman
2024-06-19 4:08 ` [PATCH 07/17] signal: Always set JOBCTL_WILL_EXIT for " Eric W. Biederman
2024-06-30 14:00 ` kernel test robot
2024-06-19 4:08 ` [PATCH 08/17] signal: Don't target tasks that are exiting Eric W. Biederman
2024-06-19 4:09 ` [PATCH 09/17] signal: Test for process exit or de_thread using task_exit_pending Eric W. Biederman
2024-06-19 4:09 ` [PATCH 10/17] signal: Only set JOBCTL_WILL_EXIT if it is not already set Eric W. Biederman
2024-06-19 4:10 ` [PATCH 11/17] signal: Make individual tasks exiting a first class concept Eric W. Biederman
2024-06-19 4:10 ` [PATCH 12/17] signal: Remove zap_other_threads Eric W. Biederman
2024-06-19 4:11 ` [PATCH 13/17] signal: Stop skipping current in do_group_exit & get_signal Eric W. Biederman
2024-06-28 5:43 ` kernel test robot
2024-06-19 4:11 ` [PATCH 14/17] signal: Factor out schedule_group_exit_locked Eric W. Biederman
2024-06-19 4:12 ` [PATCH 15/17] ptrace: Separate task->ptrace_code out from task->exit_code Eric W. Biederman
2024-06-19 4:12 ` Eric W. Biederman [this message]
2024-06-19 4:13 ` [PATCH 17/17] signal: Set SIGNAL_GROUP_EXIT when all tasks have decided to exit Eric W. Biederman
2024-06-19 20:18 ` [PATCH 0/1] exit: kill signal_struct->quick_threads Oleg Nesterov
-- strict thread matches above, loose matches on Subject: below --
2022-01-03 21:30 [PATCH 00/17] exit: Making task exiting a first class concept Eric W. Biederman
2022-01-03 21:33 ` [PATCH 16/17] signal: Record the exit_code when an exit is scheduled Eric W. Biederman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y171efjr.fsf_-_@email.froward.int.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox