Skip to content

Commit f0cbd93

Browse files
Vedang Nagargregkh
authored andcommitted
media: venus: Add a check for packet size after reading from shared memory
commit 49befc8 upstream. 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. Fixes: d96d3f3 ("[media] media: venus: hfi: add Venus HFI files") Cc: stable@vger.kernel.org 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a1524d9 commit f0cbd93

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/media/platform/qcom/venus/hfi_venus.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ static int venus_write_queue(struct venus_hfi_device *hdev,
239239
static int venus_read_queue(struct venus_hfi_device *hdev,
240240
struct iface_queue *queue, void *pkt, u32 *tx_req)
241241
{
242+
struct hfi_pkt_hdr *pkt_hdr = NULL;
242243
struct hfi_queue_header *qhdr;
243244
u32 dwords, new_rd_idx;
244245
u32 rd_idx, wr_idx, type, qsize;
@@ -304,6 +305,9 @@ static int venus_read_queue(struct venus_hfi_device *hdev,
304305
memcpy(pkt, rd_ptr, len);
305306
memcpy(pkt + len, queue->qmem.kva, new_rd_idx << 2);
306307
}
308+
pkt_hdr = (struct hfi_pkt_hdr *)(pkt);
309+
if ((pkt_hdr->size >> 2) != dwords)
310+
return -EINVAL;
307311
} else {
308312
/* bad packet received, dropping */
309313
new_rd_idx = qhdr->write_idx;

0 commit comments

Comments
 (0)