accel/ivpu: Fix signed integer truncation in IPC receive
Subsystems (3)
Andrzej Kacprowski
maintainerPATCH 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.
--- drivers/accel/ivpu/ivpu_ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_ipc.c +1 -1
@@ -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
Quoted 11 lines · Andrzej Kacprowski
Fix potential buffer overflow where firmware-supplied
data_sizeis cast to signed int before being used inmin_t(). Large unsigned values (>=0x80000000) become negative, causing unsigned wraparound and oversized memcpy operations that can overflow the stack buffer.Change
min_t(int, ...)tomin_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+Signed-off-by Andrzej Kacprowski <[email protected]>
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@@ -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);