Linux Security Modules development
 help / color / mirror / Atom feed
* [PATCH v2] KEYS: protect construct_key type dereference with key semaphore
@ 2026-11-21 12:50 Tristan Madani
  2026-11-21 13:05 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Tristan Madani @ 2026-11-21 12:50 UTC (permalink / raw)
  To: David Howells, Jarkko Sakkinen
  Cc: Paul Moore, James Morris, Serge E. Hallyn, keyrings,
	linux-security-module, linux-kernel, Tristan Madani, stable

From: Tristan Madani <tristan@talencesecurity.com>

construct_key() reads key->type->request_key without holding key->sem,
then calls the resulting actor function pointer.  While the
sys_request_key() syscall path holds key_types_sem for reading (via
key_type_lookup()), which prevents concurrent type removal, in-kernel
request_key() callers pass struct key_type directly without holding
key_types_sem.  If unregister_key_type() races with such a caller,
key_garbage_collector() can retype the key to key_type_dead and the
module text backing the original request_key method can be freed before
the actor call executes.

Take key->sem for reading around both the key->type->request_key lookup
and the actor() call, consistent with the approach used by 925c84e3cc21
("KEYS: Protect the read method check against type removal"),
51bcd09b9ffc ("KEYS: Protect the update method check against type
removal") and bab48a104447 ("KEYS: Protect the pkey method checks
against type removal") which protect analogous method dereferences in
the keyctl paths.

Fixes: b5f545c880a2 ("[PATCH] keys: Permit running process to instantiate keys")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
Changes in v2:
- Hold key->sem across the actor() call, not just the type pointer read,
  matching the established pattern from the three prior fixes (Sashiko)
- Clarify that in-kernel request_key() callers do not hold key_types_sem
  so the race is reachable outside the syscall path (Sashiko)

 security/keys/request_key.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/security/keys/request_key.c b/security/keys/request_key.c
index 22cd66a44da56..60a8cb5924e11 100644
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -241,10 +241,12 @@ static int construct_key(struct key *key, const void *callout_info,
 
 	/* Make the call */
 	actor = call_sbin_request_key;
+	down_read(&key->sem);
 	if (key->type->request_key)
 		actor = key->type->request_key;
 
 	ret = actor(authkey, aux);
+	up_read(&key->sem);
 
 	/* check that the actor called complete_request_key() prior to
 	 * returning an error */
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-21 13:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 12:50 [PATCH v2] KEYS: protect construct_key type dereference with key semaphore Tristan Madani
2026-11-21 13:05 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox