<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/security/keys, branch linux-2.6.34.y</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=linux-2.6.34.y</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=linux-2.6.34.y'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2014-02-10T21:11:33+00:00</updated>
<entry>
<title>Fix install_process_keyring error handling</title>
<updated>2014-02-10T21:11:33+00:00</updated>
<author>
<name>Andi Kleen</name>
<email>ak@linux.intel.com</email>
</author>
<published>2010-10-28T12:16:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=14424d71693c91f25d74ac09793d9f4aae43c104'/>
<id>urn:sha1:14424d71693c91f25d74ac09793d9f4aae43c104</id>
<content type='text'>
commit 27d6379894be4a81984da4d48002196a83939ca9 upstream.

Fix an incorrect error check that returns 1 for error instead of the
expected error code.

Signed-off-by: Andi Kleen &lt;ak@linux.intel.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Paul Gortmaker &lt;paul.gortmaker@windriver.com&gt;
</content>
</entry>
<entry>
<title>keys: fix race with concurrent install_user_keyrings()</title>
<updated>2014-02-10T21:11:15+00:00</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2013-03-12T05:44:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3e7f0a70958c7f5ed9bc684bc6601cf398c8c948'/>
<id>urn:sha1:3e7f0a70958c7f5ed9bc684bc6601cf398c8c948</id>
<content type='text'>
commit 0da9dfdd2cd9889201bc6f6f43580c99165cd087 upstream.

This fixes CVE-2013-1792.

There is a race in install_user_keyrings() that can cause a NULL pointer
dereference when called concurrently for the same user if the uid and
uid-session keyrings are not yet created.  It might be possible for an
unprivileged user to trigger this by calling keyctl() from userspace in
parallel immediately after logging in.

Assume that we have two threads both executing lookup_user_key(), both
looking for KEY_SPEC_USER_SESSION_KEYRING.

	THREAD A			THREAD B
	===============================	===============================
					==&gt;call install_user_keyrings();
	if (!cred-&gt;user-&gt;session_keyring)
	==&gt;call install_user_keyrings()
					...
					user-&gt;uid_keyring = uid_keyring;
	if (user-&gt;uid_keyring)
		return 0;
	&lt;==
	key = cred-&gt;user-&gt;session_keyring [== NULL]
					user-&gt;session_keyring = session_keyring;
	atomic_inc(&amp;key-&gt;usage); [oops]

At the point thread A dereferences cred-&gt;user-&gt;session_keyring, thread B
hasn't updated user-&gt;session_keyring yet, but thread A assumes it is
populated because install_user_keyrings() returned ok.

The race window is really small but can be exploited if, for example,
thread B is interrupted or preempted after initializing uid_keyring, but
before doing setting session_keyring.

This couldn't be reproduced on a stock kernel.  However, after placing
systemtap probe on 'user-&gt;session_keyring = session_keyring;' that
introduced some delay, the kernel could be crashed reliably.

Fix this by checking both pointers before deciding whether to return.
Alternatively, the test could be done away with entirely as it is checked
inside the mutex - but since the mutex is global, that may not be the best
way.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reported-by: Mateusz Guzik &lt;mguzik@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: James Morris &lt;james.l.morris@oracle.com&gt;
Signed-off-by: Paul Gortmaker &lt;paul.gortmaker@windriver.com&gt;
</content>
</entry>
<entry>
<title>KEYS: Fix a NULL pointer deref in the user-defined key type</title>
<updated>2012-08-17T19:35:05+00:00</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2011-11-15T22:09:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=7a38cd5587a22afeb4da5a1e626a47e317b38e95'/>
<id>urn:sha1:7a38cd5587a22afeb4da5a1e626a47e317b38e95</id>
<content type='text'>
commit 9f35a33b8d06263a165efe3541d9aa0cdbd70b3b upstream.

Fix a NULL pointer deref in the user-defined key type whereby updating a
negative key into a fully instantiated key will cause an oops to occur
when the code attempts to free the non-existent old payload.

This results in an oops that looks something like the following:

  BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
  IP: [&lt;ffffffff81085fa1&gt;] __call_rcu+0x11/0x13e
  PGD 3391d067 PUD 3894a067 PMD 0
  Oops: 0002 [#1] SMP
  CPU 1
  Pid: 4354, comm: keyctl Not tainted 3.1.0-fsdevel+ #1140                  /DG965RY
  RIP: 0010:[&lt;ffffffff81085fa1&gt;]  [&lt;ffffffff81085fa1&gt;] __call_rcu+0x11/0x13e
  RSP: 0018:ffff88003d591df8  EFLAGS: 00010246
  RAX: 0000000000000000 RBX: 0000000000000000 RCX: 000000000000006e
  RDX: ffffffff8161d0c0 RSI: 0000000000000000 RDI: 0000000000000000
  RBP: ffff88003d591e18 R08: 0000000000000000 R09: ffffffff8152fa6c
  R10: 0000000000000000 R11: 0000000000000300 R12: ffff88003b8f9538
  R13: ffffffff8161d0c0 R14: ffff88003b8f9d50 R15: ffff88003c69f908
  FS:  00007f97eb18c720(0000) GS:ffff88003bd00000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  CR2: 0000000000000008 CR3: 000000003d47a000 CR4: 00000000000006e0
  DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
  DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
  Process keyctl (pid: 4354, threadinfo ffff88003d590000, task ffff88003c78a040)
  Stack:
   ffff88003e0ffde0 ffff88003b8f9538 0000000000000001 ffff88003b8f9d50
   ffff88003d591e28 ffffffff810860f0 ffff88003d591e68 ffffffff8117bfea
   ffff88003d591e68 ffffffff00000000 ffff88003e0ffde1 ffff88003e0ffde0
  Call Trace:
   [&lt;ffffffff810860f0&gt;] call_rcu_sched+0x10/0x12
   [&lt;ffffffff8117bfea&gt;] user_update+0x8d/0xa2
   [&lt;ffffffff8117723a&gt;] key_create_or_update+0x236/0x270
   [&lt;ffffffff811789b1&gt;] sys_add_key+0x123/0x17e
   [&lt;ffffffff813b84bb&gt;] system_call_fastpath+0x16/0x1b

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Acked-by: Jeff Layton &lt;jlayton@redhat.com&gt;
Acked-by: Neil Horman &lt;nhorman@redhat.com&gt;
Acked-by: Steve Dickson &lt;steved@redhat.com&gt;
Acked-by: James Morris &lt;jmorris@namei.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
[PG: pre-3.0 kernels dont have kfree_rcu, so tweak accordingly]
Signed-off-by: Paul Gortmaker &lt;paul.gortmaker@windriver.com&gt;
</content>
</entry>
<entry>
<title>KEYS: Fix bug in keyctl_session_to_parent() if parent has no session keyring</title>
<updated>2011-01-06T23:08:02+00:00</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2010-09-10T08:59:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=dd1644658bbefe2626a5307e90c009720bd62623'/>
<id>urn:sha1:dd1644658bbefe2626a5307e90c009720bd62623</id>
<content type='text'>
commit 3d96406c7da1ed5811ea52a3b0905f4f0e295376 upstream.

Fix a bug in keyctl_session_to_parent() whereby it tries to check the ownership
of the parent process's session keyring whether or not the parent has a session
keyring [CVE-2010-2960].

This results in the following oops:

  BUG: unable to handle kernel NULL pointer dereference at 00000000000000a0
  IP: [&lt;ffffffff811ae4dd&gt;] keyctl_session_to_parent+0x251/0x443
  ...
  Call Trace:
   [&lt;ffffffff811ae2f3&gt;] ? keyctl_session_to_parent+0x67/0x443
   [&lt;ffffffff8109d286&gt;] ? __do_fault+0x24b/0x3d0
   [&lt;ffffffff811af98c&gt;] sys_keyctl+0xb4/0xb8
   [&lt;ffffffff81001eab&gt;] system_call_fastpath+0x16/0x1b

if the parent process has no session keyring.

If the system is using pam_keyinit then it mostly protected against this as all
processes derived from a login will have inherited the session keyring created
by pam_keyinit during the log in procedure.

To test this, pam_keyinit calls need to be commented out in /etc/pam.d/.

Reported-by: Tavis Ormandy &lt;taviso@cmpxchg8b.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Acked-by: Tavis Ormandy &lt;taviso@cmpxchg8b.com&gt;
Cc: dann frazier &lt;dannf@debian.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Paul Gortmaker &lt;paul.gortmaker@windriver.com&gt;
</content>
</entry>
<entry>
<title>KEYS: Fix RCU no-lock warning in keyctl_session_to_parent()</title>
<updated>2011-01-06T23:08:02+00:00</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2010-09-10T08:59:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=0a92e55adab5b09f9d13e5132e2678c30d34e2f9'/>
<id>urn:sha1:0a92e55adab5b09f9d13e5132e2678c30d34e2f9</id>
<content type='text'>
commit 9d1ac65a9698513d00e5608d93fca0c53f536c14 upstream.

There's an protected access to the parent process's credentials in the middle
of keyctl_session_to_parent().  This results in the following RCU warning:

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

  other info that might help us debug this:

  rcu_scheduler_active = 1, debug_locks = 0
  1 lock held by keyctl-session-/2137:
   #0:  (tasklist_lock){.+.+..}, at: [&lt;ffffffff811ae2ec&gt;] keyctl_session_to_parent+0x60/0x236

  stack backtrace:
  Pid: 2137, comm: keyctl-session- Not tainted 2.6.36-rc2-cachefs+ #1
  Call Trace:
   [&lt;ffffffff8105606a&gt;] lockdep_rcu_dereference+0xaa/0xb3
   [&lt;ffffffff811ae379&gt;] keyctl_session_to_parent+0xed/0x236
   [&lt;ffffffff811af77e&gt;] sys_keyctl+0xb4/0xb6
   [&lt;ffffffff81001eab&gt;] system_call_fastpath+0x16/0x1b

The code should take the RCU read lock to make sure the parents credentials
don't go away, even though it's holding a spinlock and has IRQ disabled.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Paul Gortmaker &lt;paul.gortmaker@windriver.com&gt;
</content>
</entry>
<entry>
<title>KEYS: Return more accurate error codes</title>
<updated>2011-01-06T23:07:33+00:00</updated>
<author>
<name>Dan Carpenter</name>
<email>error27@gmail.com</email>
</author>
<published>2010-05-17T13:42:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=d7159a6d256020f249e3038577a38280ea4576cf'/>
<id>urn:sha1:d7159a6d256020f249e3038577a38280ea4576cf</id>
<content type='text'>
commit 4d09ec0f705cf88a12add029c058b53f288cfaa2 upstream.

We were using the wrong variable here so the error codes weren't being returned
properly.  The original code returns -ENOKEY.

Signed-off-by: Dan Carpenter &lt;error27@gmail.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
Signed-off-by: Paul Gortmaker &lt;paul.gortmaker@windriver.com&gt;
</content>
</entry>
<entry>
<title>KEYS: call_sbin_request_key() must write lock keyrings before modifying them</title>
<updated>2010-05-05T13:50:24+00:00</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2010-04-30T13:32:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=896903c2f5f79f029388f033a00c3b813bc91201'/>
<id>urn:sha1:896903c2f5f79f029388f033a00c3b813bc91201</id>
<content type='text'>
call_sbin_request_key() creates a keyring and then attempts to insert a link to
the authorisation key into that keyring, but does so without holding a write
lock on the keyring semaphore.

It will normally get away with this because it hasn't told anyone that the
keyring exists yet.  The new keyring, however, has had its serial number
published, which means it can be accessed directly by that handle.

This was found by a previous patch that adds RCU lockdep checks to the code
that reads the keyring payload pointer, which includes a check that the keyring
semaphore is actually locked.

Without this patch, the following command:

	keyctl request2 user b a @s

will provoke the following lockdep warning is displayed in dmesg:

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

	other info that might help us debug this:

	rcu_scheduler_active = 1, debug_locks = 0
	2 locks held by keyctl/2076:
	 #0:  (key_types_sem){.+.+.+}, at: [&lt;ffffffff811a5b29&gt;] key_type_lookup+0x1c/0x71
	 #1:  (keyring_serialise_link_sem){+.+.+.}, at: [&lt;ffffffff811a6d1e&gt;] __key_link+0x4d/0x3c5

	stack backtrace:
	Pid: 2076, comm: keyctl Not tainted 2.6.34-rc6-cachefs #54
	Call Trace:
	 [&lt;ffffffff81051fdc&gt;] lockdep_rcu_dereference+0xaa/0xb2
	 [&lt;ffffffff811a6d1e&gt;] ? __key_link+0x4d/0x3c5
	 [&lt;ffffffff811a6e6f&gt;] __key_link+0x19e/0x3c5
	 [&lt;ffffffff811a5952&gt;] ? __key_instantiate_and_link+0xb1/0xdc
	 [&lt;ffffffff811a59bf&gt;] ? key_instantiate_and_link+0x42/0x5f
	 [&lt;ffffffff811aa0dc&gt;] call_sbin_request_key+0xe7/0x33b
	 [&lt;ffffffff8139376a&gt;] ? mutex_unlock+0x9/0xb
	 [&lt;ffffffff811a5952&gt;] ? __key_instantiate_and_link+0xb1/0xdc
	 [&lt;ffffffff811a59bf&gt;] ? key_instantiate_and_link+0x42/0x5f
	 [&lt;ffffffff811aa6fa&gt;] ? request_key_auth_new+0x1c2/0x23c
	 [&lt;ffffffff810aaf15&gt;] ? cache_alloc_debugcheck_after+0x108/0x173
	 [&lt;ffffffff811a9d00&gt;] ? request_key_and_link+0x146/0x300
	 [&lt;ffffffff810ac568&gt;] ? kmem_cache_alloc+0xe1/0x118
	 [&lt;ffffffff811a9e45&gt;] request_key_and_link+0x28b/0x300
	 [&lt;ffffffff811a89ac&gt;] sys_request_key+0xf7/0x14a
	 [&lt;ffffffff81052c0b&gt;] ? trace_hardirqs_on_caller+0x10c/0x130
	 [&lt;ffffffff81394fb9&gt;] ? trace_hardirqs_on_thunk+0x3a/0x3f
	 [&lt;ffffffff81001eeb&gt;] system_call_fastpath+0x16/0x1b

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Use RCU dereference wrappers in keyring key type code</title>
<updated>2010-05-05T13:50:12+00:00</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2010-04-30T13:32:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f0641cba7729e5e14f82d2eedc398103f5fa31b1'/>
<id>urn:sha1:f0641cba7729e5e14f82d2eedc398103f5fa31b1</id>
<content type='text'>
The keyring key type code should use RCU dereference wrappers, even when it
holds the keyring's key semaphore.

Reported-by: Vegard Nossum &lt;vegard.nossum@gmail.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Acked-by: Serge Hallyn &lt;serue@us.ibm.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: find_keyring_by_name() can gain access to a freed keyring</title>
<updated>2010-05-05T13:49:10+00:00</updated>
<author>
<name>Toshiyuki Okajima</name>
<email>toshi.okajima@jp.fujitsu.com</email>
</author>
<published>2010-04-30T13:32:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=cea7daa3589d6b550546a8c8963599f7c1a3ae5c'/>
<id>urn:sha1:cea7daa3589d6b550546a8c8963599f7c1a3ae5c</id>
<content type='text'>
find_keyring_by_name() can gain access to a keyring that has had its reference
count reduced to zero, and is thus ready to be freed.  This then allows the
dead keyring to be brought back into use whilst it is being destroyed.

The following timeline illustrates the process:

|(cleaner)                           (user)
|
| free_user(user)                    sys_keyctl()
|  |                                  |
|  key_put(user-&gt;session_keyring)     keyctl_get_keyring_ID()
|  ||	//=&gt; keyring-&gt;usage = 0        |
|  |schedule_work(&amp;key_cleanup_task)   lookup_user_key()
|  ||                                   |
|  kmem_cache_free(,user)               |
|  .                                    |[KEY_SPEC_USER_KEYRING]
|  .                                    install_user_keyrings()
|  .                                    ||
| key_cleanup() [&lt;= worker_thread()]    ||
|  |                                    ||
|  [spin_lock(&amp;key_serial_lock)]        |[mutex_lock(&amp;key_user_keyr..mutex)]
|  |                                    ||
|  atomic_read() == 0                   ||
|  |{ rb_ease(&amp;key-&gt;serial_node,) }     ||
|  |                                    ||
|  [spin_unlock(&amp;key_serial_lock)]      |find_keyring_by_name()
|  |                                    |||
|  keyring_destroy(keyring)             ||[read_lock(&amp;keyring_name_lock)]
|  ||                                   |||
|  |[write_lock(&amp;keyring_name_lock)]    ||atomic_inc(&amp;keyring-&gt;usage)
|  |.                                   ||| *** GET freeing keyring ***
|  |.                                   ||[read_unlock(&amp;keyring_name_lock)]
|  ||                                   ||
|  |list_del()                          |[mutex_unlock(&amp;key_user_k..mutex)]
|  ||                                   |
|  |[write_unlock(&amp;keyring_name_lock)]  ** INVALID keyring is returned **
|  |                                    .
|  kmem_cache_free(,keyring)            .
|                                       .
|                                       atomic_dec(&amp;keyring-&gt;usage)
v                                         *** DESTROYED ***
TIME

If CONFIG_SLUB_DEBUG=y then we may see the following message generated:

	=============================================================================
	BUG key_jar: Poison overwritten
	-----------------------------------------------------------------------------

	INFO: 0xffff880197a7e200-0xffff880197a7e200. First byte 0x6a instead of 0x6b
	INFO: Allocated in key_alloc+0x10b/0x35f age=25 cpu=1 pid=5086
	INFO: Freed in key_cleanup+0xd0/0xd5 age=12 cpu=1 pid=10
	INFO: Slab 0xffffea000592cb90 objects=16 used=2 fp=0xffff880197a7e200 flags=0x200000000000c3
	INFO: Object 0xffff880197a7e200 @offset=512 fp=0xffff880197a7e300

	Bytes b4 0xffff880197a7e1f0:  5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
	  Object 0xffff880197a7e200:  6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b jkkkkkkkkkkkkkkk

Alternatively, we may see a system panic happen, such as:

	BUG: unable to handle kernel NULL pointer dereference at 0000000000000001
	IP: [&lt;ffffffff810e61a3&gt;] kmem_cache_alloc+0x5b/0xe9
	PGD 6b2b4067 PUD 6a80d067 PMD 0
	Oops: 0000 [#1] SMP
	last sysfs file: /sys/kernel/kexec_crash_loaded
	CPU 1
	...
	Pid: 31245, comm: su Not tainted 2.6.34-rc5-nofixed-nodebug #2 D2089/PRIMERGY
	RIP: 0010:[&lt;ffffffff810e61a3&gt;]  [&lt;ffffffff810e61a3&gt;] kmem_cache_alloc+0x5b/0xe9
	RSP: 0018:ffff88006af3bd98  EFLAGS: 00010002
	RAX: 0000000000000000 RBX: 0000000000000001 RCX: ffff88007d19900b
	RDX: 0000000100000000 RSI: 00000000000080d0 RDI: ffffffff81828430
	RBP: ffffffff81828430 R08: ffff88000a293750 R09: 0000000000000000
	R10: 0000000000000001 R11: 0000000000100000 R12: 00000000000080d0
	R13: 00000000000080d0 R14: 0000000000000296 R15: ffffffff810f20ce
	FS:  00007f97116bc700(0000) GS:ffff88000a280000(0000) knlGS:0000000000000000
	CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
	CR2: 0000000000000001 CR3: 000000006a91c000 CR4: 00000000000006e0
	DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
	DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
	Process su (pid: 31245, threadinfo ffff88006af3a000, task ffff8800374414c0)
	Stack:
	 0000000512e0958e 0000000000008000 ffff880037f8d180 0000000000000001
	 0000000000000000 0000000000008001 ffff88007d199000 ffffffff810f20ce
	 0000000000008000 ffff88006af3be48 0000000000000024 ffffffff810face3
	Call Trace:
	 [&lt;ffffffff810f20ce&gt;] ? get_empty_filp+0x70/0x12f
	 [&lt;ffffffff810face3&gt;] ? do_filp_open+0x145/0x590
	 [&lt;ffffffff810ce208&gt;] ? tlb_finish_mmu+0x2a/0x33
	 [&lt;ffffffff810ce43c&gt;] ? unmap_region+0xd3/0xe2
	 [&lt;ffffffff810e4393&gt;] ? virt_to_head_page+0x9/0x2d
	 [&lt;ffffffff81103916&gt;] ? alloc_fd+0x69/0x10e
	 [&lt;ffffffff810ef4ed&gt;] ? do_sys_open+0x56/0xfc
	 [&lt;ffffffff81008a02&gt;] ? system_call_fastpath+0x16/0x1b
	Code: 0f 1f 44 00 00 49 89 c6 fa 66 0f 1f 44 00 00 65 4c 8b 04 25 60 e8 00 00 48 8b 45 00 49 01 c0 49 8b 18 48 85 db 74 0d 48 63 45 18 &lt;48&gt; 8b 04 03 49 89 00 eb 14 4c 89 f9 83 ca ff 44 89 e6 48 89 ef
	RIP  [&lt;ffffffff810e61a3&gt;] kmem_cache_alloc+0x5b/0xe9

This problem is that find_keyring_by_name does not confirm that the keyring is
valid before accepting it.

Skipping keyrings that have been reduced to a zero count seems the way to go.
To this end, use atomic_inc_not_zero() to increment the usage count and skip
the candidate keyring if that returns false.

The following script _may_ cause the bug to happen, but there's no guarantee
as the window of opportunity is small:

	#!/bin/sh
	LOOP=100000
	USER=dummy_user
	/bin/su -c "exit;" $USER || { /usr/sbin/adduser -m $USER; add=1; }
	for ((i=0; i&lt;LOOP; i++))
	do
		/bin/su -c "echo '$i' &gt; /dev/null" $USER
	done
	(( add == 1 )) &amp;&amp; /usr/sbin/userdel -r $USER
	exit

Note that the nominated user must not be in use.

An alternative way of testing this may be:

	for ((i=0; i&lt;100000; i++))
	do
		keyctl session foo /bin/true || break
	done &gt;&amp;/dev/null

as that uses a keyring named "foo" rather than relying on the user and
user-session named keyrings.

Reported-by: Toshiyuki Okajima &lt;toshi.okajima@jp.fujitsu.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Tested-by: Toshiyuki Okajima &lt;toshi.okajima@jp.fujitsu.com&gt;
Acked-by: Serge Hallyn &lt;serue@us.ibm.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>KEYS: Fix RCU handling in key_gc_keyring()</title>
<updated>2010-05-05T01:39:23+00:00</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2010-05-04T13:16:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=cf8304e8f380903de3a15dc6ebd551c9e6cf1a21'/>
<id>urn:sha1:cf8304e8f380903de3a15dc6ebd551c9e6cf1a21</id>
<content type='text'>
key_gc_keyring() needs to either hold the RCU read lock or hold the keyring
semaphore if it's going to scan the keyring's list.  Given that it only needs
to read the key list, and it's doing so under a spinlock, the RCU read lock is
the thing to use.

Furthermore, the RCU check added in e7b0a61b7929632d36cf052d9e2820ef0a9c1bfe is
incorrect as holding the spinlock on key_serial_lock is not grounds for
assuming a keyring's pointer list can be read safely.  Instead, a simple
rcu_dereference() inside of the previously mentioned RCU read lock is what we
want.

Reported-by: Serge E. Hallyn &lt;serue@us.ibm.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Acked-by: Serge Hallyn &lt;serue@us.ibm.com&gt;
Acked-by: "Paul E. McKenney" &lt;paulmck@linux.vnet.ibm.com&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
</feed>
