netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 00/42] SELinux namespace support
@ 2025-06-20 17:44 Stephen Smalley
  2025-06-20 17:44 ` [PATCH v6 01/42] selinux: restore passing of selinux_state Stephen Smalley
                   ` (41 more replies)
  0 siblings, 42 replies; 43+ messages in thread
From: Stephen Smalley @ 2025-06-20 17:44 UTC (permalink / raw)
  To: selinux; +Cc: paul, omosnace, netdev, horms, Stephen Smalley

This series introduces support for SELinux namespaces, i.e. the ability to
create multiple SELinux namespaces each with its own policy, AVC, and
enforcing mode. This support can be leveraged by Linux container runtimes
to establish a private SELinux namespace for each container, enabling the
container to load and enforce its own policy while still remaining bound by
the host OS policy (if any). Documentation and open issues can be found at
https://github.com/stephensmalley/selinuxns.

Performance data:

Baseline = v6.16-rc1
No NS = v6.16-rc1+this patch series with SECURITY_SELINUX_NS=n
Init NS = Same but with SECURITY_SELINUX_NS=y from init SELinux namespace
Child NS = Same but from a child SELinux namespace

kcbench (automated kernel compilation benchmark packaged by Fedora,
run with 'kcbench -s 6.13' for 10 runs, computing average and standard
deviation):
|CPUs|Baseline (sec)|StdDev|No NS (sec)|Init NS (sec)|Child NS (sec)|
| 16 | 123.88       | 0.24 | 121.85    | 121.67      | 121.93       |
| 19 | 125.33       | 0.43 | 123.06    | 123.03      | 122.73       |

'perf record make –jN' on a fully built allmodconfig kernel tree,
followed by 'perf report --sort=symbol,dso' yields the following
percentages (only showing __d_lookup_rcu for reference and only
showing relevant SELinux functions):
|Function                  |Baseline|NoNS  |InitNS|ChildNS|
| __d_lookup_rcu           | 1.74%  | 1.72%| 1.72%| 1.82% |
| selinux_inode_permission | 0.71%  | 0.55%| 0.58%| 0.56% |
| selinux_inode_getattr    | 0.40%  | 0.41%| 0.42%| 0.42% |
| avc_lookup               | 0.14%  | 0.07%| 0.11%| 0.21% |
| avc_has_perm/_noaudit (*)| 0.08%  | 0.05%| 0.05%| 0.09% |
| avc_policy_seqno         | 0.02%  | 0.17%| 0.16%| 0.16% |
| cred_tsid_has_perm       | N/A    | 0.07%| 0.07%| 0.10% |
| Total SELinux            | 1.35%  | 1.32%| 1.39%| 1.54% |
| SELinux/d_lookup_rcu     | 0.776  | 0.767| 0.808| 0.846 |
(*) Sum of avc_has_perm + avc_has_perm_noaudit percentages.

NB perf record was done _without_ the separate
neveraudit|permissive types optimization [1], which would
significantly reduce the SELinux percentages for such types
both with and without the SELinux namespace patches.

ApacheBench (run with 'ab –n 100000 –c 1000 http://localhost/' for
ten runs, computing average and stddev):
|Metric                  |Baseline|Std Dev|No NS  |Init NS |Child NS|
|Time taken (sec)        |  6.8071| 0.6764| 7.0198|  7.1344|  7.8451|
|Reqs / sec              | 14823.1| 1339.6|14353.2| 14163.3| 12858.4|
|Time per req (ms)       | 68.0721| 6.7646|70.1978| 71.3438| 78.4525|
|Transfer rate (KB/sec)  |  126691|  11499| 122675|  121052|  109899|
|Connect time median (ms)|    27.8|    4.3|     27|    25.8|    30.5|
|Total time median (ms)  |    62.6|    9.3|   67.6|    68.0|    77.0|

[1] https://lore.kernel.org/selinux/20250521144123.199370-4-stephen.smalley.work@gmail.com/

v6 re-bases on latest selinux/dev, fixing a conflict with the recently
merged neveraudit types support. I have not re-run the performance
benchmarks again from the prior version but could do so if required.

Stephen Smalley (42):
  selinux: restore passing of selinux_state
  selinux: introduce current_selinux_state
  selinux: support multiple selinuxfs instances
  selinux: dynamically allocate selinux namespace
  netstate,selinux: create the selinux netlink socket per network
    namespace
  selinux: limit selinux netlink notifications to init namespace
  selinux: support per-task/cred selinux namespace
  selinux: introduce cred_selinux_state() and use it
  selinux: init inode from nearest initialized namespace
  selinux: add a selinuxfs interface to unshare selinux namespace
  selinux: add limits for SELinux namespaces
  selinux: exempt creation of init SELinux namespace from limits
  selinux: refactor selinux_state_create()
  selinux: allow userspace to detect non-init SELinux namespace
  selinuxfs: restrict write operations to the same selinux namespace
  selinux: introduce a global SID table
  selinux: wrap security server interfaces to use the global SID table
  selinux: introduce a Kconfig option for SELinux namespaces
  selinux: eliminate global SID table if !CONFIG_SECURITY_SELINUX_NS
  selinux: maintain a small cache in the global SID table
  selinux: update hook functions to use correct selinux namespace
  selinux: introduce cred_task_has_perm()
  selinux: introduce cred_has_extended_perms()
  selinux: introduce cred_self_has_perm()
  selinux: introduce cred_has_perm()
  selinux: introduce cred_ssid_has_perm() and cred_other_has_perm()
  selinux: introduce task_obj_has_perm()
  selinux: update bprm hooks for selinux namespaces
  selinux: add kerneldoc to new permission checking functions
  selinux: convert selinux_file_send_sigiotask() to namespace-aware
    helper
  selinux: rename cred_has_perm*() to cred_tsid_has_perm*()
  selinux: update cred_tsid_has_perm_noaudit() to return the combined
    avd
  selinux: convert additional checks to cred_ssid_has_perm()
  selinux: introduce selinux_state_has_perm()
  selinux: annotate selinuxfs permission checks
  selinux: annotate process transition permission checks
  selinux: convert xfrm and netlabel permission checks
  selinux: switch selinux_lsm_setattr() checks to current namespace
  selinux: make open_perms namespace-aware
  selinux: split cred_ssid_has_perm() into two cases
  selinux: convert nlmsg_sock_has_extended_perms() to namespace-aware
  selinux: disallow writes to /sys/fs/selinux/user in non-init
    namespaces

 include/net/net_namespace.h                   |    3 +
 security/selinux/Kconfig                      |   65 +
 security/selinux/Makefile                     |    1 +
 security/selinux/avc.c                        |  783 ++++++++--
 security/selinux/global_sidtab.c              |  810 ++++++++++
 security/selinux/hooks.c                      | 1339 +++++++++++------
 security/selinux/ibpkey.c                     |    2 +-
 security/selinux/ima.c                        |   37 +-
 security/selinux/include/audit.h              |    8 +
 security/selinux/include/avc.h                |   76 +-
 security/selinux/include/avc_ss.h             |    3 +-
 security/selinux/{ss => include}/avtab.h      |    0
 security/selinux/include/classmap.h           |    2 +-
 security/selinux/include/conditional.h        |    4 +-
 security/selinux/{ss => include}/constraint.h |    0
 security/selinux/{ss => include}/context.h    |    0
 security/selinux/{ss => include}/ebitmap.h    |    0
 security/selinux/include/global_sidtab.h      |   26 +
 security/selinux/{ss => include}/hashtab.h    |    0
 security/selinux/include/ima.h                |   11 +-
 security/selinux/{ss => include}/mls.h        |    0
 security/selinux/{ss => include}/mls_types.h  |    0
 security/selinux/include/netif.h              |    4 +-
 security/selinux/include/netlabel.h           |   14 +-
 security/selinux/include/netnode.h            |    4 +-
 security/selinux/include/objsec.h             |   46 +-
 security/selinux/{ss => include}/policydb.h   |    0
 security/selinux/include/security.h           |  475 +++++-
 security/selinux/include/selinux_ss.h         |  119 ++
 security/selinux/{ss => include}/sidtab.h     |   34 +
 security/selinux/{ss => include}/symtab.h     |    0
 security/selinux/include/xfrm.h               |    8 +-
 security/selinux/netif.c                      |   31 +-
 security/selinux/netlabel.c                   |   32 +-
 security/selinux/netlink.c                    |   42 +-
 security/selinux/netnode.c                    |   26 +-
 security/selinux/netport.c                    |    2 +-
 security/selinux/selinuxfs.c                  |  553 ++++++-
 security/selinux/ss/services.c                |  458 +++---
 security/selinux/ss/services.h                |    1 +
 security/selinux/ss/sidtab.c                  |  105 +-
 security/selinux/status.c                     |   44 +-
 security/selinux/xfrm.c                       |   47 +-
 43 files changed, 4080 insertions(+), 1135 deletions(-)
 create mode 100644 security/selinux/global_sidtab.c
 rename security/selinux/{ss => include}/avtab.h (100%)
 rename security/selinux/{ss => include}/constraint.h (100%)
 rename security/selinux/{ss => include}/context.h (100%)
 rename security/selinux/{ss => include}/ebitmap.h (100%)
 create mode 100644 security/selinux/include/global_sidtab.h
 rename security/selinux/{ss => include}/hashtab.h (100%)
 rename security/selinux/{ss => include}/mls.h (100%)
 rename security/selinux/{ss => include}/mls_types.h (100%)
 rename security/selinux/{ss => include}/policydb.h (100%)
 create mode 100644 security/selinux/include/selinux_ss.h
 rename security/selinux/{ss => include}/sidtab.h (81%)
 rename security/selinux/{ss => include}/symtab.h (100%)

-- 
2.49.0


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

end of thread, other threads:[~2025-06-20 17:45 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 17:44 [PATCH v6 00/42] SELinux namespace support Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 01/42] selinux: restore passing of selinux_state Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 02/42] selinux: introduce current_selinux_state Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 03/42] selinux: support multiple selinuxfs instances Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 04/42] selinux: dynamically allocate selinux namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 05/42] netstate,selinux: create the selinux netlink socket per network namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 06/42] selinux: limit selinux netlink notifications to init namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 07/42] selinux: support per-task/cred selinux namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 08/42] selinux: introduce cred_selinux_state() and use it Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 09/42] selinux: init inode from nearest initialized namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 10/42] selinux: add a selinuxfs interface to unshare selinux namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 11/42] selinux: add limits for SELinux namespaces Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 12/42] selinux: exempt creation of init SELinux namespace from limits Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 13/42] selinux: refactor selinux_state_create() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 14/42] selinux: allow userspace to detect non-init SELinux namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 15/42] selinuxfs: restrict write operations to the same selinux namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 16/42] selinux: introduce a global SID table Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 17/42] selinux: wrap security server interfaces to use the " Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 18/42] selinux: introduce a Kconfig option for SELinux namespaces Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 19/42] selinux: eliminate global SID table if !CONFIG_SECURITY_SELINUX_NS Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 20/42] selinux: maintain a small cache in the global SID table Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 21/42] selinux: update hook functions to use correct selinux namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 22/42] selinux: introduce cred_task_has_perm() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 23/42] selinux: introduce cred_has_extended_perms() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 24/42] selinux: introduce cred_self_has_perm() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 25/42] selinux: introduce cred_has_perm() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 26/42] selinux: introduce cred_ssid_has_perm() and cred_other_has_perm() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 27/42] selinux: introduce task_obj_has_perm() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 28/42] selinux: update bprm hooks for selinux namespaces Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 29/42] selinux: add kerneldoc to new permission checking functions Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 30/42] selinux: convert selinux_file_send_sigiotask() to namespace-aware helper Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 31/42] selinux: rename cred_has_perm*() to cred_tsid_has_perm*() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 32/42] selinux: update cred_tsid_has_perm_noaudit() to return the combined avd Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 33/42] selinux: convert additional checks to cred_ssid_has_perm() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 34/42] selinux: introduce selinux_state_has_perm() Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 35/42] selinux: annotate selinuxfs permission checks Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 36/42] selinux: annotate process transition " Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 37/42] selinux: convert xfrm and netlabel " Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 38/42] selinux: switch selinux_lsm_setattr() checks to current namespace Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 39/42] selinux: make open_perms namespace-aware Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 40/42] selinux: split cred_ssid_has_perm() into two cases Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 41/42] selinux: convert nlmsg_sock_has_extended_perms() to namespace-aware Stephen Smalley
2025-06-20 17:44 ` [PATCH v6 42/42] selinux: disallow writes to /sys/fs/selinux/user in non-init namespaces Stephen Smalley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).