From: Jarkko Sakkinen <jarkko@kernel.org>
To: Zhenwen Liang <zhenwenliang@google.com>
Cc: Mimi Zohar <zohar@linux.ibm.com>,
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-integrity@vger.kernel.org,
linux-security-module@vger.kernel.org
Subject: Re: KEYS: encrypted: encrypted_rcu_free() callbacks can outlive the module
Date: Thu, 26 Nov 2026 22:05:07 +0200 [thread overview]
Message-ID: <awiQ80xiFgCZSXfb@kernel.org> (raw)
In-Reply-To: <20261126200058.2806412-1-zhenwenliang@google.com>
On Thu, Nov 26, 2026 at 08:00:58PM +0000, Zhenwen Liang wrote:
> On Thu, Nov 26, 2026 at 09:07:15PM +0200, Jarkko Sakkinen wrote:
> > This will be ultimately addressed by:
> [...]
> > As then operations will be always drained.
> >
> > It's actually somewhat tedious to address this particular issue
> > without this type of architectural change but I'm open for fixes.
>
> Thanks. For trees that will not get the series, I think a minimal fix
> is possible here, because unregister_key_type() already guarantees that
> no new ->update() can run once it returns: key_create_or_update() holds
> key_types_sem across __key_update(), key_update() checks
> key->type->update under key->sem, and the dead-type GC pass retypes
> each remaining key to key_type_dead under key->sem before
> unregister_key_type() returns. So every encrypted_rcu_free() has been
> queued by then, and an rcu_barrier() after unregister_key_type() in
> cleanup_encrypted() waits for all of them. trusted.ko has the same
> pattern (trusted_update() uses call_rcu(), and none of the exit paths
> waits for pending callbacks), so cleanup_trusted() needs the same.
>
> I reproduced it in QEMU with KASAN and CONFIG_RCU_LAZY=y: add an
> encrypted key, update it 20 times, and unload the module right away.
> The rcuop kthread hit int3 at encrypted_rcu_free+0x1 in the freed
> module text in 5 of 5 runs. With the barrier, 5 of 5 runs were clean.
>
> With your series applied, the barrier is still needed as far as I can
> see: the GC calls synchronize_rcu() before the module_put() in
> key_gc_unused_keys(), and key_gc_flush() is only used by dns_resolver,
> NFS idmap, the SMB client and rxrpc. On top of the series, the barrier
> could become a key_gc_flush() call.
>
> I will send two small patches (encrypted, trusted) with Fixes: tags and
> Cc: stable; feel free to drop the stable tag if you think it is not
> worth it.
>
> Thanks,
> Zhenwen Liang
I saw the patches. I'll look at them with time as soon as I have
appropriate bandwidth (might next up til next week not sure).
Br, Jarkko
prev parent reply other threads:[~2026-11-26 20:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 2:35 KEYS: encrypted: encrypted_rcu_free() callbacks can outlive the module Zhenwen Liang
2026-11-26 19:07 ` Jarkko Sakkinen
2026-11-26 20:00 ` Zhenwen Liang
2026-11-26 20:05 ` 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=awiQ80xiFgCZSXfb@kernel.org \
--to=jarkko@kernel.org \
--cc=dhowells@redhat.com \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=zhenwenliang@google.com \
--cc=zohar@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.