mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: LKML <linux-kernel@vger.kernel.org>, Xin Li <xin@zytor.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org
Subject: Re: [PATCH] x86/fred: Correct speculative safety in fred_extint()
Date: Tue, 6 Jan 2026 16:20:08 +0100	[thread overview]
Message-ID: <20260106152008.GZ3707891@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260106131504.679932-1-andrew.cooper3@citrix.com>

On Tue, Jan 06, 2026 at 01:15:04PM +0000, Andrew Cooper wrote:
> array_index_nospec() is no use if the result gets spilled to the stack, as
> it makes the believed safe-under-speculation value subject to memory
> predictions.
> 
> For all practical purposes, this means array_index_nospec() must be used in
> the expression that accesses the array.
> 
> As the code currently stands, it's the wrong side of irqentry_enter(), and
> 'index' is put into %ebp across the function call.
> 
> Remove the index variable and reposition array_index_nospec(), so it's
> calculated immediately before the array access.
> 
> Fixes: 14619d912b65 ("x86/fred: FRED entry/exit and dispatch code")
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

I suppose I can go stick this in x86/urgent or so.

> This is why we have array_access_nospec() in Xen, so you can't separate the
> safety calculation from the array access.
> 
> The observant reader might notice that the result of reading sysvec_table[] is
> also subject to memory predictions.  Aren't CPUs wonderful...
> 
> In practice, even having array_index_nospec() part of the array access
> expression is no guarantee of avoiding spilling to the stack.  KASAN is liable
> to hide a function call behind the scenes, while UBSAN is very good at
> inserting it's own unsafe range checks around objects it knows the size of.
> Aren't compilers wonderful...

Yeah, then again nobody should be running *SAN kernels in production,
right ;-)

> ---
>  arch/x86/entry/entry_fred.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/entry/entry_fred.c b/arch/x86/entry/entry_fred.c
> index 94e626cc6a07..4fc5b176d3ed 100644
> --- a/arch/x86/entry/entry_fred.c
> +++ b/arch/x86/entry/entry_fred.c
> @@ -159,8 +159,6 @@ void __init fred_complete_exception_setup(void)
>  static noinstr void fred_extint(struct pt_regs *regs)
>  {
>  	unsigned int vector = regs->fred_ss.vector;
> -	unsigned int index = array_index_nospec(vector - FIRST_SYSTEM_VECTOR,
> -						NR_SYSTEM_VECTORS);
>  
>  	if (WARN_ON_ONCE(vector < FIRST_EXTERNAL_VECTOR))
>  		return;
> @@ -169,7 +167,8 @@ static noinstr void fred_extint(struct pt_regs *regs)
>  		irqentry_state_t state = irqentry_enter(regs);
>  
>  		instrumentation_begin();
> -		sysvec_table[index](regs);
> +		sysvec_table[array_index_nospec(vector - FIRST_SYSTEM_VECTOR,
> +						NR_SYSTEM_VECTORS)](regs);
>  		instrumentation_end();
>  		irqentry_exit(regs, state);
>  	} else {

  reply	other threads:[~2026-01-06 15:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-06 13:15 Andrew Cooper
2026-01-06 15:20 ` Peter Zijlstra [this message]
2026-01-06 16:46   ` Andrew Cooper
2026-01-06 17:06     ` H. Peter Anvin
2026-01-07  0:15       ` Andrew Cooper
2026-02-23 10:25 ` [tip: x86/urgent] " tip-bot2 for Andrew Cooper

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=20260106152008.GZ3707891@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xin@zytor.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®