]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:39:13 +0000 (07:39 +0200)
commit1b86c1917e16bafbbb08ab90baaff533aa36c62d
tree3551a9f8d62e58bf965486d49f7e428152789cb2
parent4dd109038d513b92d4d33524ffc89ba32e02ba48
media: venus: hfi: add check to handle incorrect queue size

commit 69baf245b23e20efda0079238b27fc63ecf13de1 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/platform/qcom/venus/hfi_venus.c