From: Eric Biggers <ebiggers@kernel.org>
To: Cen Zhang <zzzccc427@gmail.com>
Cc: dhowells@redhat.com, jarkko@kernel.org, paul@paul-moore.com,
jmorris@namei.org, serge@hallyn.com, sergeh@kernel.org,
keyrings@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, baijiaju1990@gmail.com,
jjzuming@gmail.com
Subject: Re: [PATCH v2] keys: Avoid the owner account dereference in named keyring lookup
Date: Fri, 16 Oct 2026 20:51:56 -0700 [thread overview]
Message-ID: <20261017035156.GA29318@sol> (raw)
In-Reply-To: <pm-key-management-objects-candidate-0002-v3-2baa8cad2bb554364e10@gmail.com>
On Fri, Oct 09, 2026 at 01:11:59PM +0800, Cen Zhang wrote:
> Named keyring lookup must keep the storage containing the owner UID
> alive through the namespace mapping check. find_keyring_by_name()
> reads keyring->user->uid under keyring_name_lock, but that lock protects
> the keyring's name entry and allocation, not its separate key_user.
>
> A named session-keyring join can overlap a privileged KEYCTL_CHOWN on
> another CPU. If the keyring holds the last reference to its old dynamic
> key_user and the ownership transfer succeeds, the following ordering is
> possible:
>
> Named join Chown
> find_keyring_by_name() keyctl_chown_key()
> read_lock(keyring_name_lock) down_write(key->sem)
> load old keyring->user
> replace key->user and key->uid
> up_write(key->sem)
> key_put(key)
> key_user_put(old user): free
> read old user->uid
> read_unlock(keyring_name_lock)
>
> Chown neither takes keyring_name_lock nor key_session_mutex, so it can
> free the old account between the pointer load and the UID read. The
> lookup then reads freed memory even though the keyring itself is alive.
>
> Use keyring->uid for the mapping check. key_alloc() initializes this
> inline owner UID and keyctl_chown_key() updates it on chown.
> The existing name lock keeps its containing keyring allocated throughout
> the check, so lookup no longer depends on the account's lifetime. This
> also matches the owner UID used by the permission check.
>
> KASAN report as below:
>
> BUG: KASAN: slab-use-after-free in find_keyring_by_name+0x577/0x5d0
> Read of size 4 at addr ffff8881128ae2ec by task keycase/500
>
> Fixes: 2ea190d0a006 ("keys: skip keys from another user namespace")
> Assisted-by: LLM
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
Don't key_serial_next() and find_ge_key() (used when reading from
/proc/keys) have the same bug?
- Eric
next prev parent reply other threads:[~2026-10-17 3:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 5:11 [PATCH v2] keys: Avoid the owner account dereference in named keyring lookup Cen Zhang
2026-10-09 5:22 ` sashiko-bot
2026-10-10 20:50 ` Jarkko Sakkinen
2026-10-17 3:51 ` Eric Biggers [this message]
2026-10-17 7:47 ` Cen Zhang
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=20261017035156.GA29318@sol \
--to=ebiggers@kernel.org \
--cc=baijiaju1990@gmail.com \
--cc=dhowells@redhat.com \
--cc=jarkko@kernel.org \
--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=sergeh@kernel.org \
--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