Skip to content

Commit

Permalink
platform/chrome: fix memory corruption in ioctl
Browse files Browse the repository at this point in the history
[ Upstream commit 8a07b45 ]

If "s_mem.bytes" is larger than the buffer size it leads to memory
corruption.

Fixes: eda2e30 ("mfd / platform: cros_ec: Miscellaneous character device to talk with the EC")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/Yv8dpCFZJdbUT5ye@kili
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Dan Carpenter authored and gregkh committed Oct 21, 2022
1 parent 0365dc6 commit 0c2e189
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/platform/chrome/cros_ec_chardev.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ static long cros_ec_chardev_ioctl_readmem(struct cros_ec_dev *ec,
if (copy_from_user(&s_mem, arg, sizeof(s_mem)))
return -EFAULT;

if (s_mem.bytes > sizeof(s_mem.buffer))
return -EINVAL;

num = ec_dev->cmd_readmem(ec_dev, s_mem.offset, s_mem.bytes,
s_mem.buffer);
if (num <= 0)
Expand Down

0 comments on commit 0c2e189

Please sign in to comment.