From: sashiko-bot@kernel.org
To: "Yuansheng Yang" <0xbeac@gmail.com>,
"Jarkko Sakkinen" <jarkko@kernel.org>
Cc: "David Howells" <dhowells@redhat.com>,
"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
Subject: Re: [PATCH v5] KEYS: Protect pkey method checks against type removal
Date: Sun, 08 Nov 2026 13:32:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-203780@kernel.org> (raw)
In-Reply-To: <20261108131417.77287-1-0xbeac@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KEYS: unlocked key->type dereferences in keyctl_pkey method
checks
--
commit 0ed416869e71a7b6cc7a35c0985435f3666b373b
Author: Yuansheng Yang <0xbeac@gmail.com>
KEYS: Protect pkey method checks against type removal
This commit takes key->sem for reading around the four asymmetric key
method calls in security/keys/keyctl_pkey.c and re-checks the method
pointer under the lock to prevent races with key type unregistration.
> diff --git a/security/keys/keyctl_pkey.c b/security/keys/keyctl_pkey.c
> index 15b6bf6399b59..0ea6f2790e9de 100644
> --- a/security/keys/keyctl_pkey.c
> +++ b/security/keys/keyctl_pkey.c
[ ... ]
> @@ -305,31 +332,41 @@ long keyctl_pkey_verify(const struct keyctl_pkey_params __user *_params,
> ret = keyctl_pkey_params_get_2(_params, _info, KEYCTL_PKEY_VERIFY,
> ¶ms);
> if (ret < 0)
> - goto error_params;
> + goto out_free_params;
>
> ret = -EOPNOTSUPP;
> if (!params.key->type->asym_verify_signature)
> - goto error_params;
> + goto out_free_params;
[Severity: Medium]
Can the remaining unlocked checks of key->type still fault on freed module
memory when a key type module is unloaded?
Checking key->type->asym_verify_signature here (and the corresponding
unlocked checks of key->type->asym_eds_op in keyctl_pkey_e_d_s() and
key->type->asym_query in keyctl_pkey_params_get()) reads key->type and
then dereferences the struct key_type in module memory without holding
key->sem:
CPU0 CPU1
keyctl_pkey_verify()
reg = params.key->type
unregister_key_type()
...
down_write(&key->sem)
key->type = &key_type_dead
up_write(&key->sem)
free_module()
if (!reg->asym_verify_signature) <-- use-after-free
security/keys/keyctl_pkey.c:keyctl_pkey_params_get() {
...
key_ref = lookup_user_key(id, 0, KEY_NEED_SEARCH);
if (IS_ERR(key_ref))
return PTR_ERR(key_ref);
params->key = key_ref_to_ptr(key_ref);
if (!params->key->type->asym_query)
return -EOPNOTSUPP;
return 0;
}
Both callers of keyctl_pkey_params_get() immediately take key->sem and
re-check asym_query before doing anything else, so the unlocked check in
keyctl_pkey_params_get() can be dropped, and the early asym_eds_op and
asym_verify_signature checks can be performed under key->sem inside
keyctl_pkey_params_get_2() while still returning -EOPNOTSUPP before
memdup_user().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261108131417.77287-1-0xbeac@gmail.com?part=1
next prev parent reply other threads:[~2026-11-08 13:32 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 3:29 [PATCH] KEYS: Protect pkey method checks against type removal BeaCox
2026-11-03 3:39 ` sashiko-bot
2026-11-03 15:17 ` Jarkko Sakkinen
2026-11-04 2:14 ` [PATCH v2] " BeaCox
2026-11-04 2:25 ` sashiko-bot
2026-11-04 14:49 ` Jarkko Sakkinen
2026-11-04 23:59 ` Jarkko Sakkinen
2026-11-05 2:24 ` Yuansheng Yang
2026-11-05 3:28 ` Jarkko Sakkinen
2026-11-05 4:38 ` [PATCH v3] " Yuansheng Yang
2026-11-05 4:48 ` sashiko-bot
2026-11-05 16:55 ` Jarkko Sakkinen
2026-11-05 19:36 ` [PATCH v4] " Yuansheng Yang
2026-11-05 19:48 ` sashiko-bot
2026-11-06 14:08 ` Jarkko Sakkinen
2026-11-08 12:59 ` Yuansheng Yang
2026-11-08 13:14 ` [PATCH v5] " Yuansheng Yang
2026-11-08 13:32 ` sashiko-bot [this message]
2026-11-08 15:45 ` Jarkko Sakkinen
2026-11-09 5:52 ` [PATCH v6] " Yuansheng Yang
2026-11-09 6:02 ` sashiko-bot
2026-11-09 15:04 ` Jarkko Sakkinen
2026-11-09 15:06 ` Jarkko Sakkinen
2026-11-10 1:49 ` Jarkko Sakkinen
2026-11-10 3:02 ` Yuansheng Yang
2026-11-10 3:02 ` [PATCH v7] " Yuansheng Yang
2026-11-10 3:06 ` Jarkko Sakkinen
2026-11-10 3:13 ` sashiko-bot
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-203780@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=0xbeac@gmail.com \
--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 \
/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