Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1348800

[PATCH] platform/chrome: cros_ec_dev - Fix security issue

From Gwendal Grignou <gwendal@chromium.org>
Newsgroups linux.kernel
Subject [PATCH] platform/chrome: cros_ec_dev - Fix security issue
Date 2016-03-03 07:00 +0100
Message-ID <r8usO-2yU-5@gated-at.bofh.it> (permalink)
References <r7Zfk-5PN-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Add a check to prevent memory scribbe when sending an ioctl with .insize
set so large that memory allocation argument overflows.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
 drivers/platform/chrome/cros_ec_dev.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c
index d45cd25..86d6373 100644
--- a/drivers/platform/chrome/cros_ec_dev.c
+++ b/drivers/platform/chrome/cros_ec_dev.c
@@ -131,13 +131,23 @@ static ssize_t ec_device_read(struct file *filp, char __user *buffer,
 static long ec_device_ioctl_xcmd(struct cros_ec_dev *ec, void __user *arg)
 {
 	long ret;
+	size_t data_size;
 	struct cros_ec_command u_cmd;
 	struct cros_ec_command *s_cmd;
 
 	if (copy_from_user(&u_cmd, arg, sizeof(u_cmd)))
 		return -EFAULT;
 
-	s_cmd = kmalloc(sizeof(*s_cmd) + max(u_cmd.outsize, u_cmd.insize),
+	/*
+	 * Prevent mallicious attack where .inside is so big that amount
+	 * kmalloc'ed rollover, allowing memcpy to write beyond the allocated
+	 * space.
+	 */
+	data_size = max(u_cmd.outsize, u_cmd.insize);
+	if (data_size + sizeof(*s_cmd) < data_size)
+		return -EINVAL;
+
+	s_cmd = kmalloc(sizeof(*s_cmd) + data_size,
 			GFP_KERNEL);
 	if (!s_cmd)
 		return -ENOMEM;
-- 
2.7.0.rc3.207.g0ac5344

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Security hole in cros_ec_dev.c on 32bit chrome hosts Alan Cox <alan@lxorguk.ukuu.org.uk> - 2016-03-01 21:40 +0100
  [PATCH] platform/chrome: cros_ec_dev - Fix security issue Gwendal Grignou <gwendal@chromium.org> - 2016-03-03 07:00 +0100
    Re: [PATCH] platform/chrome: cros_ec_dev - Fix security issue Randy Dunlap <rdunlap@infradead.org> - 2016-03-03 19:40 +0100
      [PATCH v2] platform/chrome: cros_ec_dev - Fix security issue Gwendal Grignou <gwendal@chromium.org> - 2016-03-03 20:10 +0100

csiph-web