Skip to content

Commit 7fc0786

Browse files
ebiggersdhowells
authored andcommitted
KEYS: fix key refcount leak in keyctl_read_key()
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 raspberrypi#3]") Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 884bee0 commit 7fc0786

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎security/keys/keyctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
771771
if (ret == 0)
772772
goto can_read_key;
773773
if (ret != -EACCES)
774-
goto error;
774+
goto error2;
775775

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

0 commit comments

Comments
 (0)