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,
	syzbot+a95b989b2dde8e806af8@syzkaller.appspotmail.com,
	Eric Sandeen <sandeen@redhat.com>,
	David Howells <dhowells@redhat.com>
Subject: [PATCH 4.18 08/34] fscache: Fix out of bound read in long cookie keys
Date: Thu,  8 Nov 2018 13:52:37 -0800	[thread overview]
Message-ID: <20181108215139.425688236@linuxfoundation.org> (raw)
In-Reply-To: <20181108215138.892971755@linuxfoundation.org>

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

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

From: Eric Sandeen <sandeen@redhat.com>

commit fa520c47eaa15b9baa8ad66ac18da4a31679693b upstream.

fscache_set_key() can incur an out-of-bounds read, reported by KASAN:

 BUG: KASAN: slab-out-of-bounds in fscache_alloc_cookie+0x5b3/0x680 [fscache]
 Read of size 4 at addr ffff88084ff056d4 by task mount.nfs/32615

and also reported by syzbot at https://lkml.org/lkml/2018/7/8/236

  BUG: KASAN: slab-out-of-bounds in fscache_set_key fs/fscache/cookie.c:120 [inline]
  BUG: KASAN: slab-out-of-bounds in fscache_alloc_cookie+0x7a9/0x880 fs/fscache/cookie.c:171
  Read of size 4 at addr ffff8801d3cc8bb4 by task syz-executor907/4466

This happens for any index_key_len which is not divisible by 4 and is
larger than the size of the inline key, because the code allocates exactly
index_key_len for the key buffer, but the hashing loop is stepping through
it 4 bytes (u32) at a time in the buf[] array.

Fix this by calculating how many u32 buffers we'll need by using
DIV_ROUND_UP, and then using kcalloc() to allocate a precleared allocation
buffer to hold the index_key, then using that same count as the hashing
index limit.

Fixes: ec0328e46d6e ("fscache: Maintain a catalogue of allocated cookies")
Reported-by: syzbot+a95b989b2dde8e806af8@syzkaller.appspotmail.com
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/fscache/cookie.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

--- a/fs/fscache/cookie.c
+++ b/fs/fscache/cookie.c
@@ -70,7 +70,7 @@ void fscache_free_cookie(struct fscache_
 }
 
 /*
- * Set the index key in a cookie.  The cookie struct has space for a 12-byte
+ * Set the index key in a cookie.  The cookie struct has space for a 16-byte
  * key plus length and hash, but if that's not big enough, it's instead a
  * pointer to a buffer containing 3 bytes of hash, 1 byte of length and then
  * the key data.
@@ -80,10 +80,13 @@ static int fscache_set_key(struct fscach
 {
 	unsigned long long h;
 	u32 *buf;
+	int bufs;
 	int i;
 
+	bufs = DIV_ROUND_UP(index_key_len, sizeof(*buf));
+
 	if (index_key_len > sizeof(cookie->inline_key)) {
-		buf = kzalloc(index_key_len, GFP_KERNEL);
+		buf = kcalloc(bufs, sizeof(*buf), GFP_KERNEL);
 		if (!buf)
 			return -ENOMEM;
 		cookie->key = buf;
@@ -98,7 +101,8 @@ static int fscache_set_key(struct fscach
 	 */
 	h = (unsigned long)cookie->parent;
 	h += index_key_len + cookie->type;
-	for (i = 0; i < (index_key_len + sizeof(u32) - 1) / sizeof(u32); i++)
+
+	for (i = 0; i < bufs; i++)
 		h += buf[i];
 
 	cookie->key_hash = h ^ (h >> 32);



  parent reply	other threads:[~2018-11-08 22:10 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-08 21:52 [PATCH 4.18 00/34] 4.18.18-stable review Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 01/34] eeprom: at24: Add support for address-width property Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 02/34] vfs: swap names of {do,vfs}_clone_file_range() Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 03/34] bpf: fix partial copy of map_ptr when dst is scalar Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 04/34] gpio: mxs: Get rid of external API call Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 05/34] clk: sunxi-ng: sun4i: Set VCO and PLL bias current to lowest setting Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 06/34] fscache: Fix incomplete initialisation of inline key space Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 07/34] cachefiles: fix the race between cachefiles_bury_object() and rmdir(2) Greg Kroah-Hartman
2018-11-08 21:52 ` Greg Kroah-Hartman [this message]
2018-11-08 21:52 ` [PATCH 4.18 09/34] ptp: fix Spectre v1 vulnerability Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 10/34] drm/edid: Add 6 bpc quirk for BOE panel in HP Pavilion 15-n233sl Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 11/34] drm/edid: VSDB yCBCr420 Deep Color mode bit definitions Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 12/34] drm: fb-helper: Reject all pixel format changing requests Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 13/34] RDMA/ucma: Fix Spectre v1 vulnerability Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 14/34] IB/ucm: " Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 15/34] cdc-acm: do not reset notification buffer index upon urb unlinking Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 16/34] cdc-acm: correct counting of UART states in serial state notification Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 17/34] cdc-acm: fix race between reset and control messaging Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 18/34] usb: usbip: Fix BUG: KASAN: slab-out-of-bounds in vhci_hub_control() Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 19/34] usb: gadget: storage: Fix Spectre v1 vulnerability Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 20/34] usb: roles: intel_xhci: Fix Unbalanced pm_runtime_enable Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 21/34] usb: xhci: pci: Enable Intel USB role mux on Apollo Lake platforms Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 22/34] USB: fix the usbfs flag sanitization for control transfers Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 23/34] block: dont deal with discard limit in blkdev_issue_discard() Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 24/34] tracing: Fix synthetic event to accept unsigned modifier Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 25/34] tracing: Fix synthetic event to allow semicolon at end Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 26/34] Input: elan_i2c - add ACPI ID for Lenovo IdeaPad 330-15IGM Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 27/34] drm/sun4i: Fix an ulong overflow in the dotclock driver Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 28/34] sched/fair: Fix throttle_list starvation with low CFS quota Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 29/34] x86/tsc: Force inlining of cyc2ns bits Greg Kroah-Hartman
2018-11-08 21:52 ` [PATCH 4.18 30/34] x86, hibernate: Fix nosave_regions setup for hibernation Greg Kroah-Hartman
2018-11-09  8:13   ` Pavel Machek
2018-11-08 21:53 ` [PATCH 4.18 31/34] x86/percpu: Fix this_cpu_read() Greg Kroah-Hartman
2018-11-08 21:53 ` [PATCH 4.18 32/34] x86/time: Correct the attribute on jiffies definition Greg Kroah-Hartman
2018-11-08 21:53 ` [PATCH 4.18 33/34] x86/swiotlb: Enable swiotlb for > 4GiG RAM on 32-bit kernels Greg Kroah-Hartman
2018-11-08 21:53 ` [PATCH 4.18 34/34] x86/fpu: Fix i486 + no387 boot crash by only saving FPU registers on context switch if there is an FPU Greg Kroah-Hartman
2018-11-09  3:50 ` [PATCH 4.18 00/34] 4.18.18-stable review kernelci.org bot
2018-11-09 14:39 ` Naresh Kamboju
2018-11-10 15:24   ` Greg Kroah-Hartman
2018-11-09 19:41 ` Guenter Roeck
2018-11-09 19:55 ` 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=20181108215139.425688236@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sandeen@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+a95b989b2dde8e806af8@syzkaller.appspotmail.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).