Skip to contentSkip to conversation

KEYS: Destroy by key type before removing the rest of the key

PATCH New Sasha Levin 1 participant 1 message Nov 30, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KEYS: Destroy by key type before removing the rest of the key

We should make sure that the key type does it's destruction dance first before we start tearing down the key structure itself so that we won't have a live key in a semi-coherent state.

This would prevent a race between key destruction and lookup in the keyring case, resulting in a use-after-free.

---
 security/keys/gc.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
security/keys/gc.c +3 -3
index 9609a7f..8f3b518 100644
@@ -134,6 +134,9 @@ static noinline void key_gc_unused_keys(struct list_head *keys)
 		kdebug("- %u", key->serial);
 		key_check(key);
 
+		if (key->type->destroy)
+			key->type->destroy(key);
+
 		security_key_free(key);
 
 		/* deal with the user's key tracking and quota */
@@ -151,9 +154,6 @@ static noinline void key_gc_unused_keys(struct list_head *keys)
 		key_user_put(key->user);
 
 		/* now throw away the key memory */
-		if (key->type->destroy)
-			key->type->destroy(key);
-
 		kfree(key->description);
 
 #ifdef KEY_DEBUGGING
Signature · 1 line
1.7.10.4