Skip to contentSkip to conversation

media: venus: hfi: check the write index against the queue size

PATCH New Maoyi Xie 1 participant 1 message Nov 19

Subsystems (5)
lore
Share & tools
lore

Maoyi Xie

author
#0 lore raw

PATCH 1/1 media: venus: hfi: check the write index against the queue size

venus_write_queue() takes read_idx, write_idx and q_size from the queue header in memory that the firmware also writes. It checks q_size and the write pointer against the queue memory size, but not write_idx against q_size.

If q_size is below write_idx, len in the wrap branch underflows, so memcpy() is asked to copy almost 4 GiB. It reads past the end of the packet.

Return -EINVAL when write_idx is not below q_size.

Found with a CodeQL-based static analysis tool that we are developing. Reproduced in a userspace harness under AddressSanitizer, which reports nothing with this patch. Not tested on hardware, only compile-tested with W=1 on next-20261116.

Fixes d96d3f30c0f2 ("[media] media: venus: hfi: add Venus HFI files")

---
I used an LLM to help write the harness and this patch.

 drivers/media/platform/qcom/venus/hfi_venus.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/media/platform/qcom/venus/hfi_venus.c +3 -0
index bd82066bb6e77f6..662b7e89a53229d 100644
@@ -190,6 +190,9 @@ static int venus_write_queue(struct venus_hfi_device *hdev,
 	if (qsize > IFACEQ_QUEUE_SIZE / 4)
 		return -EINVAL;
 
+	if (wr_idx >= qsize)
+		return -EINVAL;
+
 	if (wr_idx >= rd_idx)
 		empty_space = qsize - (wr_idx - rd_idx);
 	else

base-commit: 7e1392a42ea288d70a266f6553fe06f57f8647ea

Signature · 1 line
2.34.1