linux/security/keys
성병찬 dd3ea3fcba KEYS: Fix add_key() race with keyring restriction
__key_create_or_update() snapshots keyring->restrict_link before taking
the destination keyring's semaphore.  keyring_restrict() installs a
restriction while holding that semaphore.

This allows a writer to observe no restriction, wait for the keyring
owner to install a reject-all restriction and return successfully, and
then link a key using the stale NULL snapshot.  The writer only needs
write permission on the destination keyring.

Move the restrict_link read after __key_link_lock() and
__key_link_begin().  The read and the subsequent restriction check are
then serialized with restriction installation by keyring->sem.

The race was reproduced on v7.2.8 in 19 executions where restriction
installation returned before the link completed.  All 19 linked the key
despite the reject-all restriction.  With this change, 312 executions
reached the same ordering and every add_key() call failed with -EPERM.

The issue was found by manual concurrency analysis assisted by AI-based
analysis and independently verified with a QEMU reproducer and kernel
instrumentation.

Fixes: 5ac7eace2d ("KEYS: Add a facility to restrict new links into a keyring")
Cc: stable@vger.kernel.org
Signed-off-by: 성병찬 <tjdqudcks0424@naver.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20260930041802.6114-1-tjdqudcks0424@naver.com
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-04 21:09:32 +03:00
..
encrypted-keys KEYS: encrypted: fix integer overflow of datablob_len 2026-09-12 00:43:45 +03:00
trusted-keys KEYS: trusted: Fix tpm2_load_cmd() boundary check 2026-09-12 00:43:45 +03:00
big_key.c mm: update shmem_[kernel]_file_*() functions to use vma_flags_t 2026-02-12 15:42:58 -08:00
compat_dh.c
compat.c security/keys: remove compat_keyctl_instantiate_key_iov 2020-10-03 00:02:16 -04:00
dh.c KEYS: DH: Use crypto_wait_req 2023-02-13 18:34:48 +08:00
gc.c keys: fix lost wakeup when reaping a dead key type 2026-09-12 00:43:45 +03:00
internal.h keys: Pin request_key_auth payload in instantiate paths 2026-06-15 15:19:13 +03:00
Kconfig KEYS: encrypted: Remove unnecessary selection of CRYPTO_RNG 2026-06-15 15:19:12 +03:00
key.c KEYS: Fix add_key() race with keyring restriction 2026-10-04 21:09:32 +03:00
keyctl_pkey.c keys: keyctl_pkey: replace BUG with return -EOPNOTSUPP 2026-06-15 15:19:13 +03:00
keyctl.c keys: Pin request_key_auth payload in instantiate paths 2026-06-15 15:19:13 +03:00
keyring.c keys: make keyring key-chunk byte order agree with keyring_diff_objects() 2026-07-23 18:23:39 +03:00
Makefile
permission.c
persistent.c keys: finalize persistent keyring timeout after link attempt 2026-10-04 21:09:32 +03:00
proc.c keys, dns: Allow key types (eg. DNS) to be reclaimed immediately on expiry 2023-12-21 13:47:38 +00:00
process_keys.c cred: make init_cred static 2025-11-04 12:36:02 +01:00
request_key_auth.c keys: translate request_key_auth pid for the reading procfs instance 2026-09-12 00:43:45 +03:00
request_key.c keys: request_key: replace BUG with return -EINVAL 2026-06-15 15:19:13 +03:00
sysctl.c treewide: const qualify ctl_tables where applicable 2025-01-28 13:48:37 +01:00
user_defined.c keys: use kmalloc_flex in user_preparse 2026-06-15 15:19:12 +03:00