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 7 lines · On Fri, 29 May 2026 13:50:05 +0200 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.
Just use min(), no need for the casts that min_t() adds.
This is another (slightly unusual) example of why min_t() is broken. Even with min() doing strict type checks the correct fix would have been to use (u32)sizeof(*jsm_msg) - and completely ignore what checkpatch says.
-- David
Quoted 21 lines
Fixes 3b434a3445ff ("accel/ivpu: Use threaded IRQ to handle JOB done messages")Cc <[email protected]> # v6.18+Signed-off-by Andrzej Kacprowski <[email protected]>--- 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);
Andrzej Kacprowski
maintainerQuoted 11 lines · David Laight
Quoted 7 lines · On Fri, 29 May 2026 13:50:05 +0200 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.
Quoted 8 lines
Just use
min(), no need for the casts thatmin_t()adds.This is another (slightly unusual) example of why
min_t()is broken. Even withmin()doing strict type checks the correct fix would have been to use (u32)sizeof(*jsm_msg) - and completely ignore what checkpatch says.-- David
Thanks for the review.
I will replace min_t() with min().
-- Andrzej
Quoted 22 lines
Quoted 21 lines
Fixes 3b434a3445ff ("accel/ivpu: Use threaded IRQ to handle JOB done messages")Cc <[email protected]> # v6.18+Signed-off-by Andrzej Kacprowski <[email protected]>--- 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);
Andrzej Kacprowski
maintainerPATCH v2 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() as both values are unsigned and can be handled by min() without explicit cast.
---
Changes in v2:
- Replaced min_t() with min()
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 (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 8 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()as both values are unsigned and can be handled bymin()without explicit cast.
Quoted 6 lines
Fixes 3b434a3445ff ("accel/ivpu: Use threaded IRQ to handle JOB done messages")Cc <[email protected]> # v6.12+Signed-off-by Andrzej Kacprowski <[email protected]>---
Changes in v2:
- Replacedmin_t()withmin()
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 (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);
Quoted 9 lines · Karol
Quoted 8 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()as both values are unsigned and can be handled bymin()without explicit cast.
Quoted 29 lines
Quoted 6 lines
Fixes 3b434a3445ff ("accel/ivpu: Use threaded IRQ to handle JOB done messages")Cc <[email protected]> # v6.12+Signed-off-by Andrzej Kacprowski <[email protected]>---
Changes in v2:
- Replacedmin_t()withmin()Reviewed-by Karol Wachowski <[email protected]>Quoted 19 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(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-
Quoted 1 line
jsm_msg->result);
Pushed to drm-misc-fixes.