From: Zhenwen Liang <zhenwenliang@google.com>
To: Jarkko Sakkinen <jarkko@kernel.org>
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 20:00:58 +0000 [thread overview]
Message-ID: <20261126200058.2806412-1-zhenwenliang@google.com> (raw)
In-Reply-To: <awiDY0d9pRUzkV4Z@kernel.org>
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
next prev parent reply other threads:[~2026-11-26 20:01 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 [this message]
2026-11-26 20:05 ` Jarkko Sakkinen
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=20261126200058.2806412-1-zhenwenliang@google.com \
--to=zhenwenliang@google.com \
--cc=dhowells@redhat.com \
--cc=jarkko@kernel.org \
--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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox