From: Jarkko Sakkinen <jarkko@kernel.org>
To: Shaomin Chen <eeesssooo020@gmail.com>
Cc: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, David Howells <dhowells@redhat.com>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>
Subject: Re: [PATCH] keys: Pin request_key_auth payload in instantiate paths
Date: Wed, 10 Jun 2026 13:16:01 +0300 [thread overview]
Message-ID: <aik5YaJhjRuOKE7I@kernel.org> (raw)
In-Reply-To: <aiZWPSJZyFq4nmxf@kernel.org>
On Mon, Jun 08, 2026 at 08:42:21AM +0300, Jarkko Sakkinen wrote:
> On Mon, Jun 08, 2026 at 08:29:11AM +0300, Jarkko Sakkinen wrote:
> > On Mon, Jun 08, 2026 at 06:10:23AM +0300, Jarkko Sakkinen wrote:
> > > On Mon, Jun 08, 2026 at 06:06:21AM +0300, Jarkko Sakkinen wrote:
> > > > On Tue, May 26, 2026 at 10:48:38AM +0800, Shaomin Chen wrote:
> > > > > keyctl_instantiate_key_common() reads request_key_auth from the assumed
> > > > > auth key before copying an instantiation payload from userspace. The copy
> > > > > can fault and sleep. If the request completes and revokes the auth key in
> > > > > that window, the auth payload can be detached and freed before the
> > > > > instantiate path uses it again.
> > > > >
> > > > > A request-key helper reproducer can trigger this race. One helper child
> > > > > blocks in KEYCTL_INSTANTIATE_IOV while the original helper instantiates the
> > > > > requested key and returns. KASAN then reports a use-after-free from the
> > > > > stale request_key_auth payload in keyctl_instantiate_key_common().
> > > > >
> > > > > Give request_key_auth payloads a refcount. Take a payload reference while
> > > >
> > > > Please, name concrete things accurately. I.e. 'usage' in this case. If
> > > > you have a name, use it instead of obfuscating generalizations.
> > > >
> > > > > authkey->sem stabilizes the payload and revocation state. Hold that
> > > > > reference across the instantiate and reject paths. Drop the auth key
> > > > > owning reference from revoke and destroy.
> > > > >
> > > > > Reported-by: Shaomin Chen <eeesssooo020@gmail.com>
> > > > > Closes: https://lore.kernel.org/r/20260519144403.436694-1-eeesssooo020@gmail.com
> > > > > Signed-off-by: Shaomin Chen <eeesssooo020@gmail.com>
> > > > > ---
> > > > > include/keys/request_key_auth-type.h | 2 ++
> > > > > security/keys/internal.h | 2 ++
> > > > > security/keys/keyctl.c | 24 +++++++++++++++-----
> > > > > security/keys/request_key_auth.c | 33 ++++++++++++++++++++++++++--
> > > > > 4 files changed, 53 insertions(+), 8 deletions(-)
> > > >
> > > > So first, couple of things.
> > > >
> > > > I'm not going to test not that well documented involving OOT driver.
> > >
> > > Oops, sorry typo. "not that well documented reproducer" :-)
> > >
> > > But it is cool we just then need to draw the picture.
> >
> > I think I got this:
> >
> > A: request_key() B: KEYCTL_INSTANTIATE_IOV
> > ---------------- -------------------------
> > create auth key
> > store rka in auth key
> > wait for helper
> > get auth key
> > load rka from auth key
> > copy user payload
> > sleep on #PF
> > helper completed
> > detach and free rka
> > destroy auth key
> > wake up
> > use rka->target_key
> > **USE-AFTER-FREE**
> >
> > So nothing really complicated here, is there?
>
> Send v2 with the code changes that I proposed as we want to the change
> as ergonomic as possible.
>
> Use this as the commit message:
>
> keys: Pin request_key_auth payload in instantiate paths
>
> A: request_key() B: KEYCTL_INSTANTIATE_IOV
> ---------------- -------------------------
> create auth key
> store rka in auth key
> wait for helper
> get auth key
> load rka from auth key
> copy user payload
> sleep on #PF
>
> helper completed
> detach and free rka
> destroy auth key
> wake up
> use rka->target_key
> **USE-AFTER-FREE**
>
> Give request_key_auth payloads a refcount. Take a payload reference while
> authkey->sem stabilizes the payload and revocation state. Hold that
> reference across the instantiate and reject paths. Drop the auth key
> owning reference from revoke and destroy.
>
> [jarkko: Replaced the first two paragraphs of text with a concurrency scenario.]
>
> And it includes also the remark at the end.
>
> BR, Jarkko
Nothing heard so I pushed:
https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/commit/?h=for-next-keys&id=9feb0bb3468e863b2b82a2eabfaeec4c7c44b90c
It has the commit message change.
BR, Jarkko
next prev parent reply other threads:[~2026-06-10 10:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 2:48 [PATCH] keys: Pin request_key_auth payload in instantiate paths Shaomin Chen
2026-05-29 22:53 ` Jarkko Sakkinen
[not found] ` <CA+TOyfhe=0Ty-FQDZy-9_LWJ6dgakzyjog5rNfQ2NdCc5X+dFQ@mail.gmail.com>
2026-05-30 16:48 ` Jarkko Sakkinen
2026-05-30 16:49 ` Jarkko Sakkinen
2026-06-08 3:06 ` Jarkko Sakkinen
2026-06-08 3:10 ` Jarkko Sakkinen
[not found] ` <aiZTIzGg_peDVo1M@kernel.org>
2026-06-08 5:42 ` Jarkko Sakkinen
2026-06-10 10:16 ` Jarkko Sakkinen [this message]
2026-06-10 15:21 ` eee sss
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=aik5YaJhjRuOKE7I@kernel.org \
--to=jarkko@kernel.org \
--cc=dhowells@redhat.com \
--cc=eeesssooo020@gmail.com \
--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