Skip to content

Introduce bpf_kern_path and bpf_path_put

Song Liu bpf linux-fsdevel linux-security-module llvm oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3bpf: Allow const char * from LSM hooks as kfunc const string argumentsinclude/linux/btf.h kernel/bpf/btf.c kernel/bpf/verifier.c+73 -120 replies
1/3bpf: Allow const char * from LSM hooks as kfunc const string argumentsinclude/linux/btf.h kernel/bpf/btf.c kernel/bpf/verifier.c+73 -120 replies
2/3bpf: Add bpf_kern_path and bpf_path_put kfuncsfs/bpf_fs_kfuncs.c+58 -04 replies
2/3bpf: Add bpf_kern_path and bpf_path_put kfuncsfs/bpf_fs_kfuncs.c+58 -00 replies
3/3selftests/bpf: Add tests for bpf_kern_path kfunctools/testing/selftests/bpf/bpf_experimental.h tools/testing/selftests/bpf/prog_tests/kern_path.c tools/testing/selftests/bpf/progs/test_kern_path.c +2 more+291 -00 replies
3/3selftests/bpf: Add tests for bpf_kern_path kfunctools/testing/selftests/bpf/bpf_experimental.h tools/testing/selftests/bpf/prog_tests/kern_path.c tools/testing/selftests/bpf/progs/test_kern_path.c +2 more+291 -00 replies

Reviews trailers per patch

None of the 6 patches has a Reviewed-by or Acked-by.

PatchAl Viro
1/3
1/3
2/3NAKed-by
2/3NAKed-by
3/3
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH bpf-next 0/3] Introduce bpf_kern_path and bpf_path_put

Security solutions use LSM hook security_sb_mount to monitor mount operations. security_sb_mount takes dev_name as a string. To get a struct path from dev_name, in-tree LSMs use kern_path. Introduce kfuncs bpf_kern_path so that bpf LSM can do similar operations. bpf_kern_path takes a reference on the return value path. Also add kfunc bpf_path_put to release path returned by bpf_kern_path. Note that, bpf_kern_path only holds reference on the path during the duration of this bpf program. The verifier enforces the bpf program release this reference.

Patch 1/3 prepares bpf verifier to handle const char * passed in as hook argument. Before this change, bpf helpers and kfuncs only consider value from read only map as const string.

Patch 2/3 adds the two kfuncs.

Patch 3/3 add tests for the new kfuncs.

Song Liu (3):
bpf: Allow const char * from LSM hooks as kfunc const string arguments
bpf: Add bpf_kern_path and bpf_path_put kfuncs selftests/bpf: Add tests for bpf_kern_path kfunc

 fs/bpf_fs_kfuncs.c                            | 58 +++++++++++
 include/linux/btf.h                           |  1 +
 kernel/bpf/btf.c                              | 33 +++++++
 kernel/bpf/verifier.c                         | 51 +++++++---
 .../testing/selftests/bpf/bpf_experimental.h  |  4 +
 .../selftests/bpf/prog_tests/kern_path.c      | 82 ++++++++++++++++
 .../selftests/bpf/progs/test_kern_path.c      | 56 +++++++++++
 .../selftests/bpf/progs/verifier_kern_path.c  | 52 ++++++++++
 .../bpf/progs/verifier_kern_path_fail.c       | 97 +++++++++++++++++++
 9 files changed, 422 insertions(+), 12 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/kern_path.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_kern_path.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_kern_path.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_kern_path_fail.c

--
2.47.3