Skip to content

Commit 4dd1995

Browse files
Dan Carpenteraloktiwa
authored andcommitted
Input: ims-pcu - check record size in ims_pcu_flash_firmware()
commit a95ef01 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: 628329d ("Input: add IMS Passenger Control Unit driver") Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/131fd1ae92c828ee9f4fa2de03d8c210ae1f3524.1748463049.git.dan.carpenter@linaro.org Cc: [email protected] Signed-off-by: Dmitry Torokhov <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit c1b9d140b0807c6aee4bb53e1bfa4e391e3dc204) Signed-off-by: Alok Tiwari <[email protected]>
1 parent 6588fdb commit 4dd1995

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/input/misc/ims-pcu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ static int ims_pcu_flash_firmware(struct ims_pcu *pcu,
845845
addr = be32_to_cpu(rec->addr) / 2;
846846
len = be16_to_cpu(rec->len);
847847

848+
if (len > sizeof(pcu->cmd_buf) - 1 - sizeof(*fragment)) {
849+
dev_err(pcu->dev,
850+
"Invalid record length in firmware: %d\n", len);
851+
return -EINVAL;
852+
}
853+
848854
fragment = (void *)&pcu->cmd_buf[1];
849855
put_unaligned_le32(addr, &fragment->addr);
850856
fragment->len = len;

0 commit comments

Comments
 (0)