Skip to contentSkip to conversation

soc: qcom: apr: accept packets without payload

PATCH New Riccardo Mereu 2 participants 2 messages Dec 1

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: qcom: apr: accept packets without payload

From: Riccardo Mereu <[email protected]>

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")
---
 drivers/soc/qcom/apr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/qcom/apr.c +2 -2
index 515729374762..55f9b6a4bb76 100644
@@ -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;
 	}
Signature · 16 lines
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.
#1 lore raw
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 --

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 <[email protected]>

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.

Quoted 14 lines
drivers/soc/qcom/apr.c +1 -1
index 5157293747620..55f9b6a4bb76c 100644
@@ -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;
 	}

drivers/soc/qcom/apr.c static int gpr_do_rx_callback(struct packet_router *gpr, struct apr_rx_buf *abuf · line 295

Quoted 8 lines
drivers/soc/qcom/apr.c +1 -1
@@ -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.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1