Skip to content

Commit 69ca969

Browse files
Dan Carpentergregkh
authored andcommitted
platform/chrome: cros_ec_dev - double fetch bug in ioctl
commit 096cdc6f52225835ff503f987a0d68ef770bb78e upstream. We verify "u_cmd.outsize" and "u_cmd.insize" but we need to make sure that those values have not changed between the two copy_from_user() calls. Otherwise it could lead to a buffer overflow. Additionally, cros_ec_cmd_xfer() can set s_cmd->insize to a lower value. We should use the new smaller value so we don't copy too much data to the user. Reported-by: Pengfei Wang <wpengfeinudt@gmail.com> Fixes: a841178 ('mfd: cros_ec: Use a zero-length array for command data') Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Kees Cook <keescook@chromium.org> Tested-by: Gwendal Grignou <gwendal@chromium.org> Signed-off-by: Olof Johansson <olof@lixom.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 68f9903 commit 69ca969

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

drivers/platform/chrome/cros_ec_dev.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,19 @@ static long ec_device_ioctl_xcmd(struct cros_ec_dev *ec, void __user *arg)
147147
goto exit;
148148
}
149149

150+
if (u_cmd.outsize != s_cmd->outsize ||
151+
u_cmd.insize != s_cmd->insize) {
152+
ret = -EINVAL;
153+
goto exit;
154+
}
155+
150156
s_cmd->command += ec->cmd_offset;
151157
ret = cros_ec_cmd_xfer(ec->ec_dev, s_cmd);
152158
/* Only copy data to userland if data was received. */
153159
if (ret < 0)
154160
goto exit;
155161

156-
if (copy_to_user(arg, s_cmd, sizeof(*s_cmd) + u_cmd.insize))
162+
if (copy_to_user(arg, s_cmd, sizeof(*s_cmd) + s_cmd->insize))
157163
ret = -EFAULT;
158164
exit:
159165
kfree(s_cmd);

0 commit comments

Comments
 (0)