]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Mar 2021 09:57:00 +0000 (10:57 +0100)
commit 5d749d0bbe811c10d9048cde6dfebc761713abfd upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/platform/chrome/cros_ec_dev.c
drivers/platform/chrome/cros_ec_proto.c
include/linux/mfd/cros_ec.h

index 2b331d5b9e79982f79680ca290064ec7589669d0..e16d82bb36a9d218ef7ef01d5e708f82d89b0645 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 5c285f2b3a65016da1bc19a0d8a4e36542e3fb5e..d20190c8f0c0629641847a73040b602bc242c1d7 100644 (file)
@@ -311,8 +311,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 3ab3cede28eac4729e345bf3868ed4de5bb727c1..93c14e9df6309bea43a30e8e31a605924ea8dd0f 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,
 };
 
 /*