Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 5e538fc

Browse files
Vikash-GarodiaHans Verkuil
authored andcommitted
media: venus: hfi: add checks to perform sanity on queue pointers
Read and write pointers are used to track the packet index in the memory shared between video driver and firmware. There is a possibility of OOB access if the read or write pointer goes beyond the queue memory size. Add checks for the read and write pointer to avoid OOB access. Cc: [email protected] Fixes: d96d3f3 ("[media] media: venus: hfi: add Venus HFI files") Signed-off-by: Vikash Garodia <[email protected]> Signed-off-by: Stanimir Varbanov <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 4801673 commit 5e538fc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ static int venus_write_queue(struct venus_hfi_device *hdev,
205205

206206
new_wr_idx = wr_idx + dwords;
207207
wr_ptr = (u32 *)(queue->qmem.kva + (wr_idx << 2));
208+
209+
if (wr_ptr < (u32 *)queue->qmem.kva ||
210+
wr_ptr > (u32 *)(queue->qmem.kva + queue->qmem.size - sizeof(*wr_ptr)))
211+
return -EINVAL;
212+
208213
if (new_wr_idx < qsize) {
209214
memcpy(wr_ptr, packet, dwords << 2);
210215
} else {
@@ -272,6 +277,11 @@ static int venus_read_queue(struct venus_hfi_device *hdev,
272277
}
273278

274279
rd_ptr = (u32 *)(queue->qmem.kva + (rd_idx << 2));
280+
281+
if (rd_ptr < (u32 *)queue->qmem.kva ||
282+
rd_ptr > (u32 *)(queue->qmem.kva + queue->qmem.size - sizeof(*rd_ptr)))
283+
return -EINVAL;
284+
275285
dwords = *rd_ptr >> 2;
276286
if (!dwords)
277287
return -EINVAL;

0 commit comments

Comments
 (0)