All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Krzysztof Kozlowski" <krzysztof.kozlowski@oss.qualcomm.com>,
	linux-sound@vger.kernel.org
Subject: Re: [PATCH] soc: qcom: apr: Reject packets with header size larger than packet size
Date: Sun, 01 Nov 2026 18:01:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-192554@kernel.org> (raw)
In-Reply-To: <20261101175407.110780-2-krzysztof.kozlowski@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] soc: qcom: apr: uninitialized resp.payload when pkt_size equals hdr_size
--

commit 2669ea074a5a71b19b685f8644fc4fa968102cc7
Author: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>

soc: qcom: apr: Reject packets with header size larger than packet size

This commit adds checks in apr_do_rx_callback() and gpr_do_rx_callback() to
reject incoming APR and GPR packets whose header size exceeds the packet size,
preventing a negative resp.payload_size and an uninitialized resp.payload
stack pointer.

> diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
> index 2d5645ff99197..6f29b57aaecce 100644
> --- a/drivers/soc/qcom/apr.c
> +++ b/drivers/soc/qcom/apr.c
> @@ -210,7 +210,8 @@ static int apr_do_rx_callback(struct packet_router *apr, struct apr_rx_buf *abuf
>  		return -EINVAL;
>  	}
>  
> -	if (hdr->pkt_size < APR_HDR_SIZE || hdr->pkt_size != len) {
> +	if (hdr->pkt_size < APR_HDR_SIZE || hdr->pkt_size != len ||
> +	    hdr->pkt_size < hdr_size) {
>  		dev_err(apr->dev, "APR: Wrong packet size\n");
>  		return -EINVAL;
>  	}
> @@ -280,7 +281,8 @@ static int gpr_do_rx_callback(struct packet_router *gpr, struct apr_rx_buf *abuf
>  		return -EINVAL;
>  	}
>  
> -	if (hdr->pkt_size < GPR_PKT_HEADER_BYTE_SIZE || hdr->pkt_size != len) {
> +	if (hdr->pkt_size < GPR_PKT_HEADER_BYTE_SIZE || hdr->pkt_size != len ||
> +	    hdr->pkt_size < hdr_size * 4) {
>  		dev_err(gpr->dev, "GPR: Wrong packet size\n");
>  		return -EINVAL;
>  	}

[Severity: High]
What happens when a packet with optional header words has hdr->pkt_size equal
to hdr_size (in apr_do_rx_callback()) or hdr_size * 4 (in
gpr_do_rx_callback())?

In apr_callback(), packets with len > APR_HDR_SIZE are accepted, so a packet
with optional header words and no payload (for example, len == 24 and a
24-byte header) passes both apr_callback() and these new < checks.

In both apr_do_rx_callback() and gpr_do_rx_callback(), resp is declared on the
stack without initialization, and resp.payload_size evaluates to 0:

	resp.hdr = *hdr;
	resp.payload_size = hdr->pkt_size - hdr_size;

	if (resp.payload_size > 0)
		resp.payload = buf + hdr_size;

	adrv->callback(adev, &resp);

Because resp.payload is only assigned when resp.payload_size > 0, resp.payload
is still left uninitialized on the stack and passed to the service callbacks
(such as q6core_callback(), q6asm_srvc_callback(), graph_callback(), and
apm_callback()), which dereference data->payload without checking
data->payload_size.

Should these checks use <= (hdr->pkt_size <= hdr_size and
hdr->pkt_size <= hdr_size * 4, matching len <= APR_HDR_SIZE in
apr_callback()), or should resp.payload be initialized to NULL if zero-length
payloads are valid?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261101175407.110780-2-krzysztof.kozlowski@oss.qualcomm.com?part=1

  reply	other threads:[~2026-11-01 18:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01 17:54 [PATCH] soc: qcom: apr: Reject packets with header size larger than packet size Krzysztof Kozlowski
2026-11-01 18:01 ` sashiko-bot [this message]
2026-11-01 19:06 ` Krzysztof Kozlowski

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=sashiko-outbox-192554@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=krzysztof.kozlowski@oss.qualcomm.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.