Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: venus: hfi: add check to handle incorrect queue size

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>

authored by

Vikash Garodia and committed by
Hans Verkuil
69baf245 9edaaa8e

+6
+6
drivers/media/platform/qcom/venus/hfi_venus.c
··· 187 187 /* ensure rd/wr indices's are read from memory */ 188 188 rmb(); 189 189 190 + if (qsize > IFACEQ_QUEUE_SIZE / 4) 191 + return -EINVAL; 192 + 190 193 if (wr_idx >= rd_idx) 191 194 empty_space = qsize - (wr_idx - rd_idx); 192 195 else ··· 257 254 rd_idx = qhdr->read_idx; 258 255 wr_idx = qhdr->write_idx; 259 256 qsize = qhdr->q_size; 257 + 258 + if (qsize > IFACEQ_QUEUE_SIZE / 4) 259 + return -EINVAL; 260 260 261 261 /* make sure data is valid before using it */ 262 262 rmb();