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

From: Kirill A. Shutemov
Date: Thu Oct 24 2024 - 10:03:04 EST


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.

--
Kiryl Shutsemau / Kirill A. Shutemov