]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: venus: hfi: add check to handle incorrect queue size
authorVikash Garodia <quic_vgarodia@quicinc.com>
Thu, 20 Feb 2025 17:20:10 +0000 (22:50 +0530)
committerHans Verkuil <hverkuil@xs4all.nl>
Mon, 3 Mar 2025 17:21:55 +0000 (18:21 +0100)
qsize represents size of shared queued between driver and video
firmware. Firmware can modify this value to an invalid large value. In
such situation, empty_space will be bigger than the space actually
available. Since new_wr_idx is not checked, so the following code will
result in an OOB write.
...
qsize = qhdr->q_size

if (wr_idx >= rd_idx)
 empty_space = qsize - (wr_idx - rd_idx)
....
if (new_wr_idx < qsize) {
 memcpy(wr_ptr, packet, dwords << 2) --> OOB write

Add check to ensure qsize is within the allocated size while
reading and writing packets into the queue.

Cc: stable@vger.kernel.org
Fixes: d96d3f30c0f2 ("[media] media: venus: hfi: add Venus HFI files")
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Vikash Garodia <quic_vgarodia@quicinc.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/platform/qcom/venus/hfi_venus.c

index a9167867063c4140450cb803218d32b5bda32d48..36d3a37db4e8a7967ec5209e78a455cc53eb4933 100644 (file)
@@ -187,6 +187,9 @@ static int venus_write_queue(struct venus_hfi_device *hdev,
        /* ensure rd/wr indices's are read from memory */
        rmb();
 
+       if (qsize > IFACEQ_QUEUE_SIZE / 4)
+               return -EINVAL;
+
        if (wr_idx >= rd_idx)
                empty_space = qsize - (wr_idx - rd_idx);
        else
@@ -255,6 +258,9 @@ static int venus_read_queue(struct venus_hfi_device *hdev,
        wr_idx = qhdr->write_idx;
        qsize = qhdr->q_size;
 
+       if (qsize > IFACEQ_QUEUE_SIZE / 4)
+               return -EINVAL;
+
        /* make sure data is valid before using it */
        rmb();