From: sashiko-bot@kernel.org
To: "Tristan Madani" <tristmd@gmail.com>,
"David Howells" <dhowells@redhat.com>,
"Jarkko Sakkinen" <jarkko@kernel.org>
Cc: "Paul Moore" <paul@paul-moore.com>,
"James Morris" <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
keyrings@vger.kernel.org, linux-security-module@vger.kernel.org,
"Tristan Madani" <tristan@talencesecurity.com>
Subject: Re: [PATCH v3] KEYS: protect construct_key type dereference with key semaphore
Date: Tue, 24 Nov 2026 21:49:18 +0000 [thread overview]
Message-ID: <sashiko-outbox-232064@kernel.org> (raw)
In-Reply-To: <20261124214125.3198541-1-tristmd@gmail.com>
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@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
prev parent reply other threads:[~2026-11-24 21:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 21:41 [PATCH v3] KEYS: protect construct_key type dereference with key semaphore Tristan Madani
2026-11-24 21:49 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-232064@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dhowells@redhat.com \
--cc=jarkko@kernel.org \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=serge@hallyn.com \
--cc=tristan@talencesecurity.com \
--cc=tristmd@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.