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 v2] KEYS: protect construct_key type dereference with key semaphore
Date: Sat, 21 Nov 2026 13:05:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-227038@kernel.org> (raw)
In-Reply-To: <20261121125039.2532663-1-tristmd@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KEYS: deadlock in construct_key() holding key->sem across
actor() call
--
commit 89caf57fd1a6b94038c074beb5c384911f131253
Author: Tristan Madani <tristan@talencesecurity.com>
KEYS: protect construct_key type dereference with key semaphore
This commit acquires key->sem for reading around the key->type->request_key
lookup and actor() invocation in construct_key().
> diff --git a/security/keys/request_key.c b/security/keys/request_key.c
> index fa2bb9f2f5381..afc9df61506b9 100644
> --- a/security/keys/request_key.c
> +++ b/security/keys/request_key.c
> @@ -241,10 +241,12 @@ 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;
>
> ret = actor(authkey, aux);
> + up_read(&key->sem);
>
> /* check that the actor called complete_request_key() prior to
> * returning an error */
[Severity: High]
Can holding key->sem across actor() deadlock against the /sbin/request-key
userspace helper?
For key types without a custom ->request_key method, actor() is
call_sbin_request_key(), which calls call_usermodehelper_keys(...,
UMH_WAIT_PROC) and blocks until the userspace helper exits. Standard
helpers (such as key.dns_resolver, nfsidmap, and cifs.upcall) invoke
keyctl(KEYCTL_SET_TIMEOUT) on the key under construction before exiting,
which keyctl_set_timeout() explicitly permits via KEY_LOOKUP_PARTIAL and
KEY_AUTHTOKEN_OVERRIDE:
Requesting task /sbin/request-key helper
--------------- ------------------------
construct_key()
down_read(&key->sem)
call_sbin_request_key()
call_usermodehelper_keys(..., UMH_WAIT_PROC)
keyctl_set_timeout()
key_set_timeout()
down_write(&key->sem) <-- blocks
up_read(&key->sem)
*** DEADLOCK ***
keyctl_setperm_key() and keyctl_chown_key() likewise look up keys under
construction with KEY_LOOKUP_PARTIAL and take down_write(&key->sem).
Also, taking key->sem in construct_key() does not protect in-kernel
request_key() callers against concurrent unregister_key_type(): the sole
caller request_key_and_link() requires struct key_type *type to remain
registered across the call and dereferences type without key->sem both
before construct_key() (type->match_preparse and key_alloc()) and after it
returns (type->match_free).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121125039.2532663-1-tristmd@gmail.com?part=1
prev parent reply other threads:[~2026-11-21 13:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 12:50 [PATCH v2] KEYS: protect construct_key type dereference with key semaphore Tristan Madani
2026-11-21 13:05 ` 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-227038@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