bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v6 Latest4 patches 34 repliesIn review
- v53 patches 15 repliesSuperseded
- v43 patches 8 repliesSuperseded
Earlier versions · 3
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v3 | 2 patches | 14 replies | Superseded | |
| v2 | 2 patches | 10 replies | Superseded | |
| v1 | 2 patches | 13 replies | Superseded |
Changes in v6 from the cover letter
- split struct lsm_xattrs / security_lsmxattr_add() into 2 patches
Patches in v6 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | security: introduce struct lsm_xattrsinclude/ include/ include/ +5 more | +50 | 0 replies | |
| 2/4 | security: add security_lsmxattr_add()include/ include/ security/ +1 more | +110 | 1 reply | |
| 3/4 | bpf: add bpf_init_inode_xattr kfunc for atomic inode labelingfs/ | +41 | 33 replies | |
| 4/4 | selftests/bpf: add tests for bpf_init_inode_xattr kfunctools/ tools/ tools/ | +194 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v6 yet.
Cover letter [PATCH v6 bpf-next 0/4] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling
Many in-kernel LSMs (SELinux, Smack, IMA) store security labels in extended attributes. For these LSMs, atomic labeling during inode creation is critical: if the inode becomes accessible before its xattr is set, it is briefly unlabeled, which can disrupt LSMs making policy decisions based on file labels.
Existing LSMs solve this by setting xattrs directly in the inode_init_security hook, which runs before the inode becomes accessible. BPF LSM programs currently lack this capability because the hook uses an output parameter (xattr_count) that BPF programs cannot write to, and existing kfuncs like bpf_set_dentry_xattr require a dentry that isn't available until after the inode is accessible.
This series introduces the bpf_init_inode_xattr() kfunc, which takes the combined inode_init_security xattr context argument and claims a slot in it via the new security_lsmxattr_add() LSM helper.
v6:
- split struct lsm_xattrs / security_lsmxattr_add() into 2 patches
(Paul)
- drop the CONFIG_BPF_LSM bracketing in security_lsmxattr_add() (Paul)
- have security_lsmxattr_add() take only extra name components (Paul)
- return 0 from security_lsmxattr_add() when the filesystem does not provide an initxattrs callback (Paul)
- selftests: label files in /dev/shm and skip when the hook does not run or the filesystem does not support xattrs at inode creation, fixing BPF CI failures on the 9p rootfs
v5:
- make the kfunc non-sleepable to avoid an ext4 deadlock (sashiko)
- move xattr creation logic to security_lsmxattr_add() (Paul)
- use distinct xattr names in init_inode_xattr_slot_limit
v4:
- introduce struct lsm_xattrs in separate patch (Alexei, Paul)
- rename struct xattr_ctx to struct lsm_xattrs (Paul)
- make lsm_xattrs.xattr_count unsigned int (Paul)
- drop new_xattrs/xattr_count locals in security_inode_init_security() (Paul)
- fold __bpf_init_inode_xattr() into bpf_init_inode_xattr() (Paul)
- drop bpf_fs_kfuncs_filter() attach-point check; rely on verifier type enforcement (Alexei)
- drop attach-time cap; enforce slot budget in the kfunc (Alexei)
- allocate the combined xattr with GFP_NOFS (sashiko-bot)
- replace init_inode_xattr_attach_cap selftest with runtime init_inode_xattr_slot_limit
v3:
- rename struct lsm_xattr_ctx to struct xattr_ctx (Paul)
- increase BPF_LSM_INODE_INIT_XATTRS to 4 (Song)
- enforce per-hook attachment cap at attach time to prevent runtime rejection (Paul)
- add init_inode_xattr_attach_cap selftest
v2:
- pass the xattr state as a combined context object and drop the verifier fixup path (Kumar)
- restrict bpf_init_inode_xattr labels to bpf.* namespace (Matt)
- cap bpf_init_inode_xattr() at BPF_LSM_INODE_INIT_XATTRS slots per invocation (AI)
v5: https://lore.kernel.org/bpf/[email protected]/
David Windsor (4):
security: introduce struct lsm_xattrs
security: add security_lsmxattr_add()
bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling selftests/bpf: add tests for bpf_init_inode_xattr kfunc
fs/bpf_fs_kfuncs.c | 41 +++++ include/linux/bpf_lsm.h | 3 + include/linux/evm.h | 9 +- include/linux/lsm_hook_defs.h | 4 +- include/linux/lsm_hooks.h | 16 +- include/linux/security.h | 15 ++ security/bpf/hooks.c | 1 + security/integrity/evm/evm_main.c | 8 +- security/security.c | 120 ++++++++++++-- security/selinux/hooks.c | 4 +- security/smack/smack_lsm.c | 27 ++- tools/testing/selftests/bpf/bpf_kfuncs.h | 5 + .../selftests/bpf/prog_tests/fs_kfuncs.c | 156 ++++++++++++++++++ .../bpf/progs/test_init_inode_xattr.c | 33 ++++ 14 files changed, 395 insertions(+), 47 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/test_init_inode_xattr.c
base-commit: 2659f94ed3be147942acbea96405efc562afb34c
Signature · 1 line
2.53.0