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.
-- Steve