mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/3] bpf: Add user memory access kfuncs for linux_binprm
@ 2026-08-20 13:17 Anastasios Papagiannis
  2026-08-20 13:17 ` [PATCH bpf-next v2 1/3] mm: Add copy_remote_mm_str() Anastasios Papagiannis
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Anastasios Papagiannis @ 2026-08-20 13:17 UTC (permalink / raw)
  To: bpf
  Cc: linux-kernel, linux-mm, linux-fsdevel, viro, brauner, akpm,
	david, ast, daniel, andrii, eddyz87, memxor, kpsingh, matt, song,
	utilityemal77, tasos.papagiannnis

During exec, argument and environment strings are copied into the new
address space held by struct linux_binprm before that address space is
installed on the task_struct. Existing eBPF user memory helpers only
support reading from the old address space (i.e. current process)
and for this reason programs cannot access these strings from the
bprm_check_security LSM hook.

This series adds two sleepable BPF kfuncs for copying bytes or
NUL-terminated strings from the address space held by struct linux_binprm.
This allows BPF LSM programs to inspect exec arguments before allowing
the exec to continue.

The series also adds selftests covering both kfuncs when reading argument
and environment strings.

Changes in v2:
- Register the kfuncs on NOMMU systems and return -EOPNOTSUPP when called,
  as suggested by Justin Suess.
- Add selftest coverage for reading environment strings, as suggested by
  Justin Suess.
- Clarify that copy_remote_mm_str() leaves the destination untouched when
  called with a zero-length buffer.
- Use sizeof() instead of hardcoded argument lengths in the selftests.
- Use ~0ULL for invalid-flags checks in the selftests.

v1:
https://lore.kernel.org/bpf/20260812111140.7762-1-tasos.papagiannnis@gmail.com/

Anastasios Papagiannis (3):
  mm: Add copy_remote_mm_str()
  bpf: Add user memory access kfuncs for linux_binprm
  selftests/bpf: Test linux_binprm user memory kfuncs

 fs/bpf_fs_kfuncs.c                            | 128 ++++++++++++++++++
 include/linux/mm.h                            |   2 +
 mm/memory.c                                   |  26 +++-
 mm/nommu.c                                    |  26 +++-
 .../bpf/prog_tests/copy_from_user_bprm.c      |  62 +++++++++
 .../selftests/bpf/progs/copy_from_user_bprm.c | 115 ++++++++++++++++
 6 files changed, 357 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/copy_from_user_bprm.c
 create mode 100644 tools/testing/selftests/bpf/progs/copy_from_user_bprm.c


base-commit: f79066c784022fda83f5936559a1af414e41b603
-- 
2.55.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-08-31  9:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-20 13:17 [PATCH bpf-next v2 0/3] bpf: Add user memory access kfuncs for linux_binprm Anastasios Papagiannis
2026-08-20 13:17 ` [PATCH bpf-next v2 1/3] mm: Add copy_remote_mm_str() Anastasios Papagiannis
2026-08-20 14:05   ` bot+bpf-ci
2026-08-21 19:52   ` Andrii Nakryiko
2026-08-20 13:18 ` [PATCH bpf-next v2 2/3] bpf: Add user memory access kfuncs for linux_binprm Anastasios Papagiannis
2026-08-20 14:21   ` bot+bpf-ci
2026-08-21 19:51   ` Andrii Nakryiko
2026-08-24 10:49     ` [PATCH bpf-next " Anastasios Papagiannis
2026-08-24 20:01       ` Andrii Nakryiko
2026-08-31  9:25         ` Anastasios Papagiannis
2026-08-20 13:18 ` [PATCH bpf-next v2 3/3] selftests/bpf: Test linux_binprm user memory kfuncs Anastasios Papagiannis
2026-08-20 14:21   ` bot+bpf-ci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®