[PATCH bpf-next v2 0/3] bpf: Add user memory access kfuncs for linux_binprm
Anastasios Papagiannis <[email protected]>
| Newsgroups | org.kernel.vger.linux-fsdevel,org.kernel.vger.bpf,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
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/[email protected]/ 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