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]
Message-ID: <c128c9b0-6bfa-4d62-9bc9-1215ee12ce2b@paulmck-laptop>
Date: Wed, 7 Feb 2024 10:30:17 -0800
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Breno Leitao <leitao@...ian.org>
Cc: Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>,
	Borislav Petkov <bp@...en8.de>,
	Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
	"H. Peter Anvin" <hpa@...or.com>, leit@...a.com,
	Mark Rutland <mark.rutland@....com>, Ingo Molnar <mingo@...nel.org>,
	"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] x86/nmi: Fix "in NMI handler" check

On Wed, Feb 07, 2024 at 08:52:35AM -0800, Breno Leitao wrote:
> Commit 344da544f177 ("x86/nmi: Print reasons why backtrace NMIs are
> ignored") creates a super nice framework to diagnose NMIs.
> 
> Every time nmi_exc() is called, it increments a per_cpu counter
> (nsp->idt_nmi_seq). At its exit, it also increments the same counter.
> Looking at this counter, you can see how many times that function was
> called (dividing by 2), and, if the function is still being executed, by
> checking the idt_nmi_seq's last bit.
> 
> On the check side (nmi_backtrace_stall_check()), that variable is
> queried to check if the NMI is still being executed, but, there is a
> mistake in the bitwise operation. That code wants to check if the last
> bit of the idt_nmi_seq is set or not, but, does the opposite, and check
> for all the other bits, which will always be true after the first
> exc_nmi() executed successfully.
> 
> This appends the misleading string to the dump "(CPU currently in NMI
> handler function)"
> 
> Fix it by checking the last bit, and if it is set, append the string.
> 
> Fixes: 344da544f177 ("x86/nmi: Print reasons why backtrace NMIs are ignored")
> Signed-off-by: Breno Leitao <leitao@...ian.org>

If someone else is taking this:

Reviewed-by: Paul E. McKenney <paulmck@...nel.org>

(I am queueing it for testing in any case.)

> ---
>  arch/x86/kernel/nmi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
> index 17e955ab69fe..6e738ad474dc 100644
> --- a/arch/x86/kernel/nmi.c
> +++ b/arch/x86/kernel/nmi.c
> @@ -639,7 +639,7 @@ void nmi_backtrace_stall_check(const struct cpumask *btp)
>  			msgp = nmi_check_stall_msg[idx];
>  			if (nsp->idt_ignored_snap != READ_ONCE(nsp->idt_ignored) && (idx & 0x1))
>  				modp = ", but OK because ignore_nmis was set";
> -			if (nmi_seq & ~0x1)
> +			if (nmi_seq & 0x1)
>  				msghp = " (CPU currently in NMI handler function)";
>  			else if (nsp->idt_nmi_seq_snap + 1 == nmi_seq)
>  				msghp = " (CPU exited one NMI handler function)";
> -- 
> 2.39.3
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ