linux/security
Ryan Foster 24e9b431b5
security: Add KUnit tests for kuid_root_in_ns and vfsuid_root_in_currentns
Add comprehensive KUnit tests for the namespace-related capability
functions that Serge Hallyn refactored in commit 9891d2f79a
("Clarify the rootid_owns_currentns").

The tests verify:
- Basic functionality: UID 0 in init namespace, invalid vfsuid,
  non-zero UIDs
- Actual namespace traversal: Creating user namespaces with different
  UID mappings where uid 0 maps to different kuids (e.g., 1000, 2000,
  3000)
- Hierarchy traversal: Testing multiple nested namespaces to verify
  correct namespace hierarchy traversal

This addresses the feedback to "test the actual functionality" by
creating real user namespaces with different values for the
namespace's uid 0, rather than just basic input validation.

The test file is included at the end of commoncap.c when
CONFIG_SECURITY_COMMONCAP_KUNIT_TEST is enabled, following the
standard kernel pattern (e.g., scsi_lib.c, ext4/mballoc.c). This
allows tests to access static functions in the same compilation unit
without modifying production code based on test configuration.

The tests require CONFIG_USER_NS to be enabled since they rely on user
namespace mapping functionality. The Kconfig dependency ensures the
tests only build when this requirement is met.

All 7 tests pass:
- test_vfsuid_root_in_currentns_init_ns
- test_vfsuid_root_in_currentns_invalid
- test_vfsuid_root_in_currentns_nonzero
- test_kuid_root_in_ns_init_ns_uid0
- test_kuid_root_in_ns_init_ns_nonzero
- test_kuid_root_in_ns_with_mapping
- test_kuid_root_in_ns_with_different_mappings

Updated MAINTAINER capabilities to include commoncap test

Signed-off-by: Ryan Foster <foster.ryan.r@gmail.com>
Signed-off-by: Serge Hallyn <sergeh@kernel.org>
2026-01-09 11:28:28 -06: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 update for v6.19-rc1 2025-12-06 09:52:41 -08: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 security: Add KUnit tests for kuid_root_in_ns and vfsuid_root_in_currentns 2026-01-09 11:28:28 -06:00
commoncap_test.c security: Add KUnit tests for kuid_root_in_ns and vfsuid_root_in_currentns 2026-01-09 11:28:28 -06: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 security: Add KUnit tests for kuid_root_in_ns and vfsuid_root_in_currentns 2026-01-09 11:28:28 -06: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