From: Shaomin Chen <eeesssooo020@gmail.com>
To: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: David Howells <dhowells@redhat.com>,
Jarkko Sakkinen <jarkko@kernel.org>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>
Subject: [bug report] keys: request_key_auth payload use-after-free in keyctl_instantiate_key_common()
Date: Tue, 19 May 2026 22:44:03 +0800 [thread overview]
Message-ID: <20260519144403.436694-1-eeesssooo020@gmail.com> (raw)
Hi,
keyctl_instantiate_key_common() can use a stale request_key_auth payload after
the current request-key authorisation key has been revoked.
The relevant code pattern is:
rka = instkey->payload.data[0];
...
copy_from_iter_full(payload, plen, from); /* can fault and sleep */
...
get_instantiation_keyring(ringid, rka, &dest_keyring);
key_instantiate_and_link(rka->target_key, payload, plen,
dest_keyring, instkey);
keyctl_instantiate_key_common() does not hold authkey->sem, an RCU read-side
critical section, or a reference to the request_key_auth payload across the
sleeping copy and later rka dereferences.
One race sequence is:
Task A: request-key helper child Task B: original request_key path
------------------------------- ---------------------------------
assume request-key authority
enter KEYCTL_INSTANTIATE_IOV
rka = instkey->payload.data[0]
block in copy_from_iter_full()
helper parent instantiates target key
helper returns to kernel
complete_request_key(authkey, 0)
key_revoke(authkey)
request_key_auth_revoke(authkey)
rcu_assign_keypointer(authkey, NULL)
call_rcu(&rka->rcu, ...)
request_key_auth_rcu_disposal()
free_request_key_auth(rka)
resume from copy_from_iter_full()
get_instantiation_keyring(..., rka, ...)
key_instantiate_and_link(rka->target_key, ...)
I reproduced this on a current upstream v7.1-rc3 based tree,
HEAD ab5fce87a778c, with KASAN enabled:
BUG: KASAN: slab-use-after-free in keyctl_instantiate_key_common+0x1dc/0x2a0
Read of size 8
Allocated by task:
request_key_auth_new+0xe0/0x4d0
Freed by task:
key_revoke+0x62/0xc0
call_sbin_request_key+0x6cb/0x740
The reproducer uses a request-key helper that forks a second process with the
request-key authority. The second process enters KEYCTL_INSTANTIATE_IOV and
blocks in copy_from_iter_full() on a user fault after rka has been loaded. The
original helper then instantiates the target key and returns, which revokes the
auth key and queues the request_key_auth payload for RCU freeing. When the
blocked instantiate path resumes, it dereferences the stale rka pointer.
I can provide the reproducer and a candidate patch.
Regards,
Shaomin Chen
reply other threads:[~2026-05-19 14:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260519144403.436694-1-eeesssooo020@gmail.com \
--to=eeesssooo020@gmail.com \
--cc=dhowells@redhat.com \
--cc=jarkko@kernel.org \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--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