Skip to content

Commit 96d8569

Browse files
committed
media: vivid: fix buffer overwrite when using > 32 buffers
The maximum number of buffers that can be requested was increased to 64 for the video capture queue. But video capture used a must_blank array that was still sized for 32 (VIDEO_MAX_FRAME). This caused an out-of-bounds write when using buffer indices >= 32. Create a new define MAX_VID_CAP_BUFFERS that is used to access the must_blank array and set max_num_buffers for the video capture queue. This solves a crash reported by: https://bugzilla.kernel.org/show_bug.cgi?id=219258 Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Fixes: cea70ed ("media: test-drivers: vivid: Increase max supported buffers for capture queues") Cc: stable@vger.kernel.org
1 parent ba9cf6b commit 96d8569

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

drivers/media/test-drivers/vivid/vivid-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ static int vivid_create_queue(struct vivid_dev *dev,
910910
* videobuf2-core.c to MAX_BUFFER_INDEX.
911911
*/
912912
if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
913-
q->max_num_buffers = 64;
913+
q->max_num_buffers = MAX_VID_CAP_BUFFERS;
914914
if (buf_type == V4L2_BUF_TYPE_SDR_CAPTURE)
915915
q->max_num_buffers = 1024;
916916
if (buf_type == V4L2_BUF_TYPE_VBI_CAPTURE)

drivers/media/test-drivers/vivid/vivid-core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define MAX_INPUTS 16
2727
/* The maximum number of outputs */
2828
#define MAX_OUTPUTS 16
29+
/* The maximum number of video capture buffers */
30+
#define MAX_VID_CAP_BUFFERS 64
2931
/* The maximum up or down scaling factor is 4 */
3032
#define MAX_ZOOM 4
3133
/* The maximum image width/height are set to 4K DMT */
@@ -481,7 +483,7 @@ struct vivid_dev {
481483
/* video capture */
482484
struct tpg_data tpg;
483485
unsigned ms_vid_cap;
484-
bool must_blank[VIDEO_MAX_FRAME];
486+
bool must_blank[MAX_VID_CAP_BUFFERS];
485487

486488
const struct vivid_fmt *fmt_cap;
487489
struct v4l2_fract timeperframe_vid_cap;

drivers/media/test-drivers/vivid/vivid-ctrls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl)
553553
break;
554554
case VIVID_CID_PERCENTAGE_FILL:
555555
tpg_s_perc_fill(&dev->tpg, ctrl->val);
556-
for (i = 0; i < VIDEO_MAX_FRAME; i++)
556+
for (i = 0; i < MAX_VID_CAP_BUFFERS; i++)
557557
dev->must_blank[i] = ctrl->val < 100;
558558
break;
559559
case VIVID_CID_INSERT_SAV:

drivers/media/test-drivers/vivid/vivid-vid-cap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int vid_cap_start_streaming(struct vb2_queue *vq, unsigned count)
213213

214214
dev->vid_cap_seq_count = 0;
215215
dprintk(dev, 1, "%s\n", __func__);
216-
for (i = 0; i < VIDEO_MAX_FRAME; i++)
216+
for (i = 0; i < MAX_VID_CAP_BUFFERS; i++)
217217
dev->must_blank[i] = tpg_g_perc_fill(&dev->tpg) < 100;
218218
if (dev->start_streaming_error) {
219219
dev->start_streaming_error = false;

0 commit comments

Comments
 (0)