]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KEYS: Use acquire when reading state in keyring search
authorGui-Dong Han <hanguidong02@gmail.com>
Fri, 29 May 2026 03:34:06 +0000 (11:34 +0800)
committerJarkko Sakkinen <jarkko@kernel.org>
Mon, 15 Jun 2026 12:19:12 +0000 (15:19 +0300)
The negative-key race fix added release/acquire ordering for key use.

Publish payload before state; read state before payload.

keyring_search_iterator() still uses READ_ONCE() before match callbacks.
An asymmetric match callback calls asymmetric_key_ids(), which reads
key->payload.data[asym_key_ids].

Use key_read_state() there to complete that ordering.

Fixes: 363b02dab09b ("KEYS: Fix race between updating and finding a negative key")
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20260529033406.20673-1-hanguidong02@gmail.com
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
security/keys/keyring.c

index 5a9887d6b7be3c5e3a98b4dd8427a2c8552ed8a0..7a2ee0ded7c931f96bcf6c7acc98342e157361b3 100644 (file)
@@ -576,7 +576,7 @@ static int keyring_search_iterator(const void *object, void *iterator_data)
        struct keyring_search_context *ctx = iterator_data;
        const struct key *key = keyring_ptr_to_key(object);
        unsigned long kflags = READ_ONCE(key->flags);
-       short state = READ_ONCE(key->state);
+       short state = key_read_state(key);
 
        kenter("{%d}", key->serial);