[PATCH 0/7] Change skb secmarks to x-array indexes
From: Casey Schaufler <casey@schaufler-ca.com>
Date: 2026-08-13 20:49:13
Also in:
lkml, netfilter-devel, selinux
When security secmarks were added to the Linux network stack there was only one Linux Security Module (LSM), SELinux. SELinux already used the concept of a security ID (secid) as the representation of the security information about a system subject (active entity) or object (passive entity). Adding a container for a secid, the secmark, to the sk_buff structure allowed for efficient transmission of the SELinux secid for socket based access controls. Subsequent LSMs have chosen to represent security information more directly. Smack and AppArmor use pointers to structures containing relevant information. Alas, these pointers do not fit in the u32 secmark on most modern architectures. These LSMs are required to provide a secid mapping to use secmarks. Even with all LSMs that use secmarks having a secid to reference the security information the mechanism is imperfect. A system that wants to use multiple LSMs that use secmarks is constrained by the size of the secmark. There is no rational way to fit multiple secids in a secmark. While it would be possible to allow one LSM to use the secmark and any others to be told it is unavailable, this has been deemed an unacceptable limitation. There is a lsm_prop structure available that contains security information for any LSM that maintains it. The secmark cannot, unfortunately, contain one. Instead, an x-array of lsm_prop structures is maintained, and the index (secxa) is used in the secmark instead of the single LSM restricted secid. Uses of security_secctx_to_secid() have been changed to security_secctx_to_lsmprop() in the netfilter and iptables code. The security_secmark_relabel_packet() function has been updated to accept an lsm_prop pointer rather than a secid. To support multiple LSMs using a secmark it is necessary to re-evaluate which lsm_prop structure represents the current security information at each step where the secmark can be set. Smack sets the secmark for every packet. Netfilter, used by SELinux, Smack and AppArmor, will set the secmark on selected packets at a later time. If Smack and AppArmor are active on a system Smack will set the secmark initially, and AppArmor may reset it by netfilter rule. https://github.com/cschaufler/lsm-stacking#secmark-xa-7.2-rc5-v1 Casey Schaufler (7): net, smack: Create a function to set secmarks LSM: Implement x array functions for secmarks LSM: Two hooks for manipulating struct lsm_prop SELinux: hooks for secctx_to_lsmprop and update_lsmprop Smack: hooks for secctx_to_lsmprop and update_lsmprop Apparmor: hooks for secctx_to_lsmprop and update_lsmprop net, lsm: Change skb secmarks to x-array indexes include/linux/lsm_hook_defs.h | 6 +- include/linux/lsm_secxa.h | 22 ++++++ include/linux/security.h | 21 +++++- net/netfilter/nfnetlink_queue.c | 12 ++- net/netfilter/nft_meta.c | 16 ++-- net/netfilter/xt_CONNSECMARK.c | 3 +- net/netfilter/xt_SECMARK.c | 15 ++-- security/Makefile | 1 + security/apparmor/include/secid.h | 4 + security/apparmor/lsm.c | 2 + security/apparmor/net.c | 8 +- security/apparmor/secid.c | 23 ++++++ security/lsm_secxa.c | 119 ++++++++++++++++++++++++++++++ security/security.c | 38 +++++++++- security/selinux/hooks.c | 89 +++++++++++++++++++--- security/smack/smack_lsm.c | 46 +++++++++++- security/smack/smack_netfilter.c | 9 ++- 17 files changed, 398 insertions(+), 36 deletions(-) create mode 100644 include/linux/lsm_secxa.h create mode 100644 security/lsm_secxa.c -- 2.54.0