linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf v3 0/2] bpf: fix bpf_d_path() helper prototype
@ 2025-12-02 14:19 Shuran Liu
  2025-12-02 14:19 ` [PATCH bpf v3 1/2] bpf: mark bpf_d_path() buffer as writeable Shuran Liu
  2025-12-02 14:19 ` [PATCH bpf v3 2/2] selftests/bpf: fix and consolidate d_path LSM regression test Shuran Liu
  0 siblings, 2 replies; 9+ messages in thread
From: Shuran Liu @ 2025-12-02 14:19 UTC (permalink / raw)
  To: song, mattbobrowski, bpf
  Cc: ast, daniel, andrii, martin.lau, eddyz87, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, rostedt, mhiramat,
	mathieu.desnoyers, linux-kernel, linux-trace-kernel, dxu,
	linux-kselftest, shuah, electronlsr

Hi,

This series fixes a verifier issue with bpf_d_path() and adds a
regression test to cover its use from an LSM program.

Patch 1 updates the bpf_d_path() helper prototype so that the second
argument is marked as MEM_WRITE. This makes it explicit to the verifier
that the helper writes into the provided buffer.

Patch 2 extends the existing d_path selftest to also cover the LSM
bprm_check_security hook. The LSM program calls bpf_d_path() on the
binary being executed and performs a simple prefix comparison on the
resulting pathname. To avoid nondeterminism, the program filters based
on an expected PID that is populated from userspace before the test
binary is executed, and the parent and child processes are synchronized
through a pipe so that the PID is set before exec. The test now uses
bpf_for() to express the small fixed-iteration loop in a
verifier-friendly way, and it removes the temporary /tmp/bpf_d_path_test
binary in the cleanup path.

Changelog
=========

v3:
  - Switch the pathname prefix loop to use bpf_for() instead of
    #pragma unroll, as suggested by Matt.
  - Remove /tmp/bpf_d_path_test in the test cleanup path.
  - Add the missing Reviewed-by tags.

v2:
  - Merge the new test into the existing d_path selftest rather than   
  creating new files.   
  - Add PID filtering in the LSM program to avoid nondeterministic failures   
  due to unrelated processes triggering bprm_check_security.   
  - Synchronize child execution using a pipe to ensure deterministic   
  updates to the PID. 

Thanks for your time and reviews.

Shuran Liu (2):
  bpf: mark bpf_d_path() buffer as writeable
  selftests/bpf: fix and consolidate d_path LSM regression test

 kernel/trace/bpf_trace.c                      |  2 +-
 .../testing/selftests/bpf/prog_tests/d_path.c | 65 +++++++++++++++++++
 .../testing/selftests/bpf/progs/test_d_path.c | 33 ++++++++++
 3 files changed, 99 insertions(+), 1 deletion(-)

-- 
2.52.0


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

end of thread, other threads:[~2025-12-04 21:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-02 14:19 [PATCH bpf v3 0/2] bpf: fix bpf_d_path() helper prototype Shuran Liu
2025-12-02 14:19 ` [PATCH bpf v3 1/2] bpf: mark bpf_d_path() buffer as writeable Shuran Liu
2025-12-02 14:19 ` [PATCH bpf v3 2/2] selftests/bpf: fix and consolidate d_path LSM regression test Shuran Liu
2025-12-02 18:39   ` Song Liu
2025-12-04  4:34     ` Shuran Liu
2025-12-04 21:41       ` Song Liu
2025-12-03  1:21   ` Alexei Starovoitov
2025-12-03 10:32     ` Matt Bobrowski
2025-12-04  4:39       ` Shuran Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).