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

From: Josh Poimboeuf
Date: Thu Oct 24 2024 - 14:47:52 EST


On Thu, Oct 24, 2024 at 10:35:33AM -0700, Linus Torvalds wrote:
> > 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?
>
> AMD doesn't _have_ LAM. When they do, they had better not
> speculatively mis-interpret addresses.

Ok. I was thinking AMD had its own version of LAM, though all I can
find is UAI which is actually quite different since it ignores bit 63
altogether (and isn't supported in Linux anyway).

> > Also, the comment above __access_ok() now seems obsolete:
> >
> > /*
> > * User pointers can have tag bits on x86-64. This scheme tolerates
> > * arbitrary values in those bits rather then masking them off.
>
> No. The comment is still correct. The scheme tolerates exactly the LAM
> kind of hardware-based address masking.

The comment doesn't seem right to me at all.

With LAM enabled, USER_PTR_MAX is PAGE_SIZE away from the sign change
boundary. So __access_ok() no longer has size check slop and that whole
discussion about the sign change boundary can go away.

AFAICT #GP can only happen when LAM is enabled and bit 47 (or 56 for
LA57) doesn't match bit 63.

--
Josh