Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] soc: qcom: apr: accept packets without payload
@ 2026-12-01 13:15 Riccardo Mereu
  2026-12-01 13:27 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Riccardo Mereu @ 2026-12-01 13:15 UTC (permalink / raw)
  To: Srinivas Kandagatla, Bjorn Andersson, Konrad Dybcio, Abel Vesa
  Cc: Krzysztof Kozlowski, Riccardo Mereu, Abel Vesa, linux-sound,
	linux-arm-msm

From: Riccardo Mereu <r.mereu@arduino.cc>

The check added to reject a header larger than the packet also rejects
a packet that is exactly as large as its header. Such packets are
valid: the DSP sends events and command responses that carry no
payload, for example ASM_DATA_EVENT_RENDERED_EOS. They are now dropped
with

  qcom,apr ...apr_audio_svc.-1.-1: APR: Wrong packet size

and the service driver never sees them. On a QRB2210 board this
happens each time a q6asm playback stream is stopped and prepared
again, so the stream never learns that the DSP rendered the last
buffer.

Only a header that does not fit in the packet makes the payload size
negative, so reject that case alone, for APR and GPR.

Fixes: e6f64f9b76d5 ("soc: qcom: apr: Reject packets with header size larger than packet size")
Signed-off-by: Riccardo Mereu <r.mereu@arduino.cc>
---
 drivers/soc/qcom/apr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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


-- 





Privacy and Confidentiality Notice: This email and all attachments are 
confidential and for the designated recipient(s) only. They may also be 
privileged. If you are not the intended recipient or among the intended 
recipients, you may not use, read, retransmit, disseminate, store/copy the 
information in any medium or take any action in reliance upon it. Please 
notify the sender that you have received it in error and immediately delete 
the entire communication, including any attachments.

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] soc: qcom: apr: accept packets without payload
  2026-12-01 13:15 [PATCH] soc: qcom: apr: accept packets without payload Riccardo Mereu
@ 2026-12-01 13:27 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-01 13:27 UTC (permalink / raw)
  To: Riccardo Mereu; +Cc: linux-sound

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] soc: qcom: apr: uninitialized resp.payload for zero-payload
  packets
--

commit 3dd22a18cdfc965891e87fd5f0f5bbf91090ba36
Author: Riccardo Mereu <r.mereu@arduino.cc>

soc: qcom: apr: accept packets without payload

This commit relaxes the packet size check in apr_do_rx_callback() and
gpr_do_rx_callback() to allow packets whose total size equals their header
size.

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

[Severity: Medium]
Does allowing zero-payload packets leave resp.payload uninitialized on the
stack in both apr_do_rx_callback() and gpr_do_rx_callback()?

In both functions, resp is declared on the stack without initialization and
resp.payload is only assigned when resp.payload_size > 0:

drivers/soc/qcom/apr.c:apr_do_rx_callback() {
	...
	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);
}

When hdr->pkt_size equals the header size (such as on
ASM_DATA_EVENT_RENDERED_EOS), resp.payload_size is 0 and resp.payload holds
stack garbage.  Service callbacks such as q6asm_stream_callback() and
graph_callback() unconditionally read data->payload and pass it to their
client callbacks, and other opcode handlers that do not check
data->payload_size will dereference an uninitialized pointer instead of
NULL.  Zero-initializing resp (or setting resp.payload = NULL) avoids this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201131537.161860-1-r.mereu.kernel@arduino.cc?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-01 13:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 13:15 [PATCH] soc: qcom: apr: accept packets without payload Riccardo Mereu
2026-12-01 13:27 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox