aboutsummaryrefslogtreecommitdiffstats
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 c7952375ac53..0773673a489d 100644
--- a/security/keys/gc.c
+++ b/security/keys/gc.c
@@ -148,8 +148,10 @@ static noinline void key_gc_unused_keys(struct list_head *keys)
if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags))
atomic_dec(&key->user->nikeys);
- /* now throw away the key memory */
- if (key->type->destroy)
+ /* now throw away the key memory 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);
key_user_put(key->user);