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] KEYS: protect construct_key type dereference with key semaphore
Date: Sat, 21 Nov 2026 11:38:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-226983@kernel.org> (raw)
In-Reply-To: <20261121112853.2175119-1-tristmd@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KEYS: ineffective key->sem locking around request_key read in
construct_key()
--
commit ac4e3e194cb3618952a6681a5209a4099b22f9f6
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().
> 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 taking key->sem only while reading key->type->request_key actually
protect the actor(authkey, aux) call from module unload, or can a
concurrent type removal happen here at all?
Unlike 925c84e3cc21 ("KEYS: Protect the read method check against type
removal"), 51bcd09b9ffc ("KEYS: Protect the update method check against
type removal") and bab48a104447 ("KEYS: Protect the pkey method checks
against type removal"), which hold key->sem across the method execution,
construct_key() drops key->sem before calling actor(authkey, aux). If
unregister_key_type() could run concurrently, key_garbage_collector()
could take down_write(&key->sem) right after up_read(&key->sem), retype
the key to key_type_dead, and allow the module text to be freed before
actor(authkey, aux) runs.
More importantly, construct_key() is only reached via
request_key_and_link(struct key_type *type, ...), which already requires
the key type to stay registered across the entire call and accesses
type->match_preparse before construct_key() and type->match_free after
it without key->sem:
security/keys/request_key.c:request_key_and_link() {
...
key = construct_key_and_link(&ctx, callout_info, callout_len,
aux, dest_keyring, flags);
}
error_free:
if (type->match_free)
type->match_free(&ctx.match_data);
...
}
On the sys_request_key() syscall path, key_type_lookup() holds
key_types_sem for reading across request_key_and_link() until
key_type_put(), blocking unregister_key_type() before key_gc_keytype()
can start, while in-kernel callers pass struct key_type * directly and
must keep the type registered for the duration of the request.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121112853.2175119-1-tristmd@gmail.com?part=1
prev parent reply other threads:[~2026-11-21 11:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 11:28 [PATCH] KEYS: protect construct_key type dereference with key semaphore Tristan Madani
2026-11-21 11:38 ` 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-226983@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox