keys: ensure that ->match_free() is called in request_key_and_link()
authorEric Biggers <ebiggers@google.com>
Fri, 30 Aug 2019 15:52:26 +0000 (16:52 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 30 Aug 2019 18:10:55 +0000 (11:10 -0700)
If check_cached_key() returns a non-NULL value, we still need to call
key_type::match_free() to undo key_type::match_preparse().

Fixes: 7743c48e54ee ("keys: Cache result of request_key*() temporarily in task_struct")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
security/keys/request_key.c

index 7325f382dbf43b5660d0f3938e0ce18b737bed6e..957b9e3e14924dff2c3ad5d8e647d77f9eff6860 100644 (file)
@@ -595,7 +595,7 @@ struct key *request_key_and_link(struct key_type *type,
 
        key = check_cached_key(&ctx);
        if (key)
 
        key = check_cached_key(&ctx);
        if (key)
-               return key;
+               goto error_free;
 
        /* search all the process keyrings for a key */
        rcu_read_lock();
 
        /* search all the process keyrings for a key */
        rcu_read_lock();