[PATCH v6] KEYS: Protect pkey method checks against type removal
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon Nov 9 06:02:54 UTC 2026
> keyctl_pkey_query(), keyctl_pkey_e_d_s() and keyctl_pkey_verify() check
> that key->type has the ->asym_*() method they need and call it later,
> without holding key->sem. A reference keeps the key alive, but does not
> pin the module that provides its type.
>
> When that module is unloaded, unregister_key_type() waits for the key GC
> to process every remaining key of the type. For each such key, the GC
> takes key->sem for writing, switches key->type to key_type_dead, whose
> ->asym_*() methods are NULL, and destroys the payload. If this happens
> between the check and the call, the keyctl calls a NULL method:
>
> KEYCTL_PKEY_SIGN task Module unload and key GC
> ------------------------ ------------------------
> keyctl_pkey_e_d_s()
> if (!key->type->asym_eds_op) unregister_key_type()
> [ ... ]
> against type removal").
>
> Fixes: 00d60fd3b932 ("KEYS: Provide keyctls to drive the new key type ops for asymmetric keys [ver #2]")
> Cc: stable at vger.kernel.org
> Signed-off-by: Yuansheng Yang <0xbeac at gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109055204.31673-1-0xbeac@gmail.com?part=1
More information about the Linux-security-module-archive
mailing list