summaryrefslogtreecommitdiff
path: root/drivers/input
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@linaro.org>2025-05-31 02:13:32 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-06-27 13:11:20 +0300
commit5a8cd6ae8393e2eaebf51d420d5374821ef2af87 (patch)
treeb848b659d1f9fb0f665a0885467d2a293369b034 /drivers/input
parentbe5f3061a6f904e3674257879e71881ceee5b673 (diff)
downloadlinux-5a8cd6ae8393e2eaebf51d420d5374821ef2af87.tar.xz
Input: ims-pcu - check record size in ims_pcu_flash_firmware()
commit a95ef0199e80f3384eb992889322957d26c00102 upstream. The "len" variable comes from the firmware and we generally do trust firmware, but it's always better to double check. If the "len" is too large it could result in memory corruption when we do "memcpy(fragment->data, rec->data, len);" Fixes: 628329d52474 ("Input: add IMS Passenger Control Unit driver") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/131fd1ae92c828ee9f4fa2de03d8c210ae1f3524.1748463049.git.dan.carpenter@linaro.org Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/misc/ims-pcu.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
index 4215f9b9c2b0..fc22cbb854a3 100644
--- a/drivers/input/misc/ims-pcu.c
+++ b/drivers/input/misc/ims-pcu.c
@@ -844,6 +844,12 @@ static int ims_pcu_flash_firmware(struct ims_pcu *pcu,
addr = be32_to_cpu(rec->addr) / 2;
len = be16_to_cpu(rec->len);
+ if (len > sizeof(pcu->cmd_buf) - 1 - sizeof(*fragment)) {
+ dev_err(pcu->dev,
+ "Invalid record length in firmware: %d\n", len);
+ return -EINVAL;
+ }
+
fragment = (void *)&pcu->cmd_buf[1];
put_unaligned_le32(addr, &fragment->addr);
fragment->len = len;