Re: [PATCH] KEYS: Prevent key type removal during key_instantiate_and_link()

From: Jarkko Sakkinen

Date: Tue Nov 24 2026 - 12:45:15 EST


On Tue, Nov 24, 2026 at 07:40:35PM +0200, Jarkko Sakkinen wrote:
> key_instantiate_and_link() accesses key->type outside key->sem, which can
> lead into null deref due that key types can be dropped at any possible
> time.
>
> Address this by moving key_construction_mutex inside key->sem, and match
> that order in key_reject_and_link())
>
> Cc: stable@xxxxxxxxxxxxxxx
> Cc: keyrings@xxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Cc: linux-security-module@xxxxxxxxxxxxxxx
> Cc: David Howells <dhowells@xxxxxxxxxx>
> Cc: James Morris <jmorris@xxxxxxxxx>
> Cc: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
> Cc: Paul Moore <paul@xxxxxxxxxxxxxx>
> Cc: "Serge E. Hallyn" <serge@xxxxxxxxxx>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Reported-by: Guicai Ma <maguicai@xxxxxxxxxx>
> Closes: https://lore.kernel.org/r/20261124091243.1019217-1-maguicai@xxxxxxxxxx
> Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>

Can be better addressed later with this:
https://lore.kernel.org/keyrings/20261112040242.247168-1-jarkko@xxxxxxxxxx/

In erases all key type drop type of issue. Thus, totally acceptable
bug fix.

Br, Jarkko