RE: [PATCH v3] x86/uaccess: Use pointer masking to limit uaccess speculation

From: David Laight
Date: Mon Sep 14 2020 - 17:24:06 EST


From: Borislav Petkov
> Sent: 14 September 2020 18:56
>
> On Thu, Sep 10, 2020 at 12:22:53PM -0500, Josh Poimboeuf wrote:
> > +/*
> > + * Sanitize a user pointer such that it becomes NULL if it's not a valid user
> > + * pointer. This prevents speculative dereferences of user-controlled pointers
> > + * to kernel space when access_ok() speculatively returns true. This should be
> > + * done *after* access_ok(), to avoid affecting error handling behavior.
>
> Err, stupid question: can this macro then be folded into access_ok() so
> that you don't have to touch so many places and the check can happen
> automatically?

My thoughts are that access_ok() could return 0 for fail and ~0u
for success.
You could then do (with a few casts):
mask = access_ok(ptr, size);
/* Stop gcc tracking the value of mask. */
asm volatile( "" : "+r" (mask));
addr = ptr & mask;
if (!addr && ptr) // Let NULL through??
return -EFAULT;

I think there are other changes in the pipeline to remove
most of the access_ok() apart from those inside put/get_user()
and copy_to/from_user().
So the changes should be more limited than you might think.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)