diff options
| author | Anastasios Papagiannis <tasos.papagiannnis@gmail.com> | 2026-09-18 16:17:55 +0300 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2026-09-18 15:32:01 +0000 |
| commit | 3f9d98dfed79ffc969d15cf214388ebf861f03af (patch) | |
| tree | b39e89876b3e77f0c2e149fca6d1c947db8d4c25 /include/linux | |
| parent | adc7fb9955e2718faf949cdc1efaf78179978445 (diff) | |
bpf: Add user memory access kfuncs for mm_struct
On CONFIG_MMU kernels, when security_bprm_check() runs, the argument and
environment strings for the exec have been copied into bprm->mm. The new
address space is not associated with a task_struct until exec_mmap(), so
existing BPF user memory helpers cannot access it.
Add bpf_copy_from_user_mm() and bpf_copy_from_user_mm_str() kfuncs. Both
take a struct mm_struct pointer directly, allowing callers to access
trusted address spaces that are not associated with a task_struct.
bpf_copy_from_user_mm() has similar semantics to
bpf_copy_from_user_task(). bpf_copy_from_user_mm_str() copies one
NUL-terminated string and returns its size including the NUL terminator.
It accepts BPF_F_PAD_ZEROS to clear unused destination bytes on success.
Refactor the task-based helpers and the new mm-based kfuncs to share
static internal implementations. The task-based interfaces validate their
arguments before acquiring and holding a reference to the task's mm for
the copy. No behavior change is intended for the existing task-based
interfaces.
Register both new kfuncs and mark them KF_SLEEPABLE because accessing a
remote address space can fault.
Signed-off-by: Anastasios Papagiannis <tasos.papagiannnis@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Matt Bobrowski <matt@bobrowski.net>
Link: https://patch.msgid.link/20260918131757.42802-4-tasos.papagiannnis@gmail.com
Diffstat (limited to 'include/linux')
0 files changed, 0 insertions, 0 deletions
