lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 18 Jun 2024 23:12:56 -0500
From: "Eric W. Biederman" <ebiederm@...ssion.com>
To: Oleg Nesterov <oleg@...hat.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,  Tejun Heo <tj@...nel.org>,
  linux-kernel@...r.kernel.org
Subject: [PATCH 16/17] signal: Record the exit_code when an exit is scheduled


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@...ssion.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ