Skip to contentSkip to conversation

accel/ivpu: Fix signed integer truncation in IPC receive

PATCH Superseded Andrzej Kacprowski 2 participants 2 messages May 29

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Andrzej Kacprowski

author maintainer
#0 lore raw

PATCH 1/1 accel/ivpu: Fix signed integer truncation in IPC receive

Fix potential buffer overflow where firmware-supplied data_size is cast to signed int before being used in min_t(). Large unsigned values (>= 0x80000000) become negative, causing unsigned wraparound and oversized memcpy operations that can overflow the stack buffer.

Change min_t(int, ...) to min_t(u32, ...) to ensure large values are properly clamped instead of becoming negative.

Fixes 3b434a3445ff ("accel/ivpu: Use threaded IRQ to handle JOB done messages")
Cc <[email protected]> # v6.18+
---
 drivers/accel/ivpu/ivpu_ipc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_ipc.c +1 -1
index f47df092bb0d..9980a7898bed 100644
@@ -276,7 +276,7 @@ int ivpu_ipc_receive(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
 	if (ipc_buf)
 		memcpy(ipc_buf, rx_msg->ipc_hdr, sizeof(*ipc_buf));
 	if (rx_msg->jsm_msg) {
-		u32 size = min_t(int, rx_msg->ipc_hdr->data_size, sizeof(*jsm_msg));
+		u32 size = min_t(u32, rx_msg->ipc_hdr->data_size, sizeof(*jsm_msg));
 
 		if (rx_msg->jsm_msg->result != VPU_JSM_STATUS_SUCCESS) {
 			ivpu_err(vdev, "IPC resp result error: %d\n", rx_msg->jsm_msg->result);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Andrzej Kacprowski

Fix potential buffer overflow where firmware-supplied data_size is cast to signed int before being used in min_t(). Large unsigned values (>= 0x80000000) become negative, causing unsigned wraparound and oversized memcpy operations that can overflow the stack buffer.

Change min_t(int, ...) to min_t(u32, ...) to ensure large values are properly clamped instead of becoming negative.

Fixes 3b434a3445ff ("accel/ivpu: Use threaded IRQ to handle JOB done messages")
Cc <[email protected]> # v6.18+
Quoted 17 lines
---
  drivers/accel/ivpu/ivpu_ipc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_ipc.c +1 -1
index f47df092bb0d..9980a7898bed 100644
@@ -276,7 +276,7 @@ int ivpu_ipc_receive(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
  	if (ipc_buf)
  		memcpy(ipc_buf, rx_msg->ipc_hdr, sizeof(*ipc_buf));
  	if (rx_msg->jsm_msg) {
-		u32 size = min_t(int, rx_msg->ipc_hdr->data_size, sizeof(*jsm_msg));
+		u32 size = min_t(u32, rx_msg->ipc_hdr->data_size, sizeof(*jsm_msg));
 
  		if (rx_msg->jsm_msg->result != VPU_JSM_STATUS_SUCCESS) {
  			ivpu_err(vdev, "IPC resp result error: %d\n", rx_msg->jsm_msg->result);