summaryrefslogtreecommitdiff
path: root/security
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2017-09-18 21:36:12 +0300
committerBen Hutchings <ben@decadent.org.uk>2018-01-01 23:50:52 +0300
commit4955da6650a89d4c9ea194dbfbe9ae5ae52f52e1 (patch)
treeed8aa14de32e730877bae2e418b8d575e352c94c /security
parent9e9039264036f9d1213920150f7db680c385aaf8 (diff)
downloadlinux-4955da6650a89d4c9ea194dbfbe9ae5ae52f52e1.tar.xz
KEYS: fix key refcount leak in keyctl_assume_authority()
commit 884bee0215fcc239b30c062c37ca29077005e064 upstream. In keyctl_assume_authority(), if keyctl_change_reqkey_auth() were to fail, we would leak the reference to the 'authkey'. Currently this can only happen if prepare_creds() fails to allocate memory. But it still should be fixed, as it is a more severe bug waiting to happen. This patch also moves the read of 'authkey->serial' to before the reference to the authkey is dropped. Doing the read after dropping the reference is very fragile because it assumes we still hold another reference to the key. (Which we do, in current->cred->request_key_auth, but there's no reason not to write it in the "obviously correct" way.) Fixes: d84f4f992cbd ("CRED: Inaugurate COW credentials") 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>
Diffstat (limited to 'security')
-rw-r--r--security/keys/keyctl.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 41525338aa8d..ed50ef10aa69 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -1345,11 +1345,9 @@ long keyctl_assume_authority(key_serial_t id)
}
ret = keyctl_change_reqkey_auth(authkey);
- if (ret < 0)
- goto error;
+ if (ret == 0)
+ ret = authkey->serial;
key_put(authkey);
-
- ret = authkey->serial;
error:
return ret;
}