[PATCH v3] KEYS: protect construct_key type dereference with key semaphore
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Nov 24 21:49:18 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] keys: releasing key->sem before actor() in construct_key()
defeats protection
--
commit 9d2b5e770f320f3d569ad3450cb1b85673517461
Author: Tristan Madani <tristan at talencesecurity.com>
KEYS: protect construct_key type dereference with key semaphore
This commit takes key->sem for reading around the key->type->request_key
lookup in construct_key() and releases it before invoking actor().
> diff --git a/security/keys/request_key.c b/security/keys/request_key.c
> index fa2bb9f2f5381..7e9fe4796319c 100644
> --- a/security/keys/request_key.c
> +++ b/security/keys/request_key.c
> @@ -241,8 +241,10 @@ static int construct_key(struct key *key, const void *callout_info,
>
> /* Make the call */
> actor = call_sbin_request_key;
> + down_read(&key->sem);
> if (key->type->request_key)
> actor = key->type->request_key;
> + up_read(&key->sem);
>
> ret = actor(authkey, aux);
[Severity: Medium]
Does holding key->sem only across the key->type->request_key pointer load
provide the protection against concurrent type unregistration that the
commit message describes?
In commit 925c84e3cc21 ("keys: Protect the read method check against type
removal"), __keyctl_read_key() holds key->sem across key_validate(key), the
key->type->read check, and the key->type->read() call itself. Here,
up_read(&key->sem) runs before actor(authkey, aux), so if
key_garbage_collector() could race with construct_key(), it could acquire
down_write(&key->sem), retype the key to key_type_dead, and let
unregister_key_type() complete right after up_read(&key->sem) and before
actor() runs. And if the key were retyped to key_type_dead before
down_read(&key->sem), key_type_dead.request_key is NULL and KEY_FLAG_DEAD
is not checked, so construct_key() would fall back to
call_sbin_request_key on a dead key.
More broadly, construct_key() is only reached through
request_key_and_link(), whose callers already pin the key_type for the
entire operation (__do_sys_request_key() holds key_types_sem via
key_type_lookup(), and request_key_and_link() itself dereferences
type->match_preparse before and type->match_free after construct_key()
without key->sem).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124214125.3198541-1-tristmd@gmail.com?part=1
More information about the Linux-security-module-archive
mailing list