Skip to content

Commit a95ef01

Browse files
Dan Carpenterdtor
authored andcommitted
Input: ims-pcu - check record size in ims_pcu_flash_firmware()
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]>
1 parent 8f38219 commit a95ef01

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
@@ -844,6 +844,12 @@ static int ims_pcu_flash_firmware(struct ims_pcu *pcu,
844844
addr = be32_to_cpu(rec->addr) / 2;
845845
len = be16_to_cpu(rec->len);
846846

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

0 commit comments

Comments
 (0)