diff --git a/0001-KEYS-Fix-crash-when-attempt-to-garbage-collect-an-un.patch b/0001-KEYS-Fix-crash-when-attempt-to-garbage-collect-an-un.patch new file mode 100644 index 000000000..15640604b --- /dev/null +++ b/0001-KEYS-Fix-crash-when-attempt-to-garbage-collect-an-un.patch @@ -0,0 +1,76 @@ +From d856e14fb043b742f94170db36b812770a2591d0 Mon Sep 17 00:00:00 2001 +From: David Howells +Date: Thu, 15 Oct 2015 17:21:37 +0100 +Subject: [PATCH 1/2] KEYS: Fix crash when attempt to garbage collect an + uninstantiated keyring + + 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: [] keyring_destroy+0x3d/0x88 + ... + Workqueue: events key_garbage_collector + ... + RIP: 0010:[] 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: + [] key_gc_unused_keys.constprop.1+0x5d/0x10f + [] key_garbage_collector+0x1fa/0x351 + [] process_one_work+0x28e/0x547 + [] worker_thread+0x26e/0x361 + [] ? rescuer_thread+0x2a8/0x2a8 + [] kthread+0xf3/0xfb + [] ? kthread_create_on_node+0x1c2/0x1c2 + [] ret_from_fork+0x3f/0x70 + [] ? 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 + Signed-off-by: David Howells +--- + security/keys/gc.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/security/keys/gc.c b/security/keys/gc.c +index c7952375ac53..11c36627adbf 100644 +--- a/security/keys/gc.c ++++ b/security/keys/gc.c +@@ -149,7 +149,9 @@ static noinline void key_gc_unused_keys(struct list_head *keys) + atomic_dec(&key->user->nikeys); + + /* now throw away the key memory */ +- if (key->type->destroy) ++ if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags) && ++ !test_bit(KEY_FLAG_NEGATIVE, &key->flags) && ++ key->type->destroy) + key->type->destroy(key); + + key_user_put(key->user); +-- +2.4.3 + diff --git a/0002-KEYS-Don-t-permit-request_key-to-construct-a-new-key.patch b/0002-KEYS-Don-t-permit-request_key-to-construct-a-new-key.patch new file mode 100644 index 000000000..727ee6aca --- /dev/null +++ b/0002-KEYS-Don-t-permit-request_key-to-construct-a-new-key.patch @@ -0,0 +1,34 @@ +From 93f27344ac019135dd5ff31a518f1ef2d9e4e4a1 Mon Sep 17 00:00:00 2001 +From: David Howells +Date: Mon, 19 Oct 2015 11:33:38 +0100 +Subject: [PATCH 2/2] KEYS: Don't permit request_key() to construct a new + keyring + + If request_key() is used to find a keyring, only do the search part - don't + do the construction part if the keyring was not found by the search. We + don't really want keyrings in the negative instantiated state since the + rejected/negative instantiation error value in the payload is unioned with + keyring metadata. + + Signed-off-by: David Howells +--- + security/keys/request_key.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/security/keys/request_key.c b/security/keys/request_key.c +index 486ef6fa393b..0d6253124278 100644 +--- a/security/keys/request_key.c ++++ b/security/keys/request_key.c +@@ -440,6 +440,9 @@ static struct key *construct_key_and_link(struct keyring_search_context *ctx, + + kenter(""); + ++ if (ctx->index_key.type == &key_type_keyring) ++ return ERR_PTR(-EPERM); ++ + user = key_user_lookup(current_fsuid()); + if (!user) + return ERR_PTR(-ENOMEM); +-- +2.4.3 + diff --git a/kernel.spec b/kernel.spec index fec57e1a9..fa4a32193 100644 --- a/kernel.spec +++ b/kernel.spec @@ -680,6 +680,10 @@ Patch538: ALSA-hda-Add-dock-support-for-ThinkPad-T550.patch #CVE-2015-5156 rhbz 1243852 1266515 Patch539: virtio-net-drop-NETIF_F_FRAGLIST.patch +#rhbz 1272172 +Patch540: 0001-KEYS-Fix-crash-when-attempt-to-garbage-collect-an-un.patch +Patch541: 0002-KEYS-Don-t-permit-request_key-to-construct-a-new-key.patch + # END OF PATCH DEFINITIONS %endif @@ -1466,6 +1470,10 @@ ApplyPatch ALSA-hda-Add-dock-support-for-ThinkPad-T550.patch #CVE-2015-5156 rhbz 1243852 1266515 ApplyPatch virtio-net-drop-NETIF_F_FRAGLIST.patch +#rhbz 1272172 +ApplyPatch 0001-KEYS-Fix-crash-when-attempt-to-garbage-collect-an-un.patch +ApplyPatch 0002-KEYS-Don-t-permit-request_key-to-construct-a-new-key.patch + # END OF PATCH APPLICATIONS %endif @@ -2325,6 +2333,9 @@ fi # ||----w | # || || %changelog +* Mon Oct 19 2015 Josh Boyer +- Fix crash in key garbage collector when using request_key (rhbz 1272172) + * Wed Oct 07 2015 Josh Boyer - CVE-2015-5156 virtio-net: bug overflow with large fraglist (rhbz 1243852 1266515)