Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Andrzej Kacprowski <andrzej.kacprowski@linux.intel.com>
Cc: stable@vger.kernel.org
Subject: Re: [PATCH] accel/ivpu: Fix signed integer truncation in IPC receive
Date: Fri, 29 May 2026 13:49:11 +0100	[thread overview]
Message-ID: <20260529134911.40728b88@pumpkin> (raw)
In-Reply-To: <20260529115005.131888-1-andrzej.kacprowski@linux.intel.com>

On Fri, 29 May 2026 13:50:05 +0200
Andrzej Kacprowski <andrzej.kacprowski@linux.intel.com> wrote:

> 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.

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

> 
> Fixes: 3b434a3445ff ("accel/ivpu: Use threaded IRQ to handle JOB done messages")
> Cc: <stable@vger.kernel.org> # v6.18+
> Signed-off-by: Andrzej Kacprowski <andrzej.kacprowski@linux.intel.com>
> ---
>  drivers/accel/ivpu/ivpu_ipc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/accel/ivpu/ivpu_ipc.c b/drivers/accel/ivpu/ivpu_ipc.c
> index f47df092bb0d..9980a7898bed 100644
> --- a/drivers/accel/ivpu/ivpu_ipc.c
> +++ b/drivers/accel/ivpu/ivpu_ipc.c
> @@ -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);


  reply	other threads:[~2026-05-29 12:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29 11:50 [PATCH] accel/ivpu: Fix signed integer truncation in IPC receive Andrzej Kacprowski
2026-05-29 12:49 ` David Laight [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-05-29 11:54 Andrzej Kacprowski
2026-05-29 12:03 ` Wachowski, Karol

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260529134911.40728b88@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=andrzej.kacprowski@linux.intel.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox