linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] signal: Initialize the info in ksignal
@ 2022-11-28  6:56 haifeng.xu
  2022-12-01 23:40 ` Kees Cook
  2022-12-01 23:42 ` Kees Cook
  0 siblings, 2 replies; 3+ messages in thread
From: haifeng.xu @ 2022-11-28  6:56 UTC (permalink / raw)
  To: brauner
  Cc: ebiederm, oleg, keescook, tglx, peterz, elver, linux-kernel, haifeng.xu

When handing the SIGNAL_GROUP_EXIT flag, the info in ksignal isn't cleared.
However, the info acquired by dequeue_synchronous_signal/dequeue_signal is
initialized and can be safely used. Fortunately, the fatal signal process
just uses the si_signo and doesn't use any other member. Even so, the
initialization before use is more safer.

Signed-off-by: haifeng.xu <haifeng.xu@shopee.com>
---
 kernel/signal.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/signal.c b/kernel/signal.c
index d140672185a4..b9b0c8c620e7 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2693,6 +2693,7 @@ bool get_signal(struct ksignal *ksig)
 		/* Has this task already been marked for death? */
 		if ((signal->flags & SIGNAL_GROUP_EXIT) ||
 		     signal->group_exec_task) {
+			clear_siginfo(&ksig->info);
 			ksig->info.si_signo = signr = SIGKILL;
 			sigdelset(&current->pending.signal, SIGKILL);
 			trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] signal: Initialize the info in ksignal
  2022-11-28  6:56 [PATCH] signal: Initialize the info in ksignal haifeng.xu
@ 2022-12-01 23:40 ` Kees Cook
  2022-12-01 23:42 ` Kees Cook
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2022-12-01 23:40 UTC (permalink / raw)
  To: haifeng.xu; +Cc: brauner, ebiederm, oleg, tglx, peterz, elver, linux-kernel

On Mon, Nov 28, 2022 at 06:56:06AM +0000, haifeng.xu wrote:
> When handing the SIGNAL_GROUP_EXIT flag, the info in ksignal isn't cleared.
> However, the info acquired by dequeue_synchronous_signal/dequeue_signal is
> initialized and can be safely used. Fortunately, the fatal signal process
> just uses the si_signo and doesn't use any other member. Even so, the
> initialization before use is more safer.

Yeah, this patch seems correct -- get_signal() is usually called with
an uninitialized stack variable, and normally goes through dequeue_*
helpers which do a copy. The fatal path doesn't.

-Kees

> Signed-off-by: haifeng.xu <haifeng.xu@shopee.com>
> ---
>  kernel/signal.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/kernel/signal.c b/kernel/signal.c
> index d140672185a4..b9b0c8c620e7 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -2693,6 +2693,7 @@ bool get_signal(struct ksignal *ksig)
>  		/* Has this task already been marked for death? */
>  		if ((signal->flags & SIGNAL_GROUP_EXIT) ||
>  		     signal->group_exec_task) {
> +			clear_siginfo(&ksig->info);
>  			ksig->info.si_signo = signr = SIGKILL;
>  			sigdelset(&current->pending.signal, SIGKILL);
>  			trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
> -- 
> 2.25.1
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] signal: Initialize the info in ksignal
  2022-11-28  6:56 [PATCH] signal: Initialize the info in ksignal haifeng.xu
  2022-12-01 23:40 ` Kees Cook
@ 2022-12-01 23:42 ` Kees Cook
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2022-12-01 23:42 UTC (permalink / raw)
  To: haifeng.xu, brauner
  Cc: Kees Cook, elver, oleg, ebiederm, linux-kernel, tglx, peterz

On Mon, 28 Nov 2022 06:56:06 +0000, haifeng.xu wrote:
> When handing the SIGNAL_GROUP_EXIT flag, the info in ksignal isn't cleared.
> However, the info acquired by dequeue_synchronous_signal/dequeue_signal is
> initialized and can be safely used. Fortunately, the fatal signal process
> just uses the si_signo and doesn't use any other member. Even so, the
> initialization before use is more safer.
> 
> 
> [...]

Applied to for-next/hardening, thanks!

[1/1] signal: Initialize the info in ksignal
      https://git.kernel.org/kees/c/935d428bb528

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-01 23:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28  6:56 [PATCH] signal: Initialize the info in ksignal haifeng.xu
2022-12-01 23:40 ` Kees Cook
2022-12-01 23:42 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).