Skip to content

Commit

Permalink
Don't leak a key reference if request_key() tries to use a revoked ke…
Browse files Browse the repository at this point in the history
…yring

If a request_key() call to allocate and fill out a key attempts to insert the
key structure into a revoked keyring, the key will leak, using memory and part
of the user's key quota until the system reboots. This is from a failure of
construct_alloc_key() to decrement the key's reference count after the attempt
to insert into the requested keyring is rejected.

key_put() needs to be called in the link_prealloc_failed callpath to ensure
the unused key is released.

Signed-off-by: David Jeffery <[email protected]>
Signed-off-by: David Howells <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
David Jeffery authored and James Morris committed Feb 16, 2015
1 parent cd07db5 commit d0709f1
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions security/keys/request_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ static int construct_alloc_key(struct keyring_search_context *ctx,

link_prealloc_failed:
mutex_unlock(&user->cons_lock);
key_put(key);
kleave(" = %d [prelink]", ret);
return ret;

Expand Down

0 comments on commit d0709f1

Please sign in to comment.