From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, David Howells <dhowells@redhat.com>,
Mateusz Guzik <mguzik@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
James Morris <james.l.morris@oracle.com>
Subject: [ 16/21] keys: fix race with concurrent install_user_keyrings()
Date: Tue, 12 Mar 2013 15:44:18 -0700 [thread overview]
Message-ID: <20130312223246.995719035@linuxfoundation.org> (raw)
In-Reply-To: <20130312223245.109098379@linuxfoundation.org>
3.0-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <dhowells@redhat.com>
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
=============================== ===============================
==>call install_user_keyrings();
if (!cred->user->session_keyring)
==>call install_user_keyrings()
...
user->uid_keyring = uid_keyring;
if (user->uid_keyring)
return 0;
<==
key = cred->user->session_keyring [== NULL]
user->session_keyring = session_keyring;
atomic_inc(&key->usage); [oops]
At the point thread A dereferences cred->user->session_keyring, thread B
hasn't updated user->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->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 <dhowells@redhat.com>
Reported-by: Mateusz Guzik <mguzik@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
security/keys/process_keys.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/security/keys/process_keys.c
+++ b/security/keys/process_keys.c
@@ -54,7 +54,7 @@ int install_user_keyrings(void)
kenter("%p{%u}", user, user->uid);
- if (user->uid_keyring) {
+ if (user->uid_keyring && user->session_keyring) {
kleave(" = 0 [exist]");
return 0;
}
next prev parent reply other threads:[~2013-03-12 22:47 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-12 22:44 [ 00/21] 3.0.69-stable review Greg Kroah-Hartman
2013-03-12 22:44 ` [ 01/21] ARM: VFP: fix emulation of second VFP instruction Greg Kroah-Hartman
2013-03-12 22:44 ` [ 02/21] ARM: fix scheduling while atomic warning in alignment handling code Greg Kroah-Hartman
2013-03-12 22:44 ` [ 03/21] SCSI: dc395x: uninitialized variable in device_alloc() Greg Kroah-Hartman
2013-03-12 22:44 ` [ 04/21] target/pscsi: Fix page increment Greg Kroah-Hartman
2013-03-16 2:10 ` Ben Hutchings
2013-03-18 5:35 ` Asias He
2013-03-18 21:00 ` Nicholas A. Bellinger
2013-03-18 23:30 ` Ben Hutchings
2013-03-19 0:56 ` Asias He
2013-03-19 1:18 ` Ben Hutchings
2013-03-19 3:18 ` Nicholas A. Bellinger
2013-03-12 22:44 ` [ 05/21] btrfs: Init io_lock after cloning btrfs device struct Greg Kroah-Hartman
2013-03-12 22:44 ` [ 06/21] cifs: ensure that cifs_get_root() only traverses directories Greg Kroah-Hartman
2013-03-12 22:44 ` [ 07/21] SUNRPC: Dont start the retransmission timer when out of socket space Greg Kroah-Hartman
2013-03-12 22:44 ` [ 08/21] hw_random: make buffer usable in scatterlist Greg Kroah-Hartman
2013-03-12 22:44 ` [ 09/21] ath9k: fix RSSI dummy marker value Greg Kroah-Hartman
2013-03-12 22:44 ` [ 10/21] md: raid0: fix error return from create_stripe_zones Greg Kroah-Hartman
2013-03-12 22:44 ` [ 11/21] hwmon: (sht15) Check return value of regulator_enable() Greg Kroah-Hartman
2013-03-16 4:15 ` Ben Hutchings
2013-03-16 13:33 ` Guenter Roeck
2013-03-12 22:44 ` [ 12/21] drm/radeon: add primary dac adj quirk for R200 board Greg Kroah-Hartman
2013-03-12 22:44 ` [ 13/21] ALSA: ice1712: Initialize card->private_data properly Greg Kroah-Hartman
2013-03-12 22:44 ` [ 14/21] ALSA: vmaster: Fix slave change notification Greg Kroah-Hartman
2013-03-12 22:44 ` [ 15/21] e1000e: fix pci-device enable-counter balance Greg Kroah-Hartman
2013-03-12 22:44 ` Greg Kroah-Hartman [this message]
2013-03-12 22:44 ` [ 17/21] vfs: fix pipe counter breakage Greg Kroah-Hartman
2013-03-12 22:44 ` [ 18/21] Fix memory leak in cpufreq stats Greg Kroah-Hartman
2013-03-12 22:44 ` [ 19/21] ftrace: Update the kconfig for DYNAMIC_FTRACE Greg Kroah-Hartman
2013-03-12 22:44 ` [ 20/21] decnet: Fix disappearing sysctl entries Greg Kroah-Hartman
[not found] ` <B401117D-23F6-4911-8D72-344EE1A022F6@usgs.gov>
2013-03-12 23:04 ` Eric W. Biederman
[not found] ` <3EDA829E-3898-4626-9C17-CCE31E8C0554@usgs.gov>
2013-03-13 20:05 ` Eric W. Biederman
2013-03-12 23:06 ` Greg Kroah-Hartman
2013-03-12 22:44 ` [ 21/21] dmi_scan: fix missing check for _DMI_ signature in smbios_present() Greg Kroah-Hartman
2013-03-13 3:56 ` [ 00/21] 3.0.69-stable review Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130312223246.995719035@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=james.l.morris@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mguzik@redhat.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).