All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mayank Rungta" <mrungta@google.com>
Cc: linux-watchdog@vger.kernel.org
Subject: Re: [PATCH v3 1/5] genirq: Synchronize in-flight handlers during NMI teardown
Date: Thu, 03 Sep 2026 02:06:40 +0000	[thread overview]
Message-ID: <20260903020640.AA1901F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902-qcom-wdt-nmi-series-v3-1-f3999362a9ea@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Pending NMIs can cause a NULL pointer dereference in lockless NMI handlers after desc->action is cleared.
- [High] __cleanup_nmi() does not abort when desc->action is NULL, leading to double-free of resources and refcount underflows if invoked on an already freed NMI.
--

commit cba735e452b4b54ed5512df243c59c9e7de9a13b
Author: Mayank Rungta <mrungta@google.com>

genirq: Synchronize in-flight handlers during NMI teardown

This patch modifies __cleanup_nmi() to synchronize in-flight handlers on
other CPUs before tearing down the NMI. It serializes teardown, shuts down
the line, and queries the hardware state using __irq_get_irqchip_state().

> diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
> index 2fbff2618a1e2..a9973b61163ae 100644
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
[ ... ]
> @@ -2034,11 +2042,20 @@ static const void *__cleanup_nmi(unsigned int irq, struct irq_desc *desc)
[ ... ]
> +	/*
> +	 * Ensure all in-flight NMI handlers on other CPUs complete before
> +	 * clearing desc->action or tearing down NMI state.
> +	 */
> +	__synchronize_hardirq(desc, true);
>  
> +	scoped_guard(raw_spinlock_irqsave, &desc->lock) {
>  		if (!WARN_ON(desc->action == NULL)) {
>  			action = desc->action;
>  			irq_pm_remove_action(desc, action);
>  			devname = action->name;
>  		}

[Severity: High]
This isn't a bug introduced by this patch, but does this function fail to
abort when it detects that the NMI was already cleaned up?

If a race condition occurs where desc->action is already NULL, this block
issues a warning but proceeds with the rest of the teardown unconditionally.
Could this lead to double-freeing irqchip resources, unbalanced PM usage, and
module refcount underflows if invoked on an already freed NMI?

>  		desc->action = NULL;

[Severity: High]
This is a pre-existing issue, but does this synchronization step fail to wait
for pending interrupts?

If an NMI is asserted by the hardware but the CPU has not yet taken the
exception, __synchronize_hardirq() queries IRQCHIP_STATE_ACTIVE and will
return immediately. The teardown path then clears desc->action to NULL.

Could the CPU taking the pending NMI exception then cause handle_fasteoi_nmi()
in kernel/irq/chip.c to locklessly dereference action->handler, resulting in a
NULL pointer dereference?

> -		irq_settings_clr_disable_unlazy(desc);
> -		irq_shutdown_and_deactivate(desc);
> +		irq_nmi_teardown(desc);
> +		desc->istate &= ~IRQS_NMI;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com?part=1

  reply	other threads:[~2026-09-03  2:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03  1:54 [PATCH v3 0/5] watchdog: qcom: Support NMI pretimeout warnings Mayank Rungta
2026-09-03  1:54 ` [PATCH v3 1/5] genirq: Synchronize in-flight handlers during NMI teardown Mayank Rungta
2026-09-03  2:06   ` sashiko-bot [this message]
2026-09-04  9:17   ` Thomas Gleixner
2026-09-04 13:40     ` Marc Zyngier
2026-09-04 14:34       ` Doug Anderson
2026-09-04 14:57         ` Marc Zyngier
2026-09-04 14:59           ` Doug Anderson
2026-09-04 15:11       ` Thomas Gleixner
2026-09-04 15:26         ` Doug Anderson
2026-09-03  1:54 ` [PATCH v3 2/5] genirq: Implement synchronous disable_nmi() Mayank Rungta
2026-09-03  2:11   ` sashiko-bot
2026-09-03  1:54 ` [PATCH v3 3/5] genirq: Export NMI APIs Mayank Rungta
2026-09-04  9:29   ` Thomas Gleixner
2026-09-04 14:07     ` Doug Anderson
2026-09-04 15:05       ` Thomas Gleixner
2026-09-05  1:52         ` Mayank Rungta
2026-09-03  1:54 ` [PATCH v3 4/5] watchdog: pretimeout: Protect governor access with RCU for NMI safety Mayank Rungta
2026-09-03  1:54 ` [PATCH v3 5/5] watchdog: qcom: Register pretimeout interrupt as NMI Mayank Rungta
2026-09-03  2:25   ` sashiko-bot
2026-09-03  8:18   ` Konrad Dybcio
2026-09-03 20:58     ` Mayank Rungta
2026-09-04  7:37       ` Konrad Dybcio
2026-09-04 14:37       ` Doug Anderson
2026-09-05  1:24         ` Mayank Rungta

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=20260903020640.AA1901F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=mrungta@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.