The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: 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-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] keys: fix lost wakeup when reaping a dead key type
Date: Fri, 21 Aug 2026 02:28:10 +0300	[thread overview]
Message-ID: <aoeNilyh183yLH6B@kernel.org> (raw)
In-Reply-To: <20260811173753.67616-1-kmehltretter@gmail.com>

On Tue, Aug 11, 2026 at 07:37:53PM +0200, Karl Mehltretter wrote:
> key_garbage_collector() clears KEY_GC_REAPING_KEYTYPE and calls
> wake_up_bit() after reaping a dead key type. wake_up_bit() uses a
> lockless waitqueue check and requires a full barrier after the clear.
> 
> The existing smp_mb() is before clear_bit(), so the GC can see an empty
> waitqueue while unregister_key_type() still sees the bit set. The final
> wakeup can then be lost, leaving module unload stuck in wait_on_bit().
> 
> Use clear_and_wake_up_bit(). Its clear_bit_unlock() preserves the
> ordering of the completed GC work, and its smp_mb__after_atomic()
> orders the clear before the waitqueue check.
> 
> Fixes: 0c061b5707ab ("KEYS: Correctly destroy key payloads when their keytype is removed")
> Assisted-by: Claude:claude-fable-5
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>


I think the fix good but it would be good first to have reminder that
while clear_bit() is an atomic operation as respect to the data it
holds, it is an unordered operation [1].

That is sort of the beginning of the story.

So yeah, tweak the commit message a bit and send v2.

[1] https://docs.kernel.org/core-api/wrappers/atomic_bitops.html

BR, Jarkko

      reply	other threads:[~2026-08-20 23:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-11 17:37 [PATCH] keys: fix lost wakeup when reaping a dead key type Karl Mehltretter
2026-08-20 23:28 ` 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=aoeNilyh183yLH6B@kernel.org \
    --to=jarkko@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=kmehltretter@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=serge@hallyn.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