]> git.baikalelectronics.ru Git - kernel.git/commitdiff
platform/chrome: cros_ec_dev - Fix security issue
authorGwendal Grignou <gwendal@chromium.org>
Tue, 8 Mar 2016 17:13:52 +0000 (09:13 -0800)
committerOlof Johansson <olof@lixom.net>
Wed, 11 May 2016 18:55:47 +0000 (11:55 -0700)
Prevent memory scribble by checking that ioctl buffer size parameters
are sane.
Without this check, on 32 bits system, if .insize = 0xffffffff - 20 and
.outsize the amount to scribble, we would overflow, allocate a small
amounts and be able to write outside of the malloc'ed area.
Adding a hard limit allows argument checking of the ioctl. With the
current EC, it is expected .insize and .outsize to be at around 512 bytes
or less.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Olof Johansson <olof@lixom.net>
drivers/platform/chrome/cros_ec_dev.c
drivers/platform/chrome/cros_ec_proto.c
include/linux/mfd/cros_ec.h

index d45cd254ed1c8f295292074100934130235fca64..187470c8a1f60a0ae59c55a5cac2aeb8fe7e9ead 100644 (file)
@@ -137,6 +137,10 @@ static long ec_device_ioctl_xcmd(struct cros_ec_dev *ec, void __user *arg)
        if (copy_from_user(&u_cmd, arg, sizeof(u_cmd)))
                return -EFAULT;
 
+       if ((u_cmd.outsize > EC_MAX_MSG_BYTES) ||
+           (u_cmd.insize > EC_MAX_MSG_BYTES))
+               return -EINVAL;
+
        s_cmd = kmalloc(sizeof(*s_cmd) + max(u_cmd.outsize, u_cmd.insize),
                        GFP_KERNEL);
        if (!s_cmd)
index 990308ca384fdcba7c9c37f49ea94768203ff7ad..b6e161f71b26af834b2366b2d2f9f0e32f61ac0c 100644 (file)
@@ -298,8 +298,8 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
                        ec_dev->max_response = EC_PROTO2_MAX_PARAM_SIZE;
                        ec_dev->max_passthru = 0;
                        ec_dev->pkt_xfer = NULL;
-                       ec_dev->din_size = EC_MSG_BYTES;
-                       ec_dev->dout_size = EC_MSG_BYTES;
+                       ec_dev->din_size = EC_PROTO2_MSG_BYTES;
+                       ec_dev->dout_size = EC_PROTO2_MSG_BYTES;
                } else {
                        /*
                         * It's possible for a test to occur too early when
index a677c2bd485c4a847af791535d0a71e5b140ed26..64184d27e3cd38cb7c2f47a3392df8518581e7b3 100644 (file)
@@ -50,9 +50,11 @@ enum {
                                        EC_MSG_TX_TRAILER_BYTES,
        EC_MSG_RX_PROTO_BYTES   = 3,
 
-       /* Max length of messages */
-       EC_MSG_BYTES            = EC_PROTO2_MAX_PARAM_SIZE +
+       /* Max length of messages for proto 2*/
+       EC_PROTO2_MSG_BYTES             = EC_PROTO2_MAX_PARAM_SIZE +
                                        EC_MSG_TX_PROTO_BYTES,
+
+       EC_MAX_MSG_BYTES                = 64 * 1024,
 };
 
 /*