BPF List
 help / color / mirror / Atom feed
From: David Windsor <dwindsor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: [PATCH v2 0/2] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling
Date: Sun,  3 May 2026 17:18:29 -0400	[thread overview]
Message-ID: <20260503211835.16103-1-dwindsor@gmail.com> (raw)

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


             reply	other threads:[~2026-05-03 21:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-03 21:18 David Windsor [this message]
2026-05-03 21:18 ` [PATCH v2 1/2] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260503211835.16103-1-dwindsor@gmail.com \
    --to=dwindsor@gmail.com \
    --cc=bpf@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox