BPF List
 help / color / mirror / Atom feed
* [PATCH v2 0/2] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling
@ 2026-05-03 21:18 David Windsor
  2026-05-03 21:18 ` [PATCH v2 1/2] " David Windsor
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: David Windsor @ 2026-05-03 21:18 UTC (permalink / raw)
  Cc: bpf

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.

commit 6bcdfd2cac55 ("security: Allow all LSMs to provide xattrs
for inode_init_security hook") allows us to reserve an xattr slot
for BPF. Before this, the hook returned a single xattr owned by one
LSM, leaving nowhere for a BPF program to write without clobbering
an existing entry.

This series introduces the bpf_init_inode_xattr() kfunc, which takes
the combined inode_init_security xattr context argument to access
xattrs and xattr_count, and internally writes to xattr_count via
lsm_get_xattr_slot().

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)

David Windsor (2):
  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                            | 106 +++++++++++++++++-
 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                      |   5 +
 kernel/bpf/bpf_lsm.c                          |   1 +
 security/bpf/hooks.c                          |   1 +
 security/integrity/evm/evm_main.c             |   8 +-
 security/security.c                           |   7 +-
 security/selinux/hooks.c                      |   4 +-
 security/smack/smack_lsm.c                    |  13 +--
 tools/testing/selftests/bpf/bpf_kfuncs.h      |   5 +
 .../selftests/bpf/prog_tests/fs_kfuncs.c      |  49 ++++++++
 .../bpf/progs/test_init_inode_xattr.c         |  32 ++++++
 15 files changed, 233 insertions(+), 30 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/test_init_inode_xattr.c


base-commit: 2ca6723a5f7b68c739dba47b2639e3eaa7884b09
-- 
2.53.0


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

end of thread, other threads:[~2026-05-10 21:22 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-03 21:18 [PATCH v2 0/2] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling David Windsor
2026-05-03 21:18 ` [PATCH v2 1/2] " David Windsor
2026-05-03 21:59   ` sashiko-bot
2026-05-04 20:14   ` Paul Moore
2026-05-04 21:40     ` Song Liu
2026-05-04 22:42       ` Paul Moore
2026-05-04 23:09         ` Song Liu
2026-05-05  1:07           ` David Windsor
2026-05-05  2:02           ` Paul Moore
2026-05-05  2:05             ` Paul Moore
2026-05-05  9:00             ` Song Liu
2026-05-05 13:49               ` Paul Moore
2026-05-10 21:22   ` bot+bpf-ci
2026-05-03 21:18 ` [PATCH v2 2/2] selftests/bpf: add tests for bpf_init_inode_xattr kfunc David Windsor
2026-05-03 21:52   ` bot+bpf-ci
2026-05-03 22:12   ` sashiko-bot
2026-05-10 21:10   ` bot+bpf-ci
     [not found] ` <b6170cc360f0db18ceb0857f97dfaf84d129a6de55836fef2b0b604805cf5039@mail.kernel.org>
2026-05-03 22:16   ` [PATCH v2 0/2] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling David Windsor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox