All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] exit: Detect and fix irq disabled state in oops
@ 2022-10-04  9:44 Nicholas Piggin
  2022-12-20  7:14 ` Nicholas Piggin
  0 siblings, 1 reply; 5+ messages in thread
From: Nicholas Piggin @ 2022-10-04  9:44 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: Nicholas Piggin, linux-kernel, Michael Ellerman

If a task oopses with irqs disabled, this can cause various cascading
problems in the oops path such as sleep-from-invalid warnings, and
potentially worse.

Since commit 0258b5fd7c712 ("coredump: Limit coredumps to a single
thread group"), the unconditional irq enable in coredump_task_exit()
will "fix" the irq state to be enabled early in do_exit(), so currently
this may not be triggerable, but that is coincidental and fragile.

Detect and fix the irqs_disabled() condition in the oops path before
calling do_exit(), similarly to the way in_atomic() is handled.

Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 kernel/exit.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/exit.c b/kernel/exit.c
index 84021b24f79e..fa696765f694 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -738,6 +738,7 @@ void __noreturn do_exit(long code)
 	struct task_struct *tsk = current;
 	int group_dead;
 
+	WARN_ON(irqs_disabled());
 	WARN_ON(tsk->plug);
 
 	kcov_task_exit(tsk);
@@ -865,6 +866,11 @@ void __noreturn make_task_dead(int signr)
 	if (unlikely(!tsk->pid))
 		panic("Attempted to kill the idle task!");
 
+	if (unlikely(irqs_disabled())) {
+		pr_info("note: %s[%d] exited with irqs disabled\n",
+			current->comm, task_pid_nr(current));
+		local_irq_enable();
+	}
 	if (unlikely(in_atomic())) {
 		pr_info("note: %s[%d] exited with preempt_count %d\n",
 			current->comm, task_pid_nr(current),
-- 
2.37.2


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

* Re: [PATCH] exit: Detect and fix irq disabled state in oops
  2022-10-04  9:44 [PATCH] exit: Detect and fix irq disabled state in oops Nicholas Piggin
@ 2022-12-20  7:14 ` Nicholas Piggin
  2022-12-24  4:28   ` Eric W. Biederman
  0 siblings, 1 reply; 5+ messages in thread
From: Nicholas Piggin @ 2022-12-20  7:14 UTC (permalink / raw)
  To: Nicholas Piggin, Eric W. Biederman; +Cc: linux-kernel, Michael Ellerman

On Tue Oct 4, 2022 at 7:44 PM AEST, Nicholas Piggin wrote:
> If a task oopses with irqs disabled, this can cause various cascading
> problems in the oops path such as sleep-from-invalid warnings, and
> potentially worse.
>
> Since commit 0258b5fd7c712 ("coredump: Limit coredumps to a single
> thread group"), the unconditional irq enable in coredump_task_exit()
> will "fix" the irq state to be enabled early in do_exit(), so currently
> this may not be triggerable, but that is coincidental and fragile.
>
> Detect and fix the irqs_disabled() condition in the oops path before
> calling do_exit(), similarly to the way in_atomic() is handled.
>
> Reported-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>

Hey Eric, did you have any thoughts on this?

Thanks,
Nick

> ---
>  kernel/exit.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/kernel/exit.c b/kernel/exit.c
> index 84021b24f79e..fa696765f694 100644
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -738,6 +738,7 @@ void __noreturn do_exit(long code)
>  	struct task_struct *tsk = current;
>  	int group_dead;
>  
> +	WARN_ON(irqs_disabled());
>  	WARN_ON(tsk->plug);
>  
>  	kcov_task_exit(tsk);
> @@ -865,6 +866,11 @@ void __noreturn make_task_dead(int signr)
>  	if (unlikely(!tsk->pid))
>  		panic("Attempted to kill the idle task!");
>  
> +	if (unlikely(irqs_disabled())) {
> +		pr_info("note: %s[%d] exited with irqs disabled\n",
> +			current->comm, task_pid_nr(current));
> +		local_irq_enable();
> +	}
>  	if (unlikely(in_atomic())) {
>  		pr_info("note: %s[%d] exited with preempt_count %d\n",
>  			current->comm, task_pid_nr(current),
> -- 
> 2.37.2


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

* Re: [PATCH] exit: Detect and fix irq disabled state in oops
  2022-12-20  7:14 ` Nicholas Piggin
@ 2022-12-24  4:28   ` Eric W. Biederman
  0 siblings, 0 replies; 5+ messages in thread
From: Eric W. Biederman @ 2022-12-24  4:28 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: linux-kernel, Michael Ellerman

"Nicholas Piggin" <npiggin@gmail.com> writes:

> On Tue Oct 4, 2022 at 7:44 PM AEST, Nicholas Piggin wrote:
>> If a task oopses with irqs disabled, this can cause various cascading
>> problems in the oops path such as sleep-from-invalid warnings, and
>> potentially worse.
>>
>> Since commit 0258b5fd7c712 ("coredump: Limit coredumps to a single
>> thread group"), the unconditional irq enable in coredump_task_exit()
>> will "fix" the irq state to be enabled early in do_exit(), so currently
>> this may not be triggerable, but that is coincidental and fragile.
>>
>> Detect and fix the irqs_disabled() condition in the oops path before
>> calling do_exit(), similarly to the way in_atomic() is handled.
>>
>> Reported-by: Michael Ellerman <mpe@ellerman.id.au>
>> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
>
> Hey Eric, did you have any thoughts on this?

No strong thoughts.

I agree that the unconditionally disabling then enabling irqs in
coredump_task_exit will mean there is likely to be little change in real
behavior.

I also agree that is something fragile to depend upon so we making
our assumptions explicit seems good.

Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>

>
> Thanks,
> Nick
>
>> ---
>>  kernel/exit.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/kernel/exit.c b/kernel/exit.c
>> index 84021b24f79e..fa696765f694 100644
>> --- a/kernel/exit.c
>> +++ b/kernel/exit.c
>> @@ -738,6 +738,7 @@ void __noreturn do_exit(long code)
>>  	struct task_struct *tsk = current;
>>  	int group_dead;
>>  
>> +	WARN_ON(irqs_disabled());
>>  	WARN_ON(tsk->plug);
>>  
>>  	kcov_task_exit(tsk);
>> @@ -865,6 +866,11 @@ void __noreturn make_task_dead(int signr)
>>  	if (unlikely(!tsk->pid))
>>  		panic("Attempted to kill the idle task!");
>>  
>> +	if (unlikely(irqs_disabled())) {
>> +		pr_info("note: %s[%d] exited with irqs disabled\n",
>> +			current->comm, task_pid_nr(current));
>> +		local_irq_enable();
>> +	}
>>  	if (unlikely(in_atomic())) {
>>  		pr_info("note: %s[%d] exited with preempt_count %d\n",
>>  			current->comm, task_pid_nr(current),
>> -- 
>> 2.37.2

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

* Re: [PATCH] exit: Detect and fix irq disabled state in oops
  2023-01-20  1:18 Nicholas Piggin
@ 2023-01-20 15:21 ` Peter Zijlstra
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2023-01-20 15:21 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: Ingo Molnar, linux-kernel, Michael Ellerman, Eric W. Biederman

On Fri, Jan 20, 2023 at 11:18:20AM +1000, Nicholas Piggin wrote:
> If a task oopses with irqs disabled, this can cause various cascading
> problems in the oops path such as sleep-from-invalid warnings, and
> potentially worse.
> 
> Since commit 0258b5fd7c712 ("coredump: Limit coredumps to a single
> thread group"), the unconditional irq enable in coredump_task_exit()
> will "fix" the irq state to be enabled early in do_exit(), so currently
> this may not be triggerable, but that is coincidental and fragile.
> 
> Detect and fix the irqs_disabled() condition in the oops path before
> calling do_exit(), similarly to the way in_atomic() is handled.
> 
> Link: https://lore.kernel.org/lkml/20221004094401.708299-1-npiggin@gmail.com/
> Reported-by: Michael Ellerman <mpe@ellerman.id.au>
> Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> Hi Peter,
> 
> Would you consider taking this through the sched tree?

Yep, can do, let me go queue it.

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

* [PATCH] exit: Detect and fix irq disabled state in oops
@ 2023-01-20  1:18 Nicholas Piggin
  2023-01-20 15:21 ` Peter Zijlstra
  0 siblings, 1 reply; 5+ messages in thread
From: Nicholas Piggin @ 2023-01-20  1:18 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Nicholas Piggin, Ingo Molnar, linux-kernel, Michael Ellerman,
	Eric W. Biederman

If a task oopses with irqs disabled, this can cause various cascading
problems in the oops path such as sleep-from-invalid warnings, and
potentially worse.

Since commit 0258b5fd7c712 ("coredump: Limit coredumps to a single
thread group"), the unconditional irq enable in coredump_task_exit()
will "fix" the irq state to be enabled early in do_exit(), so currently
this may not be triggerable, but that is coincidental and fragile.

Detect and fix the irqs_disabled() condition in the oops path before
calling do_exit(), similarly to the way in_atomic() is handled.

Link: https://lore.kernel.org/lkml/20221004094401.708299-1-npiggin@gmail.com/
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
Hi Peter,

Would you consider taking this through the sched tree?

Thanks,
Nick

 kernel/exit.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/exit.c b/kernel/exit.c
index 15dc2ec80c46..bccfa4218356 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -807,6 +807,8 @@ void __noreturn do_exit(long code)
 	struct task_struct *tsk = current;
 	int group_dead;
 
+	WARN_ON(irqs_disabled());
+
 	synchronize_group_exit(tsk, code);
 
 	WARN_ON(tsk->plug);
@@ -938,6 +940,11 @@ void __noreturn make_task_dead(int signr)
 	if (unlikely(!tsk->pid))
 		panic("Attempted to kill the idle task!");
 
+	if (unlikely(irqs_disabled())) {
+		pr_info("note: %s[%d] exited with irqs disabled\n",
+			current->comm, task_pid_nr(current));
+		local_irq_enable();
+	}
 	if (unlikely(in_atomic())) {
 		pr_info("note: %s[%d] exited with preempt_count %d\n",
 			current->comm, task_pid_nr(current),
-- 
2.37.2


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

end of thread, other threads:[~2023-01-20 15:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-04  9:44 [PATCH] exit: Detect and fix irq disabled state in oops Nicholas Piggin
2022-12-20  7:14 ` Nicholas Piggin
2022-12-24  4:28   ` Eric W. Biederman
2023-01-20  1:18 Nicholas Piggin
2023-01-20 15:21 ` Peter Zijlstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.