Skip to content

Commit 10c99d1

Browse files
ZheyuMagregkh
authored andcommitted
media: cx88: Fix a null-ptr-deref bug in buffer_prepare()
[ Upstream commit 2b064d91440b33fba5b452f2d1b31f13ae911d71 ] When the driver calls cx88_risc_buffer() to prepare the buffer, the function call may fail, resulting in a empty buffer and null-ptr-deref later in buffer_queue(). The following log can reveal it: [ 41.822762] general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN PTI [ 41.824488] KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] [ 41.828027] RIP: 0010:buffer_queue+0xc2/0x500 [ 41.836311] Call Trace: [ 41.836945] __enqueue_in_driver+0x141/0x360 [ 41.837262] vb2_start_streaming+0x62/0x4a0 [ 41.838216] vb2_core_streamon+0x1da/0x2c0 [ 41.838516] __vb2_init_fileio+0x981/0xbc0 [ 41.839141] __vb2_perform_fileio+0xbf9/0x1120 [ 41.840072] vb2_fop_read+0x20e/0x400 [ 41.840346] v4l2_read+0x215/0x290 [ 41.840603] vfs_read+0x162/0x4c0 Fix this by checking the return value of cx88_risc_buffer() [hverkuil: fix coding style issues] Signed-off-by: Zheyu Ma <zheyuma97@gmail.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent de64347 commit 10c99d1

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

drivers/media/pci/cx88/cx88-vbi.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,10 @@ static int buffer_prepare(struct vb2_buffer *vb)
144144
return -EINVAL;
145145
vb2_set_plane_payload(vb, 0, size);
146146

147-
cx88_risc_buffer(dev->pci, &buf->risc, sgt->sgl,
148-
0, VBI_LINE_LENGTH * lines,
149-
VBI_LINE_LENGTH, 0,
150-
lines);
151-
return 0;
147+
return cx88_risc_buffer(dev->pci, &buf->risc, sgt->sgl,
148+
0, VBI_LINE_LENGTH * lines,
149+
VBI_LINE_LENGTH, 0,
150+
lines);
152151
}
153152

154153
static void buffer_finish(struct vb2_buffer *vb)

drivers/media/pci/cx88/cx88-video.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ static int queue_setup(struct vb2_queue *q,
452452

453453
static int buffer_prepare(struct vb2_buffer *vb)
454454
{
455+
int ret;
455456
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
456457
struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
457458
struct cx88_core *core = dev->core;
@@ -466,43 +467,43 @@ static int buffer_prepare(struct vb2_buffer *vb)
466467

467468
switch (core->field) {
468469
case V4L2_FIELD_TOP:
469-
cx88_risc_buffer(dev->pci, &buf->risc,
470-
sgt->sgl, 0, UNSET,
471-
buf->bpl, 0, core->height);
470+
ret = cx88_risc_buffer(dev->pci, &buf->risc,
471+
sgt->sgl, 0, UNSET,
472+
buf->bpl, 0, core->height);
472473
break;
473474
case V4L2_FIELD_BOTTOM:
474-
cx88_risc_buffer(dev->pci, &buf->risc,
475-
sgt->sgl, UNSET, 0,
476-
buf->bpl, 0, core->height);
475+
ret = cx88_risc_buffer(dev->pci, &buf->risc,
476+
sgt->sgl, UNSET, 0,
477+
buf->bpl, 0, core->height);
477478
break;
478479
case V4L2_FIELD_SEQ_TB:
479-
cx88_risc_buffer(dev->pci, &buf->risc,
480-
sgt->sgl,
481-
0, buf->bpl * (core->height >> 1),
482-
buf->bpl, 0,
483-
core->height >> 1);
480+
ret = cx88_risc_buffer(dev->pci, &buf->risc,
481+
sgt->sgl,
482+
0, buf->bpl * (core->height >> 1),
483+
buf->bpl, 0,
484+
core->height >> 1);
484485
break;
485486
case V4L2_FIELD_SEQ_BT:
486-
cx88_risc_buffer(dev->pci, &buf->risc,
487-
sgt->sgl,
488-
buf->bpl * (core->height >> 1), 0,
489-
buf->bpl, 0,
490-
core->height >> 1);
487+
ret = cx88_risc_buffer(dev->pci, &buf->risc,
488+
sgt->sgl,
489+
buf->bpl * (core->height >> 1), 0,
490+
buf->bpl, 0,
491+
core->height >> 1);
491492
break;
492493
case V4L2_FIELD_INTERLACED:
493494
default:
494-
cx88_risc_buffer(dev->pci, &buf->risc,
495-
sgt->sgl, 0, buf->bpl,
496-
buf->bpl, buf->bpl,
497-
core->height >> 1);
495+
ret = cx88_risc_buffer(dev->pci, &buf->risc,
496+
sgt->sgl, 0, buf->bpl,
497+
buf->bpl, buf->bpl,
498+
core->height >> 1);
498499
break;
499500
}
500501
dprintk(2,
501502
"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
502503
buf, buf->vb.vb2_buf.index,
503504
core->width, core->height, dev->fmt->depth, dev->fmt->name,
504505
(unsigned long)buf->risc.dma);
505-
return 0;
506+
return ret;
506507
}
507508

508509
static void buffer_finish(struct vb2_buffer *vb)

0 commit comments

Comments
 (0)