Skip to content

Commit 2f7c4a8

Browse files
Dan Carpenteropsiff
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 <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> (cherry picked from commit 17474a56acf708bf6b2d174c06ed26abad0a9fd6)
1 parent 3d09daf commit 2f7c4a8

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

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)