Skip to content

Commit 2e2321a

Browse files
Dan Carpentersmb49
authored andcommitted
Input: ims-pcu - check record size in ims_pcu_flash_firmware()
BugLink: https://bugs.launchpad.net/bugs/2120812 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: 628329d ("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> Signed-off-by: Noah Wager <noah.wager@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 9b94a8a commit 2e2321a

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)