Re: [PATCH v2 12/12] uaccess: Refuse and warn on unchecked user accesses without an mm
From: David Laight
Date: Wed Dec 02 2026 - 12:45:45 EST
On Wed, 2 Dec 2026 17:10:38 +0100
"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 ?
That and the abuse of those functions for accesses to 'dodgy' pointers
to kernel memory.
I think bpf does some, if the pointers are dodgy then what you read is
garbage and IMHO you shouldn't be doing it.
I think the problem is that it allows arbitrary code be added at random
places in the kernel - where nothing has checked that the types match
at all.
David
>
> Christophe
>