Re: [PATCH] x86: fix user address masking non-canonical speculation issue
From: Linus Torvalds
Date: Thu Oct 24 2024 - 13:36:02 EST
On Wed, 23 Oct 2024 at 23:13, Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:
>
> I'm probably missing something but once LAM is enabled, how wouldn't
> this allow non-canonical address speculation?
Once LAM is enabled, together with LASS, non-canonical addresses
basically don't exit.
> 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.
IOW, notice how the LAM enablement is *dynamic* based on cpu_feature_enabled()?
(Well, right now it's commented out because Intel needs LASS for it to
work right, but that's a separate issue).
> 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 difference is just that the constant is now boot-time dynamic, so
if LAM isn't there, the whole tag bit issue goes away, of course.
> * Enforce two rules:
> * 1. 'ptr' must be in the user half of the address space
> * 2. 'ptr+size' must not overflow into kernel addresses
.. except the "user half" should probably be "user part".
Linus