Re: [PATCH v2 12/12] uaccess: Refuse and warn on unchecked user accesses without an mm

From: James Houghton

Date: Wed Dec 02 2026 - 11:31:50 EST


On Wed, Dec 2, 2026 at 11:10 AM Christophe Leroy (CS GROUP)
<chleroy@xxxxxxxxxx> wrote:
> Le 02/12/2026 à 03:39, James Houghton a écrit :
> > __copy_{from,to}_user() and __copy_{from,to}_user_inatomic() don't call
> > access_ok(): they rely on the caller having called it earlier. That
> > earlier check may have happened in a different context, e.g. KVM checks
> > a guest's memory slots when they are set up, and then accesses them
> > through __copy_{from,to}_user() from whichever task happens to run the
> > vCPU, or to tear down the VM. So the check in access_ok() doesn't cover
> > these accesses.
> >
> > Add uaccess_should_fail(), which combines the NULL current->mm check
> > with the existing should_fail_usercopy() fault injection, and use it in
> > place of should_fail_usercopy() in __copy_{from,to}_user() and
> > __copy_to_user_inatomic(). __copy_from_user_inatomic() never called
> > should_fail_usercopy(), so only add the NULL mm check there, rather than
> > start injecting failures that some of its callers don't expect, e.g.
> > __wp_page_copy_user() warns if the copy fails twice.
> >
>
> Instead, shouldn't we try to get rid of this unchecked user accesses
> completely ? Linus started already to try and get rid of __get_user()
> and __put_user() completely. Shouldn't we continue in that direction ?

Yes! I am working on this (Arnd suggested it too[1]). From the cover letter:

- Patch 12 adds the check to the unchecked accessors,
__copy_{from,to}_user() and __copy_{from,to}_user_inatomic(), which
rely on an access_ok() done beforehand, possibly from a different
context. This is the path KVM's guest memory accessors took. I'm
preparing a separate series that removes these accessors, as Arnd
suggested, after which these checks can go away. I've uploaded a
draft here[3].

[3] https://github.com/48ca/linux/tree/no-unchecked-uaccess

The series itself is quite long and touches callers all over the
kernel. I'd prefer to tackle it after this series. :)

[1] https://lore.kernel.org/lkml/32fad21b-5bad-4640-97df-ef0f638cd9e9@xxxxxxxxxxxxxxxx/