summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--security/keys/gc.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/security/keys/gc.c b/security/keys/gc.c
index 207e9686c249..7817bb094239 100644
--- a/security/keys/gc.c
+++ b/security/keys/gc.c
@@ -172,8 +172,10 @@ static noinline void key_gc_unused_key(struct key *key)
{
key_check(key);
- /* Throw away the key data */
- if (key->type->destroy)
+ /* Throw away the key data if the key is instantiated */
+ if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags) &&
+ !test_bit(KEY_FLAG_NEGATIVE, &key->flags) &&
+ key->type->destroy)
key->type->destroy(key);
security_key_free(key);