Re: [PATCH v2 03/12] bpf: Fail sleepable user copy helpers when current->mm is NULL

From: Arnd Bergmann

Date: Wed Dec 02 2026 - 05:10:32 EST


On Wed, Dec 2, 2026, at 03:39, James Houghton wrote:
> Sleepable BPF programs can run on behalf of a kernel thread, or of a
> task that has already gone through exit_mm(). For example, bpf_wq
> callbacks always run from a kworker, bpf_task_work callbacks queued late
> enough run from exit_task_work(), lsm.s programs may be attached to
> hooks reached from kernel threads or from exit_task_work() (e.g.
> bpf_lsm_inode_free_security() when the final __fput() of an unlinked
> file runs from delayed_fput() or from exit_task_work(), or
> bpf_lsm_bprm_check_security() during a usermode helper's
> kernel_execve()), and fentry.s programs may be attached to
> error-injectable functions called from kernel threads (e.g.
> btrfs_should_cancel_balance() from the btrfs-balance kthread).
>
> In such contexts, bpf_copy_from_user(), bpf_copy_from_user_str() and
> bpf_copy_from_user{,_str}_dynptr() (when reading from the current task)
> call copy_from_user() or strncpy_from_user() without an mm. That access
> does not reliably fail: the user half of the address space belongs to
> whatever mm happens to be lazily loaded, if any, so the program may read
> another task's memory.
>
> As there is no user memory to read from in this case, fail with -EFAULT
> without attempting the access.
>
> Fixes: 07be4c4a3e7a ("bpf: Add bpf_copy_from_user() helper.")
> Fixes: 65ab5ac4df01 ("bpf: Add bpf_copy_from_user_str kfunc")
> Fixes: a498ee7576de ("bpf: Implement dynptr copy kfuncs")
> Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>

Reviewed-by: Arnd Bergmann <arnd@xxxxxxxx>