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

From: Josh Poimboeuf
Date: Thu Oct 24 2024 - 15:13:55 EST


On Thu, Oct 24, 2024 at 11:13:35AM -0700, Linus Torvalds wrote:
> It does result in a few more casts on the C side, since you can't just
> do bitwise 'or' on a pointer, but I think it's still the right thing
> to do. So that thing becomes
>
> static inline void __user *mask_user_address(const void __user *ptr)
> {
> unsigned long mask;
> asm("cmp %1,%0\n\t"
> "sbb %0,%0"
> :"=r" (mask)
> :"r" (ptr),
> "0" (runtime_const_ptr(USER_PTR_MAX)));
> return (__force void __user *)(mask | (__force unsigned long)ptr);
> }

On a non-related note, doesn't the inline asm need a "cc" clobber?

--
Josh