Skip to contentSkip to conversation

Patch "KEYS: fix keyctl_set_reqkey_keyring() to not leak thread keyrings" has been added to the 4.9-stable tree

PATCH [email protected] 1 participant 1 message Apr 21, 2017

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

KEYS: fix keyctl_set_reqkey_keyring() to not leak thread keyrings

to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
keys-fix-keyctl_set_reqkey_keyring-to-not-leak-thread-keyrings.patch
and it can be found in the queue-4.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From c9f838d104fed6f2f61d68164712e3204bf5271b Mon Sep 17 00:00:00 2001

From: Eric Biggers <[email protected]>
Date: Tue, 18 Apr 2017 15:31:09 +0100
Subject: KEYS: fix keyctl_set_reqkey_keyring() to not leak thread keyrings

From: Eric Biggers <[email protected]>

commit c9f838d104fed6f2f61d68164712e3204bf5271b upstream.

This fixes CVE-2017-7472.

Running the following program as an unprivileged user exhausts kernel memory by leaking thread keyrings:

	#include <keyutils.h>

	int main()
	{
		for (;;)
			keyctl_set_reqkey_keyring(KEY_REQKEY_DEFL_THREAD_KEYRING);
	}

Fix it by only creating a new thread keyring if there wasn't one before. To make things more consistent, make install_thread_keyring_to_cred() and install_process_keyring_to_cred() both return 0 if the corresponding keyring is already present.

Fixes d84f4f992cbd ("CRED: Inaugurate COW credentials")
---
 security/keys/keyctl.c       |   11 +++-------
 security/keys/process_keys.c |   44 ++++++++++++++++++++++++++-----------------
 2 files changed, 31 insertions(+), 24 deletions(-)
security/keys/keyctl.c +4 -7
@@ -1256,8 +1256,8 @@ error:
  * Read or set the default keyring in which request_key() will cache keys and
  * return the old setting.
  *
- * If a process keyring is specified then this will be created if it doesn't
- * yet exist.  The old setting will be returned if successful.
+ * If a thread or process keyring is specified then it will be created if it
+ * doesn't yet exist.  The old setting will be returned if successful.
  */
 long keyctl_set_reqkey_keyring(int reqkey_defl)
 {
@@ -1282,11 +1282,8 @@ long keyctl_set_reqkey_keyring(int reqke
 
 	case KEY_REQKEY_DEFL_PROCESS_KEYRING:
 		ret = install_process_keyring_to_cred(new);
-		if (ret < 0) {
-			if (ret != -EEXIST)
-				goto error;
-			ret = 0;
-		}
+		if (ret < 0)
+			goto error;
 		goto set;
 
 	case KEY_REQKEY_DEFL_DEFAULT:
security/keys/process_keys.c +27 -17

105 lines not on this page · raw message

Patches currently in stable-queue which might be from [email protected] are

queue-4.9/keys-fix-keyctl_set_reqkey_keyring-to-not-leak-thread-keyrings.patch