FROMGIT: media: venus: Add a check for packet size after reading from shared memory

Add a check to ensure that the packet size does not exceed the number of
available words after reading the packet header from shared memory. This
ensures that the size provided by the firmware is safe to process and
prevent potential out-of-bounds memory access.

Signed-off-by: Vedang Nagar <quic_vnagar@quicinc.com>
Co-developed-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Bryan O'Donoghue <bod@kernel.org>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>

(cherry picked from commit 49befc830daa743e051a65468c05c2ff9e8580e6 https://gitlab.freedesktop.org/linux-media/media-committers.git master)
Change-Id: I6d0e34681bfaec467879c0dd34b74e50b7879822
Signed-off-by: Gaviraju Doddabettahalli Bettegowda <quic_gdoddabe@quicinc.com>
This commit is contained in:
Gaviraju Doddabettahalli Bettegowda
2025-07-15 15:28:28 +05:30
committed by Treehugger Robot
parent a11268a7e2
commit 2888255bfe
@@ -239,6 +239,7 @@ static int venus_write_queue(struct venus_hfi_device *hdev,
static int venus_read_queue(struct venus_hfi_device *hdev,
struct iface_queue *queue, void *pkt, u32 *tx_req)
{
struct hfi_pkt_hdr *pkt_hdr = NULL;
struct hfi_queue_header *qhdr;
u32 dwords, new_rd_idx;
u32 rd_idx, wr_idx, type, qsize;
@@ -304,6 +305,9 @@ static int venus_read_queue(struct venus_hfi_device *hdev,
memcpy(pkt, rd_ptr, len);
memcpy(pkt + len, queue->qmem.kva, new_rd_idx << 2);
}
pkt_hdr = (struct hfi_pkt_hdr *)(pkt);
if ((pkt_hdr->size >> 2) != dwords)
return -EINVAL;
} else {
/* bad packet received, dropping */
new_rd_idx = qhdr->write_idx;