<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/security/keys/process_keys.c, branch v3.12.14</title>
<subtitle>Linux kernel source tree</subtitle>
<id>https://git.amat.us/linux/atom/security/keys/process_keys.c?h=v3.12.14</id>
<link rel='self' href='https://git.amat.us/linux/atom/security/keys/process_keys.c?h=v3.12.14'/>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/'/>
<updated>2013-03-12T05:44:31Z</updated>
<entry>
<title>keys: fix race with concurrent install_user_keyrings()</title>
<updated>2013-03-12T05:44:31Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2013-03-12T05:44:31Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=0da9dfdd2cd9889201bc6f6f43580c99165cd087'/>
<id>urn:sha1:0da9dfdd2cd9889201bc6f6f43580c99165cd087</id>
<content type='text'>
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;
Cc: &lt;stable@kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: James Morris &lt;james.l.morris@oracle.com&gt;
</content>
</entry>
<entry>
<title>userns: Stop oopsing in key_change_session_keyring</title>
<updated>2013-03-04T03:35:38Z</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2013-03-03T03:14:03Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=ba0e3427b03c3d1550239779eca5c1c5a53a2152'/>
<id>urn:sha1:ba0e3427b03c3d1550239779eca5c1c5a53a2152</id>
<content type='text'>
Dave Jones &lt;davej@redhat.com&gt; writes:
&gt; Just hit this on Linus' current tree.
&gt;
&gt; [   89.621770] BUG: unable to handle kernel NULL pointer dereference at 00000000000000c8
&gt; [   89.623111] IP: [&lt;ffffffff810784b0&gt;] commit_creds+0x250/0x2f0
&gt; [   89.624062] PGD 122bfd067 PUD 122bfe067 PMD 0
&gt; [   89.624901] Oops: 0000 [#1] PREEMPT SMP
&gt; [   89.625678] Modules linked in: caif_socket caif netrom bridge hidp 8021q garp stp mrp rose llc2 af_rxrpc phonet af_key binfmt_misc bnep l2tp_ppp can_bcm l2tp_core pppoe pppox can_raw scsi_transport_iscsi ppp_generic slhc nfnetlink can ipt_ULOG ax25 decnet irda nfc rds x25 crc_ccitt appletalk atm ipx p8023 psnap p8022 llc lockd sunrpc ip6t_REJECT nf_conntrack_ipv6 nf_defrag_ipv6 xt_conntrack nf_conntrack ip6table_filter ip6_tables btusb bluetooth snd_hda_codec_realtek snd_hda_intel snd_hda_codec snd_pcm vhost_net snd_page_alloc snd_timer tun macvtap usb_debug snd rfkill microcode macvlan edac_core pcspkr serio_raw kvm_amd soundcore kvm r8169 mii
&gt; [   89.637846] CPU 2
&gt; [   89.638175] Pid: 782, comm: trinity-main Not tainted 3.8.0+ #63 Gigabyte Technology Co., Ltd. GA-MA78GM-S2H/GA-MA78GM-S2H
&gt; [   89.639850] RIP: 0010:[&lt;ffffffff810784b0&gt;]  [&lt;ffffffff810784b0&gt;] commit_creds+0x250/0x2f0
&gt; [   89.641161] RSP: 0018:ffff880115657eb8  EFLAGS: 00010207
&gt; [   89.641984] RAX: 00000000000003e8 RBX: ffff88012688b000 RCX: 0000000000000000
&gt; [   89.643069] RDX: 0000000000000000 RSI: ffffffff81c32960 RDI: ffff880105839600
&gt; [   89.644167] RBP: ffff880115657ed8 R08: 0000000000000000 R09: 0000000000000000
&gt; [   89.645254] R10: 0000000000000001 R11: 0000000000000246 R12: ffff880105839600
&gt; [   89.646340] R13: ffff88011beea490 R14: ffff88011beea490 R15: 0000000000000000
&gt; [   89.647431] FS:  00007f3ac063b740(0000) GS:ffff88012b200000(0000) knlGS:0000000000000000
&gt; [   89.648660] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
&gt; [   89.649548] CR2: 00000000000000c8 CR3: 0000000122bfc000 CR4: 00000000000007e0
&gt; [   89.650635] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
&gt; [   89.651723] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
&gt; [   89.652812] Process trinity-main (pid: 782, threadinfo ffff880115656000, task ffff88011beea490)
&gt; [   89.654128] Stack:
&gt; [   89.654433]  0000000000000000 ffff8801058396a0 ffff880105839600 ffff88011beeaa78
&gt; [   89.655769]  ffff880115657ef8 ffffffff812c7d9b ffffffff82079be0 0000000000000000
&gt; [   89.657073]  ffff880115657f28 ffffffff8106c665 0000000000000002 ffff880115657f58
&gt; [   89.658399] Call Trace:
&gt; [   89.658822]  [&lt;ffffffff812c7d9b&gt;] key_change_session_keyring+0xfb/0x140
&gt; [   89.659845]  [&lt;ffffffff8106c665&gt;] task_work_run+0xa5/0xd0
&gt; [   89.660698]  [&lt;ffffffff81002911&gt;] do_notify_resume+0x71/0xb0
&gt; [   89.661581]  [&lt;ffffffff816c9a4a&gt;] int_signal+0x12/0x17
&gt; [   89.662385] Code: 24 90 00 00 00 48 8b b3 90 00 00 00 49 8b 4c 24 40 48 39 f2 75 08 e9 83 00 00 00 48 89 ca 48 81 fa 60 29 c3 81 0f 84 41 fe ff ff &lt;48&gt; 8b 8a c8 00 00 00 48 39 ce 75 e4 3b 82 d0 00 00 00 0f 84 4b
&gt; [   89.667778] RIP  [&lt;ffffffff810784b0&gt;] commit_creds+0x250/0x2f0
&gt; [   89.668733]  RSP &lt;ffff880115657eb8&gt;
&gt; [   89.669301] CR2: 00000000000000c8
&gt;
&gt; My fastest trinity induced oops yet!
&gt;
&gt;
&gt; Appears to be..
&gt;
&gt;                 if ((set_ns == subset_ns-&gt;parent)  &amp;&amp;
&gt;      850:       48 8b 8a c8 00 00 00    mov    0xc8(%rdx),%rcx
&gt;
&gt; from the inlined cred_cap_issubset

By historical accident we have been reading trying to set new-&gt;user_ns
from new-&gt;user_ns.  Which is totally silly as new-&gt;user_ns is NULL (as
is every other field in new except session_keyring at that point).

The intent is clearly to copy all of the fields from old to new so copy
old-&gt;user_ns into  into new-&gt;user_ns.

Cc: stable@vger.kernel.org
Reported-by: Dave Jones &lt;davej@redhat.com&gt;
Tested-by: Dave Jones &lt;davej@redhat.com&gt;
Acked-by: Serge Hallyn &lt;serge.hallyn@canonical.com&gt;
Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
</content>
</entry>
<entry>
<title>KEYS: Revert one application of "Fix unreachable code" patch</title>
<updated>2013-02-21T15:56:25Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2013-02-21T12:00:25Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=fe9453a1dcb5fb146f9653267e78f4a558066f6f'/>
<id>urn:sha1:fe9453a1dcb5fb146f9653267e78f4a558066f6f</id>
<content type='text'>
A patch to fix some unreachable code in search_my_process_keyrings() got
applied twice by two different routes upstream as commits e67eab39bee2
and b010520ab3d2 (both "fix unreachable code").

Unfortunately, the second application removed something it shouldn't
have and this wasn't detected by GIT.  This is due to the patch not
having sufficient lines of context to distinguish the two places of
application.

The effect of this is relatively minor: inside the kernel, the keyring
search routines may search multiple keyrings and then prioritise the
errors if no keys or negative keys are found in any of them.  With the
extra deletion, the presence of a negative key in the thread keyring
(causing ENOKEY) is incorrectly overridden by an error searching the
process keyring.

So revert the second application of the patch.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Cc: Jiri Kosina &lt;jkosina@suse.cz&gt;
Cc: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>keys: fix unreachable code</title>
<updated>2012-12-21T01:40:21Z</updated>
<author>
<name>Alan Cox</name>
<email>alan@linux.intel.com</email>
</author>
<published>2012-12-20T23:05:54Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=e67eab39bee26f509d38d00ca1a8f24b63f46a31'/>
<id>urn:sha1:e67eab39bee26f509d38d00ca1a8f24b63f46a31</id>
<content type='text'>
We set ret to NULL then test it. Remove the bogus test

Signed-off-by: Alan Cox &lt;alan@linux.intel.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security</title>
<updated>2012-12-16T23:40:50Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-12-16T23:40:50Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=2a74dbb9a86e8102dcd07d284135b4530a84826e'/>
<id>urn:sha1:2a74dbb9a86e8102dcd07d284135b4530a84826e</id>
<content type='text'>
Pull security subsystem updates from James Morris:
 "A quiet cycle for the security subsystem with just a few maintenance
  updates."

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
  Smack: create a sysfs mount point for smackfs
  Smack: use select not depends in Kconfig
  Yama: remove locking from delete path
  Yama: add RCU to drop read locking
  drivers/char/tpm: remove tasklet and cleanup
  KEYS: Use keyring_alloc() to create special keyrings
  KEYS: Reduce initial permissions on keys
  KEYS: Make the session and process keyrings per-thread
  seccomp: Make syscall skipping and nr changes more consistent
  key: Fix resource leak
  keys: Fix unreachable code
  KEYS: Add payload preparsing opportunity prior to key instantiate or update
</content>
</entry>
<entry>
<title>Merge branch 'master' into for-next</title>
<updated>2012-10-28T18:29:19Z</updated>
<author>
<name>Jiri Kosina</name>
<email>jkosina@suse.cz</email>
</author>
<published>2012-10-28T18:28:52Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=3bd7bf1f0fe14f591c089ae61bbfa9bd356f178a'/>
<id>urn:sha1:3bd7bf1f0fe14f591c089ae61bbfa9bd356f178a</id>
<content type='text'>
Sync up with Linus' tree to be able to apply Cesar's patch
against newer version of the code.

Signed-off-by: Jiri Kosina &lt;jkosina@suse.cz&gt;
</content>
</entry>
<entry>
<title>keys: Fix unreachable code</title>
<updated>2012-10-25T16:00:27Z</updated>
<author>
<name>Alan Cox</name>
<email>alan@linux.intel.com</email>
</author>
<published>2012-10-25T14:23:35Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=b010520ab3d2c05eb444ed5e01fe6c33842f597a'/>
<id>urn:sha1:b010520ab3d2c05eb444ed5e01fe6c33842f597a</id>
<content type='text'>
We set ret to NULL then test it. Remove the bogus test

Signed-off-by: Alan Cox &lt;alan@linux.intel.com&gt;
Signed-off-by: Jiri Kosina &lt;jkosina@suse.cz&gt;
</content>
</entry>
<entry>
<title>KEYS: Reduce initial permissions on keys</title>
<updated>2012-10-02T18:24:56Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2012-10-02T18:24:56Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=96b5c8fea6c0861621051290d705ec2e971963f1'/>
<id>urn:sha1:96b5c8fea6c0861621051290d705ec2e971963f1</id>
<content type='text'>
Reduce the initial permissions on new keys to grant the possessor everything,
view permission only to the user (so the keys can be seen in /proc/keys) and
nothing else.

This gives the creator a chance to adjust the permissions mask before other
processes can access the new key or create a link to it.

To aid with this, keyring_alloc() now takes a permission argument rather than
setting the permissions itself.

The following permissions are now set:

 (1) The user and user-session keyrings grant the user that owns them full
     permissions and grant a possessor everything bar SETATTR.

 (2) The process and thread keyrings grant the possessor full permissions but
     only grant the user VIEW.  This permits the user to see them in
     /proc/keys, but not to do anything with them.

 (3) Anonymous session keyrings grant the possessor full permissions, but only
     grant the user VIEW and READ.  This means that the user can see them in
     /proc/keys and can list them, but nothing else.  Possibly READ shouldn't
     be provided either.

 (4) Named session keyrings grant everything an anonymous session keyring does,
     plus they grant the user LINK permission.  The whole point of named
     session keyrings is that others can also subscribe to them.  Possibly this
     should be a separate permission to LINK.

 (5) The temporary session keyring created by call_sbin_request_key() gets the
     same permissions as an anonymous session keyring.

 (6) Keys created by add_key() get VIEW, SEARCH, LINK and SETATTR for the
     possessor, plus READ and/or WRITE if the key type supports them.  The used
     only gets VIEW now.

 (7) Keys created by request_key() now get the same as those created by
     add_key().

Reported-by: Lennart Poettering &lt;lennart@poettering.net&gt;
Reported-by: Stef Walter &lt;stefw@redhat.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
</content>
</entry>
<entry>
<title>KEYS: Make the session and process keyrings per-thread</title>
<updated>2012-10-02T18:24:29Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2012-10-02T18:24:29Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=3a50597de8635cd05133bd12c95681c82fe7b878'/>
<id>urn:sha1:3a50597de8635cd05133bd12c95681c82fe7b878</id>
<content type='text'>
Make the session keyring per-thread rather than per-process, but still
inherited from the parent thread to solve a problem with PAM and gdm.

The problem is that join_session_keyring() will reject attempts to change the
session keyring of a multithreaded program but gdm is now multithreaded before
it gets to the point of starting PAM and running pam_keyinit to create the
session keyring.  See:

	https://bugs.freedesktop.org/show_bug.cgi?id=49211

The reason that join_session_keyring() will only change the session keyring
under a single-threaded environment is that it's hard to alter the other
thread's credentials to effect the change in a multi-threaded program.  The
problems are such as:

 (1) How to prevent two threads both running join_session_keyring() from
     racing.

 (2) Another thread's credentials may not be modified directly by this process.

 (3) The number of threads is uncertain whilst we're not holding the
     appropriate spinlock, making preallocation slightly tricky.

 (4) We could use TIF_NOTIFY_RESUME and key_replace_session_keyring() to get
     another thread to replace its keyring, but that means preallocating for
     each thread.

A reasonable way around this is to make the session keyring per-thread rather
than per-process and just document that if you want a common session keyring,
you must get it before you spawn any threads - which is the current situation
anyway.

Whilst we're at it, we can the process keyring behave in the same way.  This
means we can clean up some of the ickyness in the creds code.

Basically, after this patch, the session, process and thread keyrings are about
inheritance rules only and not about sharing changes of keyring.

Reported-by: Mantas M. &lt;grawity@gmail.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Tested-by: Ray Strode &lt;rstrode@redhat.com&gt;
</content>
</entry>
<entry>
<title>keys: Fix unreachable code</title>
<updated>2012-09-28T11:20:02Z</updated>
<author>
<name>Alan Cox</name>
<email>alan@linux.intel.com</email>
</author>
<published>2012-09-28T11:20:02Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=631527703d1aa2f0c5dc2af0d998f4da95c83f0e'/>
<id>urn:sha1:631527703d1aa2f0c5dc2af0d998f4da95c83f0e</id>
<content type='text'>
We set ret to NULL then test it. Remove the bogus test

Signed-off-by: Alan Cox &lt;alan@linux.intel.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
</content>
</entry>
</feed>
