Re: [PATCH v2 07/12] tracing: Don't read user memory without an mm

From: James Houghton

Date: Wed Dec 02 2026 - 11:44:12 EST


On Wed, Dec 2, 2026 at 8:33 AM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> On Wed, 2 Dec 2026 02:39:14 +0000
> James Houghton <jthoughton@xxxxxxxxxx> wrote:
>
> > #ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
> > - if ((unsigned long)str_val < TASK_SIZE)
> > - ret = strncpy_from_user_nofault(str_field, (const void __user *)str_val, STR_VAR_LEN_MAX);
> > - else
> > + if ((unsigned long)str_val < TASK_SIZE) {
> > + /*
> > + * Synthetic events may fire in any context, including
> > + * kernel threads, which have no user memory to read.
> > + */
> > + if (unlikely(!current->mm))
> > + ret = -EFAULT;
> > + else
> > + ret = strncpy_from_user_nofault(str_field,
> > + (const void __user *)str_val,
> > + STR_VAR_LEN_MAX);
> > + } else
> > #endif
>
> Instead of adding all these crazy checks, and then we need to play
> whack-a-mole when we add a new one that triggers the warning, can't you add
> a helper function for this?
>
> strncpy_from_user_trace_nofault()?
>
> Where it can be used by places that do not care if there's an current->mm or not.
>
> If you are reading user space for tracing purposes, it may be done from a
> kernel thread too, and that's not a bug. It should simply return -EFAULT.

Hi Steve,

Thanks for the feedback! Yes adding strncpy_from_user_trace_nofault()
would be much better, but I think I'm going to drop this patch anyway
given the feedback on got on patch 6[1].

[1] https://lore.kernel.org/kvm/a611a1a5-e20f-4ff1-aeb1-520a307e6d30@xxxxxxxxxxxxxxxx/