Commit 34574dd1 authored by David Howells's avatar David Howells Committed by Linus Torvalds

keys: Handle there being no fallback destination keyring for request_key()

When request_key() is called, without there being any standard process
keyrings on which to fall back if a destination keyring is not specified, an
oops is liable to occur when construct_alloc_key() calls down_write() on
dest_keyring's semaphore.

Due to function inlining this may be seen as an oops in down_write() as called
from request_key_and_link().

This situation crops up during boot, where request_key() is called from within
the kernel (such as in CIFS mounts) where nobody is actually logged in, and so
PAM has not had a chance to create a session keyring and user keyrings to act
as the fallback.

To fix this, make construct_alloc_key() not attempt to cache a key if there is
no fallback key if no destination keyring is given specifically.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Tested-by: default avatarJeff Layton <jlayton@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 11ff5f6a
...@@ -311,6 +311,7 @@ static int construct_alloc_key(struct key_type *type, ...@@ -311,6 +311,7 @@ static int construct_alloc_key(struct key_type *type,
set_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags); set_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags);
if (dest_keyring)
down_write(&dest_keyring->sem); down_write(&dest_keyring->sem);
/* attach the key to the destination keyring under lock, but we do need /* attach the key to the destination keyring under lock, but we do need
...@@ -322,9 +323,11 @@ static int construct_alloc_key(struct key_type *type, ...@@ -322,9 +323,11 @@ static int construct_alloc_key(struct key_type *type,
if (!IS_ERR(key_ref)) if (!IS_ERR(key_ref))
goto key_already_present; goto key_already_present;
if (dest_keyring)
__key_link(dest_keyring, key); __key_link(dest_keyring, key);
mutex_unlock(&key_construction_mutex); mutex_unlock(&key_construction_mutex);
if (dest_keyring)
up_write(&dest_keyring->sem); up_write(&dest_keyring->sem);
mutex_unlock(&user->cons_lock); mutex_unlock(&user->cons_lock);
*_key = key; *_key = key;
......
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