linux/security/selinux/include
Eric Suen 5473a722f7 selinux: add support for BPF token access control
BPF token support was introduced to allow a privileged process to delegate
limited BPF functionality—such as map creation and program loading—to
an unprivileged process:
  https://lore.kernel.org/linux-security-module/20231130185229.2688956-1-andrii@kernel.org/

This patch adds SELinux support for controlling BPF token access. With
this change, SELinux policies can now enforce constraints on BPF token
usage based on both the delegating (privileged) process and the recipient
(unprivileged) process.

Supported operations currently include:
  - map_create
  - prog_load

High-level workflow:
  1. An unprivileged process creates a VFS context via `fsopen()` and
     obtains a file descriptor.
  2. This descriptor is passed to a privileged process, which configures
     BPF token delegation options and mounts a BPF filesystem.
  3. SELinux records the `creator_sid` of the privileged process during
     mount setup.
  4. The unprivileged process then uses this BPF fs mount to create a
     token and attach it to subsequent BPF syscalls.
  5. During verification of `map_create` and `prog_load`, SELinux uses
     `creator_sid` and the current SID to check policy permissions via:
       avc_has_perm(creator_sid, current_sid, SECCLASS_BPF,
                    BPF__MAP_CREATE, NULL);

The implementation introduces two new permissions:
  - map_create_as
  - prog_load_as

At token creation time, SELinux verifies that the current process has the
appropriate `*_as` permission (depending on the `allowed_cmds` value in
the bpf_token) to act on behalf of the `creator_sid`.

Example SELinux policy:
  allow test_bpf_t self:bpf {
      map_create map_read map_write prog_load prog_run
      map_create_as prog_load_as
  };

Additionally, a new policy capability bpf_token_perms is added to ensure
backward compatibility. If disabled, previous behavior ((checks based on
current process SID)) is preserved.

Signed-off-by: Eric Suen <ericsu@linux.microsoft.com>
Tested-by: Daniel Durning <danieldurning.work@gmail.com>
Reviewed-by: Daniel Durning <danieldurning.work@gmail.com>
[PM: merge fuzz, subject tweaks, whitespace tweaks, line length tweaks]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2026-01-13 15:42:37 -05:00
..
audit.h selinux: move initcalls to the LSM framework 2025-10-22 19:24:28 -04:00
avc.h selinux: introduce neveraudit types 2025-06-19 17:23:04 -04:00
avc_ss.h selinux: fix style issues in security/selinux/include/avc_ss.h 2023-12-22 18:09:26 -05:00
classmap.h selinux: add support for BPF token access control 2026-01-13 15:42:37 -05:00
conditional.h selinux: constify and reconcile function parameter names 2025-01-07 23:14:38 -05:00
hash.h selinux: improve bucket distribution uniformity of avc_hash() 2025-10-23 18:24:30 -04:00
ibpkey.h selinux: make header files self-including 2023-05-18 14:12:43 -04:00
ima.h selinux: fix style issues in security/selinux/include/ima.h 2023-12-22 18:09:28 -05:00
initcalls.h selinux: move initcalls to the LSM framework 2025-10-22 19:24:28 -04:00
initial_sid_to_string.h selinux: do not include <linux/*.h> headers from host programs 2024-10-03 15:34:24 -04:00
netif.h selinux: fix style issues in security/selinux/include/netif.h 2023-12-22 18:09:28 -05:00
netlabel.h selinux: fix style issues with security/selinux/include/netlabel.h 2023-12-22 18:09:28 -05:00
netnode.h selinux: constify network address pointer 2025-04-11 16:29:50 -04:00
netport.h selinux: include necessary headers in headers 2022-05-03 14:11:13 -04:00
objsec.h selinux: add support for BPF token access control 2026-01-13 15:42:37 -05:00
policycap.h selinux: add support for BPF token access control 2026-01-13 15:42:37 -05:00
policycap_names.h selinux: add support for BPF token access control 2026-01-13 15:42:37 -05:00
security.h selinux: add support for BPF token access control 2026-01-13 15:42:37 -05:00
xfrm.h selinux: fix style issues in security/selinux/include/xfrm.h 2023-12-22 18:09:30 -05:00