linux/security
Günther Noack 65b691f84d
landlock: Transpose the layer masks data structure
The layer masks data structure tracks the requested but unfulfilled
access rights during an operation's security check.  It stores one bit
for each combination of access right and layer index.  If the bit is
set, that access right is not granted (yet) in the given layer and we
have to traverse the path further upwards to grant it.

Previously, the layer masks were stored as arrays mapping from access
right indices to layer_mask_t.  The layer_mask_t value then indicates
all layers in which the given access right is still (tentatively)
denied.

This patch introduces struct layer_access_masks instead: This struct
contains an array with the access_mask_t of each (tentatively) denied
access right in that layer.

The hypothesis of this patch is that this simplifies the code enough
so that the resulting code will run faster:

* We can use bitwise operations in multiple places where we previously
  looped over bits individually with macros.  (Should require less
  branch speculation and lends itself to better loop unrolling.)

* Code is ~75 lines smaller.

Other noteworthy changes:

* In no_more_access(), call a new helper function may_refer(), which
  only solves the asymmetric case.  Previously, the code interleaved
  the checks for the two symmetric cases in RENAME_EXCHANGE.  It feels
  that the code is clearer when renames without RENAME_EXCHANGE are
  more obviously the normal case.

Tradeoffs:

This change improves performance, at a slight size increase to the
layer masks data structure.

This fixes the size of the data structure at 32 bytes for all types of
access rights. (64, once we introduce a 17th filesystem access right).

For filesystem access rights, at the moment, the data structure has
the same size as before, but once we introduce the 17th filesystem
access right, it will double in size (from 32 to 64 bytes), as
access_mask_t grows from 16 to 32 bit [1].

Link: https://lore.kernel.org/all/20260120.haeCh4li9Vae@digikod.net/ [1]
Signed-off-by: Günther Noack <gnoack3000@gmail.com>
Link: https://lore.kernel.org/r/20260206151154.97915-5-gnoack3000@gmail.com
[mic: Cosmetic fixes, moved struct layer_access_masks definition]
Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-02-10 16:46:50 +01:00
..
apparmor Some filesystems use a kinda-sorta controlled dentry refcount leak to pin 2025-12-05 14:36:21 -08:00
bpf lsm: replace the name field with a pointer to the lsm_id struct 2025-10-22 19:24:18 -04:00
integrity kernel/kexec: change the prototype of kimage_map_segment() 2025-12-23 11:23:13 -08:00
ipe ipe/stable-6.19 PR 20251202 2025-12-03 11:19:34 -08:00
keys tpm2-sessions: Open code tpm_buf_append_hmac_session() 2025-12-05 06:42:51 +02:00
landlock landlock: Transpose the layer masks data structure 2026-02-10 16:46:50 +01:00
loadpin loadpin: move initcalls to the LSM framework 2025-10-22 19:24:25 -04:00
lockdown lockdown: move initcalls to the LSM framework 2025-10-22 19:24:27 -04:00
safesetid safesetid: move initcalls to the LSM framework 2025-10-22 19:24:26 -04:00
selinux Some filesystems use a kinda-sorta controlled dentry refcount leak to pin 2025-12-05 14:36:21 -08:00
smack Some filesystems use a kinda-sorta controlled dentry refcount leak to pin 2025-12-05 14:36:21 -08:00
tomoyo Trivial optimization. 2025-12-14 15:21:02 +12:00
yama lsm: replace the name field with a pointer to the lsm_id struct 2025-10-22 19:24:18 -04:00
commoncap.c Capabilities patch for v6.19 2025-12-04 20:10:28 -08:00
device_cgroup.c device_cgroup: Refactor devcgroup_seq_show to use seq_put* helpers 2025-11-11 19:47:24 -05:00
inode.c Some filesystems use a kinda-sorta controlled dentry refcount leak to pin 2025-12-05 14:36:21 -08:00
Kconfig lsm: CONFIG_LSM can depend on CONFIG_SECURITY 2025-09-11 16:32:04 -04:00
Kconfig.hardening rust: add bitmap API. 2025-09-22 15:52:44 -04:00
lsm.h lsm: consolidate all of the LSM framework initcalls 2025-10-22 19:24:28 -04:00
lsm_audit.c net: Retire DCCP socket. 2025-04-11 18:58:10 -07:00
lsm_init.c lsm: use unrcu_pointer() for current->cred in security_init() 2025-11-19 10:32:06 -05:00
lsm_notifier.c lsm: split the notifier code out into lsm_notifier.c 2025-10-22 19:24:15 -04:00
lsm_syscalls.c lsm: rework lsm_active_cnt and lsm_idlist[] 2025-10-22 19:24:19 -04:00
Makefile lsm: split the init code out into lsm_init.c 2025-10-22 19:24:16 -04:00
min_addr.c lsm: consolidate all of the LSM framework initcalls 2025-10-22 19:24:28 -04:00
security.c lsm: cleanup the debug and console output in lsm_init.c 2025-10-22 19:24:23 -04:00