From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "David Howells" <dhowells@redhat.com>,
"Eric Biggers" <ebiggers@google.com>
Subject: [PATCH 3.2 94/94] KEYS: add missing permission check for request_key() destination
Date: Thu, 28 Dec 2017 16:59:12 +0000 [thread overview]
Message-ID: <lsq.1514480352.626935849@decadent.org.uk> (raw)
In-Reply-To: <lsq.1514480348.981935392@decadent.org.uk>
3.2.97-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <ebiggers@google.com>
commit 4dca6ea1d9432052afb06baf2e3ae78188a4410b upstream.
When the request_key() syscall is not passed a destination keyring, it
links the requested key (if constructed) into the "default" request-key
keyring. This should require Write permission to the keyring. However,
there is actually no permission check.
This can be abused to add keys to any keyring to which only Search
permission is granted. This is because Search permission allows joining
the keyring. keyctl_set_reqkey_keyring(KEY_REQKEY_DEFL_SESSION_KEYRING)
then will set the default request-key keyring to the session keyring.
Then, request_key() can be used to add keys to the keyring.
Both negatively and positively instantiated keys can be added using this
method. Adding negative keys is trivial. Adding a positive key is a
bit trickier. It requires that either /sbin/request-key positively
instantiates the key, or that another thread adds the key to the process
keyring at just the right time, such that request_key() misses it
initially but then finds it in construct_alloc_key().
Fix this bug by checking for Write permission to the keyring in
construct_get_dest_keyring() when the default keyring is being used.
We don't do the permission check for non-default keyrings because that
was already done by the earlier call to lookup_user_key(). Also,
request_key_and_link() is currently passed a 'struct key *' rather than
a key_ref_t, so the "possessed" bit is unavailable.
We also don't do the permission check for the "requestor keyring", to
continue to support the use case described by commit 8bbf4976b59f
("KEYS: Alter use of key instantiation link-to-keyring argument") where
/sbin/request-key recursively calls request_key() to add keys to the
original requestor's destination keyring. (I don't know of any users
who actually do that, though...)
Fixes: 3e30148c3d52 ("[PATCH] Keys: Make request-key create an authorisation key")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
[bwh: Backported to 3.2:
- s/KEY_NEED_WRITE/KEY_WRITE/
- Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
security/keys/request_key.c | 46 ++++++++++++++++++++++++++++++++++++---------
1 file changed, 37 insertions(+), 9 deletions(-)
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -267,11 +267,12 @@ static int construct_key(struct key *key
* The keyring selected is returned with an extra reference upon it which the
* caller must release.
*/
-static void construct_get_dest_keyring(struct key **_dest_keyring)
+static int construct_get_dest_keyring(struct key **_dest_keyring)
{
struct request_key_auth *rka;
const struct cred *cred = current_cred();
struct key *dest_keyring = *_dest_keyring, *authkey;
+ int ret;
kenter("%p", dest_keyring);
@@ -280,6 +281,8 @@ static void construct_get_dest_keyring(s
/* the caller supplied one */
key_get(dest_keyring);
} else {
+ bool do_perm_check = true;
+
/* use a default keyring; falling through the cases until we
* find one that we actually have */
switch (cred->jit_keyring) {
@@ -294,8 +297,10 @@ static void construct_get_dest_keyring(s
dest_keyring =
key_get(rka->dest_keyring);
up_read(&authkey->sem);
- if (dest_keyring)
+ if (dest_keyring) {
+ do_perm_check = false;
break;
+ }
}
case KEY_REQKEY_DEFL_THREAD_KEYRING:
@@ -330,11 +335,29 @@ static void construct_get_dest_keyring(s
default:
BUG();
}
+
+ /*
+ * Require Write permission on the keyring. This is essential
+ * because the default keyring may be the session keyring, and
+ * joining a keyring only requires Search permission.
+ *
+ * However, this check is skipped for the "requestor keyring" so
+ * that /sbin/request-key can itself use request_key() to add
+ * keys to the original requestor's destination keyring.
+ */
+ if (dest_keyring && do_perm_check) {
+ ret = key_permission(make_key_ref(dest_keyring, 1),
+ KEY_WRITE);
+ if (ret) {
+ key_put(dest_keyring);
+ return ret;
+ }
+ }
}
*_dest_keyring = dest_keyring;
kleave(" [dk %d]", key_serial(dest_keyring));
- return;
+ return 0;
}
/*
@@ -449,11 +472,15 @@ static struct key *construct_key_and_lin
kenter("");
- user = key_user_lookup(current_fsuid(), current_user_ns());
- if (!user)
- return ERR_PTR(-ENOMEM);
+ ret = construct_get_dest_keyring(&dest_keyring);
+ if (ret)
+ goto error;
- construct_get_dest_keyring(&dest_keyring);
+ user = key_user_lookup(current_fsuid(), current_user_ns());
+ if (!user) {
+ ret = -ENOMEM;
+ goto error_put_dest_keyring;
+ }
ret = construct_alloc_key(type, description, dest_keyring, flags, user,
&key);
@@ -469,7 +496,7 @@ static struct key *construct_key_and_lin
} else if (ret == -EINPROGRESS) {
ret = 0;
} else {
- goto couldnt_alloc_key;
+ goto error_put_dest_keyring;
}
key_put(dest_keyring);
@@ -479,8 +506,9 @@ static struct key *construct_key_and_lin
construction_failed:
key_negate_and_link(key, key_negative_timeout, NULL, NULL);
key_put(key);
-couldnt_alloc_key:
+error_put_dest_keyring:
key_put(dest_keyring);
+error:
kleave(" = %d", ret);
return ERR_PTR(ret);
}
next prev parent reply other threads:[~2017-12-28 18:26 UTC|newest]
Thread overview: 96+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-28 16:59 [PATCH 3.2 00/94] 3.2.97-rc1 review Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 65/94] ALSA: timer: Add missing mutex lock for compat ioctls Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 02/94] spi: uapi: spidev: add missing ioctl header Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 76/94] ALSA: timer: Protect the whole snd_timer_close() with open race Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 36/94] ALSA: usx2y: Suppress kernel warning at page allocation failures Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 54/94] ecryptfs: fix dereference of NULL user_key_payload Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 23/94] KEYS: prevent creating a different user's keyrings Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 75/94] l2tp: don't use l2tp_tunnel_find() in l2tp_ip and l2tp_ip6 Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 45/94] crypto: shash - Fix zero-length shash ahash digest crash Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 05/94] USB: serial: option: add support for TP-Link LTE module Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 55/94] iommu/amd: Finish TLB flush in amd_iommu_unmap() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 21/94] KEYS: fix key refcount leak in keyctl_assume_authority() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 74/94] l2tp: hold tunnel socket when handling control frames in l2tp_ip and l2tp_ip6 Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 10/94] usb: pci-quirks.c: Corrected timeout values used in handshake Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 50/94] scsi: libiscsi: fix shifting of DID_REQUEUE host byte Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 61/94] can: esd_usb2: Fix can_dlc value for received RTR, frames Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 52/94] KEYS: encrypted: fix dereference of NULL user_key_payload Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 35/94] l2tp: fix l2tp_eth module loading Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 30/94] packet: only test po->has_vnet_hdr once in packet_snd Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 59/94] usb: cdc_acm: Add quirk for Elatec TWN3 Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 42/94] lsm: fix smack_inode_removexattr and xattr_getsecurity memleak Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 87/94] USB: core: prevent malicious bNumInterfaces overflow Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 82/94] MIPS: AR7: Ensure that serial ports are properly set up Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 22/94] KEYS: fix key refcount leak in keyctl_read_key() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 08/94] usb: Increase quirk delay for USB devices Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 67/94] macvtap: fix TUNSETSNDBUF values > 64k Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 86/94] Bluetooth: bnep: bnep_add_connection() should verify that it's dealing with l2cap socket Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 79/94] ALSA: seq: Avoid invalid lockdep class warning Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 06/94] uwb: ensure that endpoint is interrupt Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 48/94] usb: renesas_usbhs: Fix DMAC sequence for receiving zero-length packet Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 53/94] FS-Cache: fix dereference of NULL user_key_payload Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 58/94] scsi: zfcp: fix erp_action use-before-initialize in REC action trace Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 89/94] security: Fix mode test in selinux_ptrace_access_check() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 33/94] kvm/x86: Handle async PF in RCU read-side critical sections Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 11/94] s390/mm: fix write access check in gup_huge_pmd() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 18/94] USB: gadgetfs: Fix crash caused by inadequate synchronization Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 68/94] tun/tap: sanitize TUNSETSNDBUF input Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 57/94] net: enable interface alias removal via rtnl Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 71/94] KEYS: trusted: fix writing past end of buffer in trusted_read() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 24/94] vfs: Return -ENXIO for negative SEEK_HOLE / SEEK_DATA offsets Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 25/94] USB: dummy-hcd: fix infinite-loop resubmission bug Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 64/94] l2tp: hold tunnel in pppol2tp_connect() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 09/94] xhci: fix finding correct bus_state structure for USB 3.1 hosts Ben Hutchings
2017-12-28 16:59 ` Ben Hutchings [this message]
2017-12-28 16:59 ` [PATCH 3.2 38/94] kernel/params.c: align add_sysfs_param documentation with code Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 92/94] crypto: salsa20 - fix blkcipher_walk API usage Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 62/94] ipsec: Fix aborted xfrm policy dump crash Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 04/94] USB: serial: ftdi_sio: add id for Cypress WICED dev board Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 07/94] uwb: properly check kthread_run return value Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 44/94] ALSA: seq: Fix copy_from_user() call inside lock Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 80/94] ALSA: seq: Fix OSS sysex delivery in OSS emulation Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 60/94] usb: quirks: add quirk for WORLDE MINI MIDI keyboard Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 01/94] tile: array underflow in setup_maxnodemem() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 66/94] ALSA: seq: Fix nested rwsem annotation for lockdep splat Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 31/94] sched/sysctl: Check user input value of sysctl_sched_time_avg Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 15/94] usb-storage: unusual_devs entry to fix write-access regression for Seagate external drives Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 77/94] ALSA: timer: Limit max instances per timer Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 14/94] Input: uinput - avoid FF flush when destroying device Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 17/94] USB: gadgetfs: fix copy_to_user while holding spinlock Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 37/94] scsi: sd: Implement blacklist option for WRITE SAME w/ UNMAP Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 26/94] USB: gadgetfs, dummy-hcd, net2280: fix locking for callbacks Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 27/94] USB: dummy-hcd: Fix erroneous synchronization change Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 78/94] ARM: 8720/1: ensure dump_instr() checks addr_limit Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 88/94] KVM: VMX: remove I/O port 0x80 bypass on Intel hosts Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 72/94] ocfs2: fstrim: Fix start offset of first cluster group during fstrim Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 91/94] KVM: Fix stack-out-of-bounds read in write_mmio Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 41/94] Smack: remove unneeded NULL-termination from securtity label Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 81/94] x86/oprofile/ppro: Do not use __this_cpu*() in preemptible context Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 32/94] KVM: Do not take reference to mm during async #PF Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 93/94] crypto: hmac - require that the underlying hash algorithm is unkeyed Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 85/94] Bluetooth: cmtp: cmtp_add_connection() should verify that it's dealing with l2cap socket Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 73/94] l2tp: hold socket before dropping lock in l2tp_ip{, 6}_recv() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 19/94] KEYS: fix cred refcount leak in request_key_auth_new() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 70/94] KEYS: trusted: sanitize all key material Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 20/94] KEYS: don't revoke uninstantiated key in request_key_auth_new() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 40/94] sh: sh7757: remove nonexistent GPIO_PT[JLNQ]7_RESV to fix pinctrl registration Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 84/94] Bluetooth: hidp: verify l2cap sockets Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 34/94] staging: iio: ade7759: fix signed extension bug on shift of a u8 Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 46/94] more bio_map_user_iov() leak fixes Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 51/94] KVM: nVMX: fix guest CR4 loading when emulating L2 to L1 exit Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 56/94] l2tp: check ps->sock before running pppol2tp_session_ioctl() Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 69/94] tcp: fix tcp_mtu_probe() vs highest_sack Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 90/94] ptrace: change __ptrace_unlink() to clear ->ptrace under ->siglock Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 16/94] usb: gadget: fix spinlock dead lock in gadgetfs Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 43/94] kvm/x86: Avoid async PF preempting the kernel incorrectly Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 28/94] usb: renesas_usbhs: fix the BCLR setting condition for non-DCP pipe Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 03/94] scsi: lpfc: Don't return internal MBXERR_ERROR code from probe function Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 13/94] crypto: talitos - fix sha224 Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 49/94] ALSA: caiaq: Fix stray URB at probe error path Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 63/94] sctp: fix a type cast warnings that causes a_rwnd gets the wrong value Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 12/94] USB: serial: cp210x: add support for ELV TFD500 Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 47/94] USB: dummy-hcd: Fix deadlock caused by disconnect detection Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 29/94] usb: renesas_usbhs: fix usbhsf_fifo_clear() for RX direction Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 83/94] dccp: CVE-2017-8824: use-after-free in DCCP code Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 39/94] sh: sh7722: remove nonexistent GPIO_PTQ7 to fix pinctrl registration Ben Hutchings
2017-12-28 19:26 ` [PATCH 3.2 00/94] 3.2.97-rc1 review 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=lsq.1514480352.626935849@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=ebiggers@google.com \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®