[PATCH 2/2] KEYS: trusted: Wait for RCU callbacks before module unload
Jarkko Sakkinen
jarkko at kernel.org
Thu Nov 26 20:42:32 UTC 2026
On Thu, Nov 26, 2026 at 08:01:03PM +0000, Zhenwen Liang wrote:
> trusted_update() frees the old payload with call_rcu(), and the
> callback, trusted_rcu_free(), is part of trusted.ko. cleanup_trusted()
> calls the trust source's exit callback, which unregisters the key type,
> but nothing waits for callbacks that are already queued, so the module
> can be freed while a trusted_rcu_free() callback is still pending.
+1
>
> Add an rcu_barrier() after the exit callback. As for encrypted keys, no
> new callback can be queued once unregister_key_type() has returned. If
> no trust source was found, the key type was never registered and
> trusted_key_exit is NULL; the barrier is then harmless.
>
> Tested in QEMU (x86_64, TCG) without a trust source, so only the
> trusted_key_exit == NULL case ran: trusted.ko loads and unloads cleanly
> with this patch (5 runs). The trusted_update() path itself was not run,
> because no TPM was available.
>
> The problem was found, and this patch prepared, with the help of a
> formal analysis tool we are developing that uses AI assistance; I have
> reviewed the analysis and the patch.
>
> Fixes: d00a1c72f7f4 ("keys: add new trusted key-type")
> Link: https://lore.kernel.org/all/20261126023538.4160950-1-zhenwenliang@google.com/
> Cc: stable at vger.kernel.org
> Signed-off-by: Zhenwen Liang <zhenwenliang at google.com>
> ---
> security/keys/trusted-keys/trusted_core.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
> index 0509d9955f2a..5efd1e6ef111 100644
> --- a/security/keys/trusted-keys/trusted_core.c
> +++ b/security/keys/trusted-keys/trusted_core.c
> @@ -401,6 +401,7 @@ static void __exit cleanup_trusted(void)
> {
> if (trusted_key_exit)
> (*trusted_key_exit)();
> + rcu_barrier();
> }
>
> late_initcall(init_trusted);
Reviewed-by: Jarkko Sakkinen <jarkko at kernel.org>
Br, Jarkko
More information about the Linux-security-module-archive
mailing list