media: dvb_vb2: fix possible out of bound access

vb2_core_qbuf and vb2_core_querybuf don't check the range of b->index
controlled by the user.

Fix this by adding range checking code before using them.

Fixes: 57868acc369a ("media: videobuf2: Add new uAPI for DVB streaming I/O")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

authored by Hangyu Hua and committed by Mauro Carvalho Chehab 37238699 f0da34f3

Changed files
+11
drivers
media
dvb-core
+11
drivers/media/dvb-core/dvb_vb2.c
··· 354 354 355 355 int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) 356 356 { 357 + struct vb2_queue *q = &ctx->vb_q; 358 + 359 + if (b->index >= q->num_buffers) { 360 + dprintk(1, "[%s] buffer index out of range\n", ctx->name); 361 + return -EINVAL; 362 + } 357 363 vb2_core_querybuf(&ctx->vb_q, b->index, b); 358 364 dprintk(3, "[%s] index=%d\n", ctx->name, b->index); 359 365 return 0; ··· 384 378 385 379 int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) 386 380 { 381 + struct vb2_queue *q = &ctx->vb_q; 387 382 int ret; 388 383 384 + if (b->index >= q->num_buffers) { 385 + dprintk(1, "[%s] buffer index out of range\n", ctx->name); 386 + return -EINVAL; 387 + } 389 388 ret = vb2_core_qbuf(&ctx->vb_q, b->index, b, NULL); 390 389 if (ret) { 391 390 dprintk(1, "[%s] index=%d errno=%d\n", ctx->name,