Skip to content

Change skb secmarks to x-array indexes

Casey Schaufler linux-security-module lkml netfilter-devel selinux 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest7 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7net, smack: Create a function to set secmarksinclude/linux/lsm_secxa.h net/netfilter/nft_meta.c net/netfilter/xt_CONNSECMARK.c +2 more+31 -50 replies
2/7LSM: Implement x array functions for secmarksinclude/linux/lsm_secxa.h security/Makefile security/lsm_secxa.c+113 -50 replies
3/7LSM: Two hooks for manipulating struct lsm_propinclude/linux/lsm_hook_defs.h include/linux/security.h security/security.c+53 -00 replies
4/7SELinux: hooks for secctx_to_lsmprop and update_lsmpropsecurity/selinux/hooks.c+18 -00 replies
5/7Smack: hooks for secctx_to_lsmprop and update_lsmpropsecurity/smack/smack_lsm.c+36 -00 replies
6/7Apparmor: hooks for secctx_to_lsmprop and update_lsmpropsecurity/apparmor/include/secid.h security/apparmor/lsm.c security/apparmor/secid.c+29 -00 replies
7/7net, lsm: Change skb secmarks to x-array indexesinclude/linux/lsm_hook_defs.h include/linux/security.h net/netfilter/nfnetlink_queue.c +8 more+127 -350 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/7] Change skb secmarks to x-array indexes

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
Signature · 1 line
2.54.0