Skip to content

Commit

Permalink
KEYS: fix key refcount leak in keyctl_read_key()
Browse files Browse the repository at this point in the history
In keyctl_read_key(), if key_permission() were to return an error code
other than EACCES, we would leak a the reference to the key.  This can't
actually happen currently because key_permission() can only return an
error code other than EACCES if security_key_permission() does, only
SELinux and Smack implement that hook, and neither can return an error
code other than EACCES.  But it should still be fixed, as it is a bug
waiting to happen.

Fixes: 29db919 ("[PATCH] Keys: Add LSM hooks for key management [try #3]")
Signed-off-by: Eric Biggers <[email protected]>
Signed-off-by: David Howells <[email protected]>
  • Loading branch information
ebiggers authored and dhowells committed Sep 25, 2017
1 parent 884bee0 commit 7fc0786
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion security/keys/keyctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
if (ret == 0)
goto can_read_key;
if (ret != -EACCES)
goto error;
goto error2;

/* we can't; see if it's searchable from this process's keyrings
* - we automatically take account of the fact that it may be
Expand Down

0 comments on commit 7fc0786

Please sign in to comment.