KEYS: fix key refcount leak in keyctl_read_key()
authorEric Biggers <ebiggers@google.com>
Mon, 18 Sep 2017 18:36:31 +0000 (11:36 -0700)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 1 Jan 2018 20:50:52 +0000 (20:50 +0000)
commit0286cd9b50525d917de6f882fa6cbbe4190cf2d2
treef918d40d2a8ff99cd689344df93f01db11f59ae1
parent4955da6650a89d4c9ea194dbfbe9ae5ae52f52e1
KEYS: fix key refcount leak in keyctl_read_key()

commit 7fc0786d956d9e59b68d282be9b156179846ea3d upstream.

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: 29db91906340 ("[PATCH] Keys: Add LSM hooks for key management [try #3]")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
security/keys/keyctl.c