On Wed, 2 Dec 2026 08:32:59 -0500
Steven Rostedt <[email protected]> wrote:

> On Wed,  2 Dec 2026 02:39:14 +0000
> James Houghton <[email protected]> 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.

Is there anywhere where it is valid to call strncpy_from_user_nofault()
when current->mm is NULL?
So the check could be moved inside.
Unlike access_ok() (and friends) this is a slow function and no one will
notice the extra check.

Thinks more...

I'd also have thought that kernel threads won't have anything mapped for
user addresses, so the access will fault, the fault handler will see the
flag that 'nofault' sets (or itself check current->mm) and return -EFAULT
instead of trying to fault-in the missing page.
So the extra check only affects threads that have mapped user addresses but
don't have current->mm.

David

> 
> -- Steve
> 


Reply via email to