RE: [PATCH 12/14] x86: remove address space overrides using set_fs()

From: David Laight
Date: Fri Sep 04 2020 - 03:59:35 EST


From: Linus Torvalds
> Sent: 04 September 2020 00:26
>
> On Thu, Sep 3, 2020 at 2:30 PM David Laight <David.Laight@xxxxxxxxxx> wrote:
> >
> > A non-canonical (is that the right term) address between the highest
> > valid user address and the lowest valid kernel address (7ffe to fffe?)
> > will fault anyway.
>
> Yes.
>
> But we actually warn against that fault, because it's been a good way
> to catch places that didn't use the proper "access_ok()" pattern.
>
> See ex_handler_uaccess() and the
>
> WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault in
> user access. Non-canonical address?");
>
> warning. It's been good for randomized testing - a missing range check
> on a user address will often hit this.
>
> Of course, you should never see it in real life (and hopefully not in
> testing either any more). But belt-and-suspenders..

That could still be effective, just pick an address limit that is
appropriate for the one access_ok() is using.

Even if access_ok() uses 1<<63 there are plenty of addresses above it that fault.
But the upper limit for 5-level page tables could be used all the time.

One option is to test '(address | length) < (3<<62)' in access_ok().
That is also moderately suitable for masking invalid addresses to 0.

David

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