Re: [PATCH] x86: fix user address masking non-canonical speculation issue

From: Josh Poimboeuf
Date: Thu Oct 24 2024 - 11:43:40 EST


On Thu, Oct 24, 2024 at 05:02:42PM +0300, Kirill A. Shutemov wrote:
> On Wed, Oct 23, 2024 at 11:13:00PM -0700, Josh Poimboeuf wrote:
> > On Wed, Oct 23, 2024 at 06:31:59PM -0700, Linus Torvalds wrote:
> > > @@ -2389,6 +2390,15 @@ void __init arch_cpu_finalize_init(void)
> > > + /*
> > > + * Enable this when LAM is gated on LASS support
> > > + if (cpu_feature_enabled(X86_FEATURE_LAM))
> > > + USER_PTR_MAX = (1ul << 63) - PAGE_SIZE;
> > > + */
> >
> > I'm probably missing something but once LAM is enabled, how wouldn't
> > this allow non-canonical address speculation? i.e. when bit 47/56 is
> > set and 63 is cleared, would it not go untouched by mask_user_address()
> > and thus be speculatively interpreted by AMD as a kernel address?
>
> CPU with LAM enabled enforces bit 63 to be equal bit 47/56 and raises #GP
> otherwise.

Right, but I'm asking about the speculation bug which happens before the
exception (and which prompted this patch in the first place).

--
Josh