linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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>,
	Mimi Zohar <zohar@linux.vnet.ibm.com>,
	linux-ima-devel@lists.sourceforge.net
Subject: [PATCH 4.10 01/24] KEYS: Disallow keyrings beginning with . to be joined as session keyrings
Date: Tue, 25 Apr 2017 16:09:10 +0100	[thread overview]
Message-ID: <20170425150834.314713682@linuxfoundation.org> (raw)
In-Reply-To: <20170425150834.258486705@linuxfoundation.org>

4.10-stable review patch.  If anyone has any objections, please let me know.

------------------

From: David Howells <dhowells@redhat.com>

commit ee8f844e3c5a73b999edf733df1c529d6503ec2f upstream.

This fixes CVE-2016-9604.

Keyrings whose name begin with a '.' are special internal keyrings and so
userspace isn't allowed to create keyrings by this name to prevent
shadowing.  However, the patch that added the guard didn't fix
KEYCTL_JOIN_SESSION_KEYRING.  Not only can that create dot-named keyrings,
it can also subscribe to them as a session keyring if they grant SEARCH
permission to the user.

This, for example, allows a root process to set .builtin_trusted_keys as
its session keyring, at which point it has full access because now the
possessor permissions are added.  This permits root to add extra public
keys, thereby bypassing module verification.

This also affects kexec and IMA.

This can be tested by (as root):

	keyctl session .builtin_trusted_keys
	keyctl add user a a @s
	keyctl list @s

which on my test box gives me:

	2 keys in keyring:
	180010936: ---lswrv     0     0 asymmetric: Build time autogenerated kernel key: ae3d4a31b82daa8e1a75b49dc2bba949fd992a05
	801382539: --alswrv     0     0 user: a


Fix this by rejecting names beginning with a '.' in the keyctl.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
cc: linux-ima-devel@lists.sourceforge.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 security/keys/keyctl.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -271,7 +271,8 @@ error:
  * Create and join an anonymous session keyring or join a named session
  * keyring, creating it if necessary.  A named session keyring must have Search
  * permission for it to be joined.  Session keyrings without this permit will
- * be skipped over.
+ * be skipped over.  It is not permitted for userspace to create or join
+ * keyrings whose name begin with a dot.
  *
  * If successful, the ID of the joined session keyring will be returned.
  */
@@ -288,12 +289,16 @@ long keyctl_join_session_keyring(const c
 			ret = PTR_ERR(name);
 			goto error;
 		}
+
+		ret = -EPERM;
+		if (name[0] == '.')
+			goto error_name;
 	}
 
 	/* join the session */
 	ret = join_session_keyring(name);
+error_name:
 	kfree(name);
-
 error:
 	return ret;
 }

  reply	other threads:[~2017-04-25 15:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-25 15:09 [PATCH 4.10 00/24] 4.10.13-stable review Greg Kroah-Hartman
2017-04-25 15:09 ` Greg Kroah-Hartman [this message]
2017-04-25 15:09 ` [PATCH 4.10 02/24] KEYS: Change the name of the dead type to ".dead" to prevent user access Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 03/24] KEYS: fix keyctl_set_reqkey_keyring() to not leak thread keyrings Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 04/24] tracing: Allocate the snapshot buffer before enabling probe Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 05/24] HID: wacom: Treat HID_DG_TOOLSERIALNUMBER as unsigned Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 06/24] ring-buffer: Have ring_buffer_iter_empty() return true when empty Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 07/24] mm: prevent NR_ISOLATE_* stats from going negative Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 08/24] cifs: Do not send echoes before Negotiate is complete Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 09/24] CIFS: remove bad_network_name flag Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 10/24] mmc: dw_mmc: silent verbose log when calling from PM context Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 11/24] s390/mm: fix CMMA vs KSM vs others Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 12/24] Input: elantech - add Fujitsu Lifebook E547 to force crc_enabled Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 13/24] ACPI / power: Avoid maybe-uninitialized warning Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 14/24] mmc: dw_mmc: Dont allow Runtime PM for SDIO cards Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 15/24] mmc: sdhci-esdhc-imx: increase the pad I/O drive strength for DDR50 card Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 16/24] ubifs: Fix RENAME_WHITEOUT support Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 17/24] ubifs: Fix O_TMPFILE corner case in ubifs_link() Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 18/24] mac80211: reject ToDS broadcast data frames Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 19/24] mac80211: fix MU-MIMO follow-MAC mode Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 20/24] x86/mce: Make the MCE notifier a blocking one Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 21/24] ubi/upd: Always flush after prepared for an update Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 22/24] powerpc/kprobe: Fix oops when kprobed on stdu instruction Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 23/24] x86/mce/AMD: Give a name to MCA bank 3 when accessed with legacy MSRs Greg Kroah-Hartman
2017-04-25 15:09 ` [PATCH 4.10 24/24] device-dax: switch to srcu, fix rcu_read_lock() vs pte allocation Greg Kroah-Hartman
2017-04-25 18:24 ` [PATCH 4.10 00/24] 4.10.13-stable review Shuah Khan
2017-04-26  2:23 ` Guenter Roeck

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=20170425150834.314713682@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=dhowells@redhat.com \
    --cc=linux-ima-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zohar@linux.vnet.ibm.com \
    /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).