Re: [PATCH v2 06/12] bpf: Don't read user memory without an mm in tracing helpers
From: James Houghton
Date: Wed Dec 02 2026 - 11:41:33 EST
On Wed, Dec 2, 2026 at 8:02 AM Arnd Bergmann <arnd@xxxxxxxx> wrote:
>
> On Wed, Dec 2, 2026, at 05:07, Alexei Starovoitov wrote:
> > On Tue, Dec 01, 2026 at 06:39 PM James Houghton <jthoughton@xxxxxxxxxx> wrote:
> >> + /*
> >> + * Tracing programs may run in any context, including kernel threads
> >> + * and exiting tasks, which have no user memory to read. That's not a
> >> + * kernel bug, so fail before the user copy helpers warn about it.
> >> + */
> >> + if (unlikely(!current->mm))
> >> + ret = -EFAULT;
> >> + else
> >> + ret = copy_from_user_nofault(dst, unsafe_ptr, size);
> >
> > The nofault helpers exist for callers that run in any context.
> > v1 had the check inside the helpers. That was the right place.
> > Nack to v2.
>
> Looking through it all again, I agree with this now, as it simplifies
> the rules. If {copy_from,strncpy_from,strnlen}_user_nofault()
> silently fail on !current->mm, a couple of patches in this series
> are no longer needed, and James has checked the remaining users
> for correctness.
Thanks Alexei, Arnd. I'm happy to go back to how v1 did it (so we can
drop patches 6-8). Here's a WIP of v3 if you want to take a look [1].
[1] https://github.com/48ca/linux uaccess-v3-wip