[PATCH 02/17] signal: Compute the process exit_code in get_signal

Eric W. Biederman posted 17 patches 1 year, 7 months ago
[PATCH 02/17] signal: Compute the process exit_code in get_signal
Posted by Eric W. Biederman 1 year, 7 months ago

In prepartion for moving the work of sys_exit and sys_group_exit into
get_signal compute exit_code in get_signal, make PF_SIGNALED depend on
the exit_code and pass the exit_code to do_group_exit.

Anytime there is a group exit the exit_code may differ from the signal
number.

To match the historical precedent as best I can make the exit_code 0
during exec. (The exit_code field would not have been set but probably
would have been left at a value of 0).

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 kernel/signal.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index e3662fff919a..392d802dbf61 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2738,6 +2738,7 @@ bool get_signal(struct ksignal *ksig)
 	for (;;) {
 		struct k_sigaction *ka;
 		enum pid_type type;
+		int exit_code;
 
 		/* Has this task already been marked for death? */
 		if ((signal->flags & SIGNAL_GROUP_EXIT) ||
@@ -2751,6 +2752,10 @@ bool get_signal(struct ksignal *ksig)
 			 * implies do_group_exit() or return to PF_USER_WORKER,
 			 * no need to initialize ksig->info/etc.
 			 */
+			if (signal->flags & SIGNAL_GROUP_EXIT)
+				exit_code = signal->group_exit_code;
+			else
+				exit_code = 0;
 			goto fatal;
 		}
 
@@ -2872,15 +2877,17 @@ 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 (exit_code & 0x7f)
+			current->flags |= PF_SIGNALED;
 
 		if (sig_kernel_coredump(signr)) {
 			if (print_fatal_signals)
@@ -2909,7 +2916,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
Re: [PATCH 02/17] signal: Compute the process exit_code in get_signal
Posted by Oleg Nesterov 1 year, 7 months ago
On 06/18, Eric W. Biederman wrote:
>
> In prepartion for moving the work of sys_exit and sys_group_exit into
> get_signal compute exit_code in get_signal,

So far I don't understand the purpose of this preparation, but

> make PF_SIGNALED depend on the exit_code

> -		current->flags |= PF_SIGNALED;
> +		if (exit_code & 0x7f)
> +			current->flags |= PF_SIGNALED;

This is another user-visible change...

PF_SIGNALED means that the task didn't exit on its own but have gone
through get_signal().

This should not affect coredump_task_exit(), but what about
acct_collect/bacct_add_tsk ?

Confused...

Oleg.