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, Martin Kelly <mkelly@xevo.com>,
	Stable@vger.kernel.org,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: [PATCH 4.9 48/61] iio:kfifo_buf: check for uint overflow
Date: Tue,  5 Jun 2018 19:02:09 +0200	[thread overview]
Message-ID: <20180605170120.770541100@linuxfoundation.org> (raw)
In-Reply-To: <20180605170117.643936916@linuxfoundation.org>

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

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

From: Martin Kelly <mkelly@xevo.com>

commit 3d13de4b027d5f6276c0f9d3a264f518747d83f2 upstream.

Currently, the following causes a kernel OOPS in memcpy:

echo 1073741825 > buffer/length
echo 1 > buffer/enable

Note that using 1073741824 instead of 1073741825 causes "write error:
Cannot allocate memory" but no OOPS.

This is because 1073741824 == 2^30 and 1073741825 == 2^30+1. Since kfifo
rounds up to the nearest power of 2, it will actually call kmalloc with
roundup_pow_of_two(length) * bytes_per_datum.

Using length == 1073741825 and bytes_per_datum == 2, we get:

kmalloc(roundup_pow_of_two(1073741825) * 2
or kmalloc(2147483648 * 2)
or kmalloc(4294967296)
or kmalloc(UINT_MAX + 1)

so this overflows to 0, causing kmalloc to return ZERO_SIZE_PTR and
subsequent memcpy to fail once the device is enabled.

Fix this by checking for overflow prior to allocating a kfifo. With this
check added, the above code returns -EINVAL when enabling the buffer,
rather than causing an OOPS.

Signed-off-by: Martin Kelly <mkelly@xevo.com>
cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/iio/buffer/kfifo_buf.c |    7 +++++++
 1 file changed, 7 insertions(+)

--- a/drivers/iio/buffer/kfifo_buf.c
+++ b/drivers/iio/buffer/kfifo_buf.c
@@ -24,6 +24,13 @@ static inline int __iio_allocate_kfifo(s
 	if ((length == 0) || (bytes_per_datum == 0))
 		return -EINVAL;
 
+	/*
+	 * Make sure we don't overflow an unsigned int after kfifo rounds up to
+	 * the next power of 2.
+	 */
+	if (roundup_pow_of_two(length) > UINT_MAX / bytes_per_datum)
+		return -EINVAL;
+
 	return __kfifo_alloc((struct __kfifo *)&buf->kf, length,
 			     bytes_per_datum, GFP_KERNEL);
 }

  parent reply	other threads:[~2018-06-05 17:06 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 17:01 [PATCH 4.9 00/61] 4.9.107-stable review Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 01/61] arm64: lse: Add early clobbers to some input/output asm operands Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 02/61] powerpc/64s: Clear PCR on boot Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 03/61] USB: serial: cp210x: use tcflag_t to fix incompatible pointer type Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 04/61] Revert "pinctrl: msm: Use dynamic GPIO numbering" Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 05/61] xfs: detect agfl count corruption and reset agfl Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 06/61] Revert "ima: limit file hash setting by user to fix and log modes" Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 07/61] Input: elan_i2c_smbus - fix corrupted stack Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 08/61] tracing: Fix crash when freeing instances with event triggers Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 09/61] selinux: KASAN: slab-out-of-bounds in xattr_getsecurity Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 10/61] cfg80211: further limit wiphy names to 64 bytes Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 11/61] dma-buf: remove redundant initialization of sg_table Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 12/61] rtlwifi: rtl8192cu: Remove variable self-assignment in rf.c Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 13/61] ASoC: Intel: sst: remove redundant variable dma_dev_name Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 14/61] platform/chrome: cros_ec_lpc: remove redundant pointer request Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 15/61] x86/amd: revert commit 944e0fc51a89c9827b9 Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 16/61] xen: set cpu capabilities from xen_start_kernel() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 17/61] x86/amd: dont set X86_BUG_SYSRET_SS_ATTRS when running under Xen Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 18/61] tcp: avoid integer overflows in tcp_rcv_space_adjust() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 19/61] scsi: ufs: fix failure to read the string descriptor Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 20/61] scsi: ufs: refactor device descriptor reading Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 21/61] scsi: ufs: Factor out ufshcd_read_desc_param Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 22/61] arm64: Add hypervisor safe helper for checking constant capabilities Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 23/61] arm64/cpufeature: dont use mutex in bringup path Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 24/61] powerpc/rfi-flush: Move out of HARDLOCKUP_DETECTOR #ifdef Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 25/61] powerpc/pseries: Support firmware disable of RFI flush Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 26/61] powerpc/powernv: " Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 27/61] powerpc/rfi-flush: Move the logic to avoid a redo into the debugfs code Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 28/61] powerpc/rfi-flush: Make it possible to call setup_rfi_flush() again Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 29/61] powerpc/rfi-flush: Always enable fallback flush on pseries Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 30/61] powerpc/rfi-flush: Differentiate enabled and patched flush types Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 31/61] powerpc/rfi-flush: Call setup_rfi_flush() after LPM migration Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 32/61] powerpc/pseries: Add new H_GET_CPU_CHARACTERISTICS flags Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 33/61] powerpc: Add security feature flags for Spectre/Meltdown Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 34/61] powerpc/pseries: Set or clear security feature flags Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 35/61] powerpc/powernv: " Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 36/61] powerpc/64s: Move cpu_show_meltdown() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 37/61] powerpc/64s: Enhance the information in cpu_show_meltdown() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.9 38/61] powerpc/powernv: Use the security flags in pnv_setup_rfi_flush() Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 39/61] powerpc/pseries: Use the security flags in pseries_setup_rfi_flush() Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 40/61] powerpc/64s: Wire up cpu_show_spectre_v1() Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 41/61] powerpc/64s: Wire up cpu_show_spectre_v2() Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 42/61] powerpc/pseries: Fix clearing of security feature flags Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 43/61] powerpc: Move default " Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 44/61] powerpc/pseries: Restore default security feature flags on setup Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 45/61] powerpc/64s: Fix section mismatch warnings from setup_rfi_flush() Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 47/61] net/mlx4_en: fix potential use-after-free with dma_unmap_page Greg Kroah-Hartman
2018-06-05 17:02 ` Greg Kroah-Hartman [this message]
2018-06-05 17:02 ` [PATCH 4.9 49/61] MIPS: ptrace: Fix PTRACE_PEEKUSR requests for 64-bit FGRs Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 50/61] MIPS: prctl: Disallow FRE without FR with PR_SET_FP_MODE requests Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 51/61] scsi: scsi_transport_srp: Fix shost to rport translation Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 52/61] stm class: Use vmalloc for the master map Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 53/61] hwtracing: stm: fix build error on some arches Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 54/61] IB/core: Fix error code for invalid GID entry Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 58/61] fix io_destroy()/aio_complete() race Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 59/61] mm: fix the NULL mapping case in __isolate_lru_page() Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 60/61] sparc64: Dont clibber fixed registers in __multi4 Greg Kroah-Hartman
2018-06-05 17:02 ` [PATCH 4.9 61/61] serial: pl011: add console matching function Greg Kroah-Hartman
2018-06-05 22:01 ` [PATCH 4.9 00/61] 4.9.107-stable review Shuah Khan
2018-06-06  8:06   ` Greg Kroah-Hartman
2018-06-06 11:24 ` Naresh Kamboju
2018-06-06 13:29 ` Guenter Roeck
2018-06-06 13:32   ` Greg Kroah-Hartman

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=20180605170120.770541100@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkelly@xevo.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).