Skip to content

Commit

Permalink
media: venus: hfi: add checks to perform sanity on queue pointers
Browse files Browse the repository at this point in the history
commit 5e538fc upstream.

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: stable@vger.kernel.org
Fixes: d96d3f3 ("[media] media: venus: hfi: add Venus HFI files")
Signed-off-by: Vikash Garodia <quic_vgarodia@quicinc.com>
Signed-off-by: Stanimir Varbanov <stanimir.k.varbanov@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Vikash-Garodia authored and gregkh committed Nov 28, 2023
1 parent 2c86b24 commit 4edc7e6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/media/platform/qcom/venus/hfi_venus.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ static int venus_write_queue(struct venus_hfi_device *hdev,

new_wr_idx = wr_idx + dwords;
wr_ptr = (u32 *)(queue->qmem.kva + (wr_idx << 2));

if (wr_ptr < (u32 *)queue->qmem.kva ||
wr_ptr > (u32 *)(queue->qmem.kva + queue->qmem.size - sizeof(*wr_ptr)))
return -EINVAL;

if (new_wr_idx < qsize) {
memcpy(wr_ptr, packet, dwords << 2);
} else {
Expand Down Expand Up @@ -272,6 +277,11 @@ static int venus_read_queue(struct venus_hfi_device *hdev,
}

rd_ptr = (u32 *)(queue->qmem.kva + (rd_idx << 2));

if (rd_ptr < (u32 *)queue->qmem.kva ||
rd_ptr > (u32 *)(queue->qmem.kva + queue->qmem.size - sizeof(*rd_ptr)))
return -EINVAL;

dwords = *rd_ptr >> 2;
if (!dwords)
return -EINVAL;
Expand Down

0 comments on commit 4edc7e6

Please sign in to comment.