Commit 9aae17f8 authored by Eric Biggers's avatar Eric Biggers Committed by Greg Kroah-Hartman

KEYS: put keyring if install_session_keyring_to_cred() fails

[ Upstream commit d636bd9f ]

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 23567fd0 ("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: default avatarEric Biggers <>
Signed-off-by: default avatarDavid Howells <>
Signed-off-by: default avatarJames Morris <>
Signed-off-by: default avatarSasha Levin <>
parent 6596d0ab
...@@ -808,15 +808,14 @@ long join_session_keyring(const char *name) ...@@ -808,15 +808,14 @@ long join_session_keyring(const char *name)
ret = PTR_ERR(keyring); ret = PTR_ERR(keyring);
goto error2; goto error2;
} else if (keyring == new->session_keyring) { } else if (keyring == new->session_keyring) {
ret = 0; ret = 0;
goto error2; goto error3;
} }
/* we've got a keyring - now to install it */ /* we've got a keyring - now to install it */
ret = install_session_keyring_to_cred(new, keyring); ret = install_session_keyring_to_cred(new, keyring);
if (ret < 0) if (ret < 0)
goto error2; goto error3;
commit_creds(new); commit_creds(new);
mutex_unlock(&key_session_mutex); mutex_unlock(&key_session_mutex);
...@@ -826,6 +825,8 @@ long join_session_keyring(const char *name) ...@@ -826,6 +825,8 @@ long join_session_keyring(const char *name)
okay: okay:
return ret; return ret;
error2: error2:
mutex_unlock(&key_session_mutex); mutex_unlock(&key_session_mutex);
error: error:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment