summaryrefslogtreecommitdiffstats
path: root/security/keys
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2017-06-08 14:48:03 +0100
committerJames Morris <james.l.morris@oracle.com>2017-06-09 13:29:46 +1000
commitd636bd9f12a66ea3775c9fabbf3f8e118253467a (patch)
treed2242b7934d34bd2e6779e5d2061a0ed5ce216cc /security/keys
parent41f1c53e0d7d6e79087d5f5e18c467747126a3fc (diff)
downloadop-kernel-dev-d636bd9f12a66ea3775c9fabbf3f8e118253467a.zip
op-kernel-dev-d636bd9f12a66ea3775c9fabbf3f8e118253467a.tar.gz
KEYS: put keyring if install_session_keyring_to_cred() fails
In join_session_keyring(), if install_session_keyring_to_cred() were to fail, we would leak the keyring reference, just like in the bug fixed by commit 23567fd052a9 ("KEYS: Fix keyring ref leak in join_session_keyring()"). Fortunately this cannot happen currently, but we really should be more careful. Do this by adding and using a new error label at which the keyring reference is dropped. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: James Morris <james.l.morris@oracle.com>
Diffstat (limited to 'security/keys')
-rw-r--r--security/keys/process_keys.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
index 2217dfe..86bced9 100644
--- a/security/keys/process_keys.c
+++ b/security/keys/process_keys.c
@@ -809,15 +809,14 @@ long join_session_keyring(const char *name)
ret = PTR_ERR(keyring);
goto error2;
} else if (keyring == new->session_keyring) {
- key_put(keyring);
ret = 0;
- goto error2;
+ goto error3;
}
/* we've got a keyring - now to install it */
ret = install_session_keyring_to_cred(new, keyring);
if (ret < 0)
- goto error2;
+ goto error3;
commit_creds(new);
mutex_unlock(&key_session_mutex);
@@ -827,6 +826,8 @@ long join_session_keyring(const char *name)
okay:
return ret;
+error3:
+ key_put(keyring);
error2:
mutex_unlock(&key_session_mutex);
error:
OpenPOWER on IntegriCloud