Skip to content

Commit f01fa7f

Browse files
torvaldsopsiff
authored andcommitted
security/keys: fix missed RCU read section on lookup
commit 43a1e3744548e6fd85873e6fb43e293eb4010694 upstream. Nicholas Carlini reports that the keyring code calls assoc_array_find() in find_key_to_update() without holding the RCU read lock, while the assoc_array_gc() code really is designed around removing the node from the tree and then freeing it after an RCU grace-period. The regular key handling doesn't see this because holding the keyring semaphore hides any lifetime issues, but the persistent key handling uses a different model. Instead of extending the keyring locking, just do the simple RCU locking that the assoc_array was designed for. Reported-by: Nicholas Carlini <npc@anthropic.com> Cc: David Howells <dhowells@redhat.com> Cc: Jarkko Sakkinen <jarkko@kernel.org> Cc: Paul Moore <paul@paul-moore.com> Cc: James Morris James Morris <jmorris@namei.org> Cc: Serge E. Hallyn <serge@hallyn.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 50bb3435a5e627bfbdc52eb4536f49f88b3486b8) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent ec0c26a commit f01fa7f

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

security/keys/keyring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ key_ref_t find_key_to_update(key_ref_t keyring_ref,
11091109
kenter("{%d},{%s,%s}",
11101110
keyring->serial, index_key->type->name, index_key->description);
11111111

1112+
guard(rcu)();
11121113
object = assoc_array_find(&keyring->keys, &keyring_assoc_array_ops,
11131114
index_key);
11141115

0 commit comments

Comments
 (0)