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>,
"Mimi Zohar" <zohar@linux.vnet.ibm.com>,
"James Morris" <james.l.morris@oracle.com>,
"Eric Biggers" <ebiggers@google.com>
Subject: [PATCH 3.2 71/94] KEYS: trusted: fix writing past end of buffer in trusted_read()
Date: Thu, 28 Dec 2017 16:59:12 +0000 [thread overview]
Message-ID: <lsq.1514480352.620909706@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 a3c812f7cfd80cf51e8f5b7034f7418f6beb56c1 upstream.
When calling keyctl_read() on a key of type "trusted", if the
user-supplied buffer was too small, the kernel ignored the buffer length
and just wrote past the end of the buffer, potentially corrupting
userspace memory. Fix it by instead returning the size required, as per
the documentation for keyctl_read().
We also don't even fill the buffer at all in this case, as this is
slightly easier to implement than doing a short read, and either
behavior appears to be permitted. It also makes it match the behavior
of the "encrypted" key type.
Fixes: d00a1c72f7f4 ("keys: add new trusted key-type")
Reported-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Reviewed-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
security/keys/trusted.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
--- a/security/keys/trusted.c
+++ b/security/keys/trusted.c
@@ -1089,20 +1089,21 @@ static long trusted_read(const struct ke
p = rcu_dereference_key(key);
if (!p)
return -EINVAL;
- if (!buffer || buflen <= 0)
- return 2 * p->blob_len;
- ascii_buf = kmalloc(2 * p->blob_len, GFP_KERNEL);
- if (!ascii_buf)
- return -ENOMEM;
- bufp = ascii_buf;
- for (i = 0; i < p->blob_len; i++)
- bufp = hex_byte_pack(bufp, p->blob[i]);
- if ((copy_to_user(buffer, ascii_buf, 2 * p->blob_len)) != 0) {
+ if (buffer && buflen >= 2 * p->blob_len) {
+ ascii_buf = kmalloc(2 * p->blob_len, GFP_KERNEL);
+ if (!ascii_buf)
+ return -ENOMEM;
+
+ bufp = ascii_buf;
+ for (i = 0; i < p->blob_len; i++)
+ bufp = hex_byte_pack(bufp, p->blob[i]);
+ if (copy_to_user(buffer, ascii_buf, 2 * p->blob_len) != 0) {
+ kzfree(ascii_buf);
+ return -EFAULT;
+ }
kzfree(ascii_buf);
- return -EFAULT;
}
- kzfree(ascii_buf);
return 2 * p->blob_len;
}
next prev parent reply other threads:[~2017-12-28 18:22 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 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 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 50/94] scsi: libiscsi: fix shifting of DID_REQUEUE host byte 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 42/94] lsm: fix smack_inode_removexattr and xattr_getsecurity memleak 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 87/94] USB: core: prevent malicious bNumInterfaces overflow 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 35/94] l2tp: fix l2tp_eth module loading 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 30/94] packet: only test po->has_vnet_hdr once in packet_snd 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 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 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 21/94] KEYS: fix key refcount leak in keyctl_assume_authority() 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 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 02/94] spi: uapi: spidev: add missing ioctl header 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 24/94] vfs: Return -ENXIO for negative SEEK_HOLE / SEEK_DATA offsets Ben Hutchings
2017-12-28 16:59 ` Ben Hutchings [this message]
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 09/94] xhci: fix finding correct bus_state structure for USB 3.1 hosts Ben Hutchings
2017-12-28 16:59 ` [PATCH 3.2 94/94] KEYS: add missing permission check for request_key() destination 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 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 89/94] security: Fix mode test in selinux_ptrace_access_check() 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 18/94] USB: gadgetfs: Fix crash caused by inadequate synchronization 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 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 58/94] scsi: zfcp: fix erp_action use-before-initialize in REC action trace 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 67/94] macvtap: fix TUNSETSNDBUF values > 64k 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 88/94] KVM: VMX: remove I/O port 0x80 bypass on Intel hosts 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 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 26/94] USB: gadgetfs, dummy-hcd, net2280: fix locking for callbacks 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 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 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 31/94] sched/sysctl: Check user input value of sysctl_sched_time_avg 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 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 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 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 13/94] crypto: talitos - fix sha224 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 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 47/94] USB: dummy-hcd: Fix deadlock caused by disconnect detection 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 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 43/94] kvm/x86: Avoid async PF preempting the kernel incorrectly 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 73/94] l2tp: hold socket before dropping lock in l2tp_ip{, 6}_recv() 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 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 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 81/94] x86/oprofile/ppro: Do not use __this_cpu*() in preemptible context 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 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 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.620909706@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=ebiggers@google.com \
--cc=james.l.morris@oracle.com \
--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
all inboxes | Powered by JetHome®