summaryrefslogtreecommitdiff
path: root/drivers/input/misc
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@linaro.org>2025-05-30 16:13:32 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-06-27 11:02:51 +0100
commitc1b9d140b0807c6aee4bb53e1bfa4e391e3dc204 (patch)
tree1be5853dbb771b3d3337574238a29ce0bdcf5916 /drivers/input/misc
parent922200f03b5f181feed0fa93a98ab6fadc4238eb (diff)
downloadlinux-c1b9d140b0807c6aee4bb53e1bfa4e391e3dc204.tar.gz
linux-c1b9d140b0807c6aee4bb53e1bfa4e391e3dc204.tar.bz2
linux-c1b9d140b0807c6aee4bb53e1bfa4e391e3dc204.zip
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/misc')
-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 4dfed127952d..6e02a33ec379 100644
--- a/drivers/input/misc/ims-pcu.c
+++ b/drivers/input/misc/ims-pcu.c
@@ -845,6 +845,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;