Skip to content

Enable writing xattr from BPF programs

Song Liu bpf linux-fsdevel linux-security-module lkml 12 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v12 Latest5 patches 2 repliesIn review
  2. v117 patches 8 repliesSuperseded
  3. v107 patches 1 replySuperseded
Earlier versions · 9
VersionPostedPatchesRepliesStatus
v97 patches3 repliesSuperseded
v87 patches4 repliesSuperseded
v77 patches0 repliesSuperseded
v67 patches1 replySuperseded
v55 patches5 repliesSuperseded
v46 patches5 repliesSuperseded
v36 patches5 repliesSuperseded
v22 patches0 repliesSuperseded
v12 patches22 repliesSuperseded

Changes in v12 from the cover letter

1. Drop btf_kfunc_id_set.remap and changes for bpf_dynptr_from_skb. (Alexei)
2. Minor refactoring in patch 1. (Matt Bobrowski)

Patches in v12 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5fs/xattr: bpf: Introduce security.bpf. xattr name prefixfs/bpf_fs_kfuncs.c include/uapi/linux/xattr.h+29 -110 replies
2/5selftests/bpf: Extend test fs_kfuncs to cover security.bpf. xattr namestools/testing/selftests/bpf/prog_tests/fs_kfuncs.c tools/testing/selftests/bpf/progs/test_get_xattr.c+51 -140 replies
3/5bpf: lsm: Add two more sleepable hookskernel/bpf/bpf_lsm.c+2 -01 reply
4/5bpf: fs/xattr: Add BPF kfuncs to set and remove xattrsfs/bpf_fs_kfuncs.c include/linux/bpf_lsm.h kernel/bpf/verifier.c+228 -01 reply
5/5selftests/bpf: Test kfuncs that set and remove xattr from BPF programstools/testing/selftests/bpf/bpf_kfuncs.h tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c tools/testing/selftests/bpf/progs/test_set_remove_xattr.c+263 -00 replies

Reviews trailers per patch

3 of 5 patches have a Reviewed-by or Acked-by.

PatchChristian BraunerJan KaraMatt Bobrowski
1/5A-b R-b R-b
2/5
3/5R-b
4/5A-b R-b
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v12 thread

Cover letter [PATCH v12 bpf-next 0/5] Enable writing xattr from BPF programs

Add support to set and remove xattr from BPF program. Also add security.bpf. xattr name prefix.

kfuncs are added to set and remove xattrs with security.bpf. name prefix. Update kfuncs bpf_get_[file|dentry]_xattr to read xattrs with security.bpf. name prefix. Note that BPF programs can read user. xattrs, but not write and remove them.

To pick the right version of kfunc to use, a remap logic is added to btf_kfunc_id_set. This helps move some kfunc specific logic off the verifier core code. Also use this remap logic to select bpf_dynptr_from_skb or bpf_dynptr_from_skb_rdonly.

Cover letter of v1 and v2:

Follow up discussion in LPC 2024 [1], that we need security.bpf xattr prefix. This set adds "security.bpf." xattr name prefix, and allows bpf kfuncs bpf_get_[file|dentry]_xattr() to read these xattrs.

[1] https://lpc.events/event/18/contributions/1940/

---

Changes v11 => v12:
1. Drop btf_kfunc_id_set.remap and changes for bpf_dynptr_from_skb. (Alexei)
2. Minor refactoring in patch 1. (Matt Bobrowski)

v11: https://lore.kernel.org/bpf/[email protected]/

Changes v10 => v11:

1. Add Acked-by from Christian Brauner.
2. Fix selftests build error like this one:
https://github.com/kernel-patches/bpf/actions/runs/13022268618/job/36325472992
3. Rename some variables in the selftests.

v10: https://lore.kernel.org/bpf/[email protected]/

Changes v9 => v10:
1. Refactor bpf_[set|remove]_dentry_xattr[_locked]. (Christian Brauner).

v9: https://lore.kernel.org/bpf/[email protected]/

Changes v8 => v9
1. Fix build for CONFIG_DEBUG_INFO_BTF=n case. (kernel test robot)

v8: https://lore.kernel.org/bpf/[email protected]/

Changes v7 => v8
1. Rebase and resolve conflicts.

v7: https://lore.kernel.org/bpf/[email protected]/

Changes v6 => v7
1. Move btf_kfunc_id_remap() to the right place. (Bug reported by CI)

v6: https://lore.kernel.org/bpf/[email protected]/

Changes v5 => v6
1. Hide _locked version of the kfuncs from vmlinux.h (Alexei)
2. Add remap logic to btf_kfunc_id_set and use that to pick the correct version of kfuncs to use.
3. Also use the remap logic for bpf_dynptr_from_skb[|_rdonly].

v5: https://lore.kernel.org/bpf/[email protected]/

Changes v4 => v5
1. Let verifier pick proper kfunc (_locked or not _locked) based on the calling context. (Alexei)
2. Remove the __failure test (6/6 of v4).

v4: https://lore.kernel.org/bpf/[email protected]/

Changes v3 => v4
1. Do write permission check with inode locked. (Jan Kara)
2. Fix some source_inline warnings.

v3: https://lore.kernel.org/bpf/[email protected]/

Changes v2 => v3
1. Add kfuncs to set and remove xattr from BPF programs.

v2: https://lore.kernel.org/bpf/[email protected]/

Changes v1 => v2
1. Update comment of bpf_get_[file|dentry]_xattr. (Jiri Olsa)
2. Fix comment for return value of bpf_get_[file|dentry]_xattr.

v1: https://lore.kernel.org/bpf/[email protected]/

Song Liu (5):
fs/xattr: bpf: Introduce security.bpf. xattr name prefix selftests/bpf: Extend test fs_kfuncs to cover security.bpf. xattr
names
bpf: lsm: Add two more sleepable hooks
bpf: fs/xattr: Add BPF kfuncs to set and remove xattrs selftests/bpf: Test kfuncs that set and remove xattr from BPF programs

 fs/bpf_fs_kfuncs.c                            | 225 +++++++++++++++++-
 include/linux/bpf_lsm.h                       |  18 ++
 include/uapi/linux/xattr.h                    |   4 +
 kernel/bpf/bpf_lsm.c                          |   2 +
 kernel/bpf/verifier.c                         |  21 ++
 tools/testing/selftests/bpf/bpf_kfuncs.h      |   5 +
 .../selftests/bpf/prog_tests/fs_kfuncs.c      | 162 ++++++++++++-
 .../selftests/bpf/progs/test_get_xattr.c      |  28 ++-
 .../bpf/progs/test_set_remove_xattr.c         | 133 +++++++++++
 9 files changed, 573 insertions(+), 25 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/test_set_remove_xattr.c

--
2.43.5