From: Jarkko Sakkinen <jarkko@kernel.org>
To: Cen Zhang <zzzccc427@gmail.com>
Cc: dhowells@redhat.com, paul@paul-moore.com, jmorris@namei.org,
serge@hallyn.com, keyrings@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, baijiaju1990@gmail.com,
jjzuming@gmail.com
Subject: Re: [PATCH] keys: Check the authorization payload in process keyring searches
Date: Sun, 11 Oct 2026 00:24:20 +0300 [thread overview]
Message-ID: <asqtBDX8112XvcRT@kernel.org> (raw)
In-Reply-To: <pm-key-management-objects-candidate-0004-v3-598361863b76bc25d58d@gmail.com>
On Fri, Oct 09, 2026 at 01:52:16PM +0800, Cen Zhang wrote:
> An authorization payload and its saved credentials must remain valid
> while search_process_keyrings_rcu() searches the requestor's keyrings.
> The function validates the authorization key, then separately loads
> payload.data[0] and unconditionally reads rka->cred. Validation does
> not prevent request_key_auth_revoke() from clearing the payload.
>
> A request-key helper can assume authority and fork a descendant that
> inherits the authorization key. If the descendant misses in its own
> keyrings, it falls back to the saved requestor credentials. Successful
> target instantiation invalidates the authorization key without clearing
> the payload. After the helper exits, UMH_WAIT_PROC returns to the
> requester, which calls complete_request_key() and revokes that key.
>
> With the descendant paused after validation, the paths can interleave
> as follows:
>
> 1. The descendant enters search_process_keyrings_rcu() under RCU and
> key_validate() succeeds.
> 2. The helper instantiates the target, invalidates the authorization
> key, and exits.
> 3. The requester resumes from UMH_WAIT_PROC, calls
> complete_request_key(), and revokes the authorization key.
> request_key_auth_revoke() sets its payload pointer to NULL.
> 4. The descendant loads NULL and dereferences rka->cred.
>
> This NULL dereference can oops the kernel. RCU delays payload disposal
> but does not prevent the pointer from being cleared.
>
> Load the payload with dereference_key_rcu() and require a non-NULL
> result before validating the authorization key and searching its saved
> credentials. A non-NULL payload and its credentials remain alive for
> the caller's RCU read-side section; a cleared payload skips the fallback
> search and follows the existing error selection.
>
> KASAN report as below:
>
> Oops: general protection fault, probably for non-canonical address 0xdffffc0000000005: 0000 [#1] SMP KASAN NOPTI
> KASAN: null-ptr-deref in range [0x0000000000000028-0x000000000000002f]
> RIP: 0010:search_process_keyrings_rcu+0x32b/0x790
>
> Fixes: e59428f721ee ("keys: Move the RCU locks outwards from the keyring search functions")
> Assisted-by: LLM
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
> ---
>
> diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
> index a63c46bb2d148080add6a194579f7b1093c04d82..76da13fa07fab70115966e9ea8360af66390dd85 100644
> --- a/security/keys/process_keys.c
> +++ b/security/keys/process_keys.c
> @@ -556,9 +556,8 @@ key_ref_t search_process_keyrings_rcu(struct keyring_search_context *ctx)
> ) {
> const struct cred *cred = ctx->cred;
>
> - if (key_validate(cred->request_key_auth) == 0) {
> - rka = ctx->cred->request_key_auth->payload.data[0];
> -
> + rka = dereference_key_rcu(cred->request_key_auth);
> + if (rka && key_validate(cred->request_key_auth) == 0) {
> //// was search_process_keyrings() [ie. recursive]
> ctx->cred = rka->cred;
> key_ref = search_cred_keyrings_rcu(ctx);
Thanks.
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
prev parent reply other threads:[~2026-10-10 21:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 5:52 Cen Zhang
2026-10-10 21:24 ` Jarkko Sakkinen [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=asqtBDX8112XvcRT@kernel.org \
--to=jarkko@kernel.org \
--cc=baijiaju1990@gmail.com \
--cc=dhowells@redhat.com \
--cc=jjzuming@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 \
--cc=zzzccc427@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
all inboxes | Powered by JetHome®