Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93b4a44f authored by David Howells's avatar David Howells Committed by Linus Torvalds
Browse files

keys: fix an RCU warning



Fix the following RCU warning:

  ===================================================
  [ INFO: suspicious rcu_dereference_check() usage. ]
  ---------------------------------------------------
  security/keys/request_key.c:116 invoked rcu_dereference_check() without protection!

This was caused by doing:

	[root@andromeda ~]# keyctl newring fred @s
	539196288
	[root@andromeda ~]# keyctl request2 user a a 539196288
	request_key: Required key not available

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Acked-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ccdb4004
Loading
Loading
Loading
Loading
+8 −5
Original line number Original line Diff line number Diff line
@@ -68,7 +68,8 @@ static int call_sbin_request_key(struct key_construction *cons,
{
{
	const struct cred *cred = current_cred();
	const struct cred *cred = current_cred();
	key_serial_t prkey, sskey;
	key_serial_t prkey, sskey;
	struct key *key = cons->key, *authkey = cons->authkey, *keyring;
	struct key *key = cons->key, *authkey = cons->authkey, *keyring,
		*session;
	char *argv[9], *envp[3], uid_str[12], gid_str[12];
	char *argv[9], *envp[3], uid_str[12], gid_str[12];
	char key_str[12], keyring_str[3][12];
	char key_str[12], keyring_str[3][12];
	char desc[20];
	char desc[20];
@@ -112,10 +113,12 @@ static int call_sbin_request_key(struct key_construction *cons,
	if (cred->tgcred->process_keyring)
	if (cred->tgcred->process_keyring)
		prkey = cred->tgcred->process_keyring->serial;
		prkey = cred->tgcred->process_keyring->serial;


	if (cred->tgcred->session_keyring)
	rcu_read_lock();
		sskey = rcu_dereference(cred->tgcred->session_keyring)->serial;
	session = rcu_dereference(cred->tgcred->session_keyring);
	else
	if (!session)
		sskey = cred->user->session_keyring->serial;
		session = cred->user->session_keyring;
	sskey = session->serial;
	rcu_read_unlock();


	sprintf(keyring_str[2], "%d", sskey);
	sprintf(keyring_str[2], "%d", sskey);