[linux] 02/03: KEYS: Fix crash when attempt to garbage collect an uninstantiated keyring (CVE-2015-7872)

debian-kernel at lists.debian.org debian-kernel at lists.debian.org
Wed Oct 21 16:54:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

carnil pushed a commit to branch wheezy-security
in repository linux.

commit 52308c87fee013284ccc8771625fc65970d3c1fc
Author: Salvatore Bonaccorso <carnil at debian.org>
Date:   Wed Oct 21 17:04:16 2015 +0200

    KEYS: Fix crash when attempt to garbage collect an uninstantiated keyring (CVE-2015-7872)
---
 debian/changelog                                   |  2 +
 ...ash-when-attempt-to-garbage-collect-an-un.patch | 75 ++++++++++++++++++++++
 debian/patches/series                              |  1 +
 3 files changed, 78 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 4d2c219..bb8a3d1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
 linux (3.2.68-1+deb7u6) UNRELEASED; urgency=medium
 
   * KEYS: Fix race between key destruction and finding a keyring by name
+  * KEYS: Fix crash when attempt to garbage collect an uninstantiated keyring
+    (CVE-2015-7872)
 
  -- Salvatore Bonaccorso <carnil at debian.org>  Wed, 21 Oct 2015 17:00:31 +0200
 
diff --git a/debian/patches/bugfix/all/KEYS-Fix-crash-when-attempt-to-garbage-collect-an-un.patch b/debian/patches/bugfix/all/KEYS-Fix-crash-when-attempt-to-garbage-collect-an-un.patch
new file mode 100644
index 0000000..5b56b79
--- /dev/null
+++ b/debian/patches/bugfix/all/KEYS-Fix-crash-when-attempt-to-garbage-collect-an-un.patch
@@ -0,0 +1,75 @@
+From: David Howells <dhowells at redhat.com>
+Date: Thu, 15 Oct 2015 17:21:37 +0100
+Subject: KEYS: Fix crash when attempt to garbage collect an uninstantiated
+ keyring
+Origin: https://git.kernel.org/linus/f05819df10d7b09f6d1eb6f8534a8f68e5a4fe61
+
+The following sequence of commands:
+
+    i=`keyctl add user a a @s`
+    keyctl request2 keyring foo bar @t
+    keyctl unlink $i @s
+
+tries to invoke an upcall to instantiate a keyring if one doesn't already
+exist by that name within the user's keyring set.  However, if the upcall
+fails, the code sets keyring->type_data.reject_error to -ENOKEY or some
+other error code.  When the key is garbage collected, the key destroy
+function is called unconditionally and keyring_destroy() uses list_empty()
+on keyring->type_data.link - which is in a union with reject_error.
+Subsequently, the kernel tries to unlink the keyring from the keyring names
+list - which oopses like this:
+
+	BUG: unable to handle kernel paging request at 00000000ffffff8a
+	IP: [<ffffffff8126e051>] keyring_destroy+0x3d/0x88
+	...
+	Workqueue: events key_garbage_collector
+	...
+	RIP: 0010:[<ffffffff8126e051>] keyring_destroy+0x3d/0x88
+	RSP: 0018:ffff88003e2f3d30  EFLAGS: 00010203
+	RAX: 00000000ffffff82 RBX: ffff88003bf1a900 RCX: 0000000000000000
+	RDX: 0000000000000000 RSI: 000000003bfc6901 RDI: ffffffff81a73a40
+	RBP: ffff88003e2f3d38 R08: 0000000000000152 R09: 0000000000000000
+	R10: ffff88003e2f3c18 R11: 000000000000865b R12: ffff88003bf1a900
+	R13: 0000000000000000 R14: ffff88003bf1a908 R15: ffff88003e2f4000
+	...
+	CR2: 00000000ffffff8a CR3: 000000003e3ec000 CR4: 00000000000006f0
+	...
+	Call Trace:
+	 [<ffffffff8126c756>] key_gc_unused_keys.constprop.1+0x5d/0x10f
+	 [<ffffffff8126ca71>] key_garbage_collector+0x1fa/0x351
+	 [<ffffffff8105ec9b>] process_one_work+0x28e/0x547
+	 [<ffffffff8105fd17>] worker_thread+0x26e/0x361
+	 [<ffffffff8105faa9>] ? rescuer_thread+0x2a8/0x2a8
+	 [<ffffffff810648ad>] kthread+0xf3/0xfb
+	 [<ffffffff810647ba>] ? kthread_create_on_node+0x1c2/0x1c2
+	 [<ffffffff815f2ccf>] ret_from_fork+0x3f/0x70
+	 [<ffffffff810647ba>] ? kthread_create_on_node+0x1c2/0x1c2
+
+Note the value in RAX.  This is a 32-bit representation of -ENOKEY.
+
+The solution is to only call ->destroy() if the key was successfully
+instantiated.
+
+Reported-by: Dmitry Vyukov <dvyukov at google.com>
+Signed-off-by: David Howells <dhowells at redhat.com>
+Tested-by: Dmitry Vyukov <dvyukov at google.com>
+[carnil: Backported for 3.2: adjust context]
+---
+ security/keys/gc.c | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+--- a/security/keys/gc.c
++++ b/security/keys/gc.c
+@@ -172,8 +172,10 @@ static noinline void key_gc_unused_key(s
+ {
+ 	key_check(key);
+ 
+-	/* Throw away the key data */
+-	if (key->type->destroy)
++	/* Throw away the key data if the key is instantiated */
++	if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags) &&
++	    !test_bit(KEY_FLAG_NEGATIVE, &key->flags) &&
++	    key->type->destroy)
+ 		key->type->destroy(key);
+ 
+ 	security_key_free(key);
diff --git a/debian/patches/series b/debian/patches/series
index 96f2752..ecfa141 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1185,3 +1185,4 @@ bugfix/all/Initialize-msg-shm-IPC-objects-before-doing-ipc_addi.patch
 bugfix/all/dcache-handle-escaped-paths-in-prepend_path.patch
 bugfix/all/vfs-test-for-and-handle-paths-that-are-unreachable-from-their-mnt_root.patch
 bugfix/all/KEYS-Fix-race-between-key-destruction-and-finding-a-.patch
+bugfix/all/KEYS-Fix-crash-when-attempt-to-garbage-collect-an-un.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/linux.git



More information about the Kernel-svn-changes mailing list