MEDIA CODA: Fix NULL ptr dereference in the encoder.
PATCH 1/1 MEDIA CODA: Fix NULL ptr dereference in the encoder.
ctx->mb_err_cnt_ctrl could be NULL in case of failed initialization (on decoders), and encoders don't use it at all.
drivers/media/platform/coda/coda-bit.c +4 -2
@@ -2373,8 +2373,10 @@ static void coda_finish_decode(struct coda_ctx *ctx)if (err_mb >0 ) {if (__ratelimit (&dev->mb_err_rs))coda_dbg (1 , ctx,"errors in %d macroblocks\n" , err_mb); -v4l2_ctrl_s_ctrl (ctx->mb_err_cnt_ctrl, -v4l2_ctrl_g_ctrl (ctx->mb_err_cnt_ctrl) + err_mb); +if (ctx->mb_err_cnt_ctrl) +v4l2_ctrl_s_ctrl (ctx->mb_err_cnt_ctrl, +v4l2_ctrl_g_ctrl (ctx->mb_err_cnt_ctrl) + + err_mb); } if (dev->devtype->product == CODA_HX4 ||
drivers/media/platform/coda/coda-common.c +2 -1
@@ -2062,7 +2062,8 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)if (q_data_dst->fourcc ==V4L2_PIX_FMT_JPEG ) ctx->params.gop_size =1 ; ctx->gopcounter = ctx->params.gop_size -1 ; -v4l2_ctrl_s_ctrl (ctx->mb_err_cnt_ctrl,0 ); +if (ctx->mb_err_cnt_ctrl) +v4l2_ctrl_s_ctrl (ctx->mb_err_cnt_ctrl,0 ); ret = ctx->ops->start_streaming (ctx);if (ctx->inst_type ==CODA_INST_DECODER ) {
Signature · 5 lines
Krzysztof Hałasa Sieć Badawcza Łukasiewicz Przemysłowy Instytut Automatyki i Pomiarów PIAP Al. Jerozolimskie 202, 02-486 Warszawa
Hi Krzysztof,
thank you for the patch.
Quoted 14 lines · Krzysztof Halasa
ctx->mb_err_cnt_ctrlcould be NULL in case of failed initialization (on decoders), and encoders don't use it at all.Fixes b2d3bef1aa78 ("media: coda: Add a V4L2 user for control error macroblocks count")Signed-off-by Krzysztof Halasa <[email protected]>Cc [email protected] # 5.11+drivers/media/platform/coda/coda-bit.c +0
-0@@ -2373,8 +2373,10 @@ static void coda_finish_decode(struct coda_ctx *ctx)if (err_mb >0 ) {if (__ratelimit (&dev->mb_err_rs))
drivers/media/platform/coda/coda-bit.c static void coda_finish_decode(struct coda_ctx *ctx) · line 2382
Quoted 10 lines
drivers/media/platform/coda/coda-bit.c +4
-2coda_dbg (1 , ctx,"errors in %d macroblocks\n" , err_mb); -v4l2_ctrl_s_ctrl (ctx->mb_err_cnt_ctrl, -v4l2_ctrl_g_ctrl (ctx->mb_err_cnt_ctrl) + err_mb); +if (ctx->mb_err_cnt_ctrl) +v4l2_ctrl_s_ctrl (ctx->mb_err_cnt_ctrl, +v4l2_ctrl_g_ctrl (ctx->mb_err_cnt_ctrl) + + err_mb); } if (dev->devtype->product == CODA_HX4 ||
I don't think this is required though. If v4l2_ctrl_new_custom() fails in coda_ctrls_setup(), ctx->ctrls.error is set and the function returns -EINVAL, causing coda_open() to fail with the error message "failed to setup coda controls". I see no way to reach coda_finish_decode() without ctx->mb_err_cnt_ctrl being set correctly.
Quoted 5 lines
drivers/media/platform/coda/coda-common.c +0
-0
drivers/media/platform/coda/coda-common.c static int coda_start_streaming(struct vb2_queue *q, unsigned int count) · line 2069
Quoted 9 lines
drivers/media/platform/coda/coda-common.c +2
-1@@ -2062,7 +2062,8 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)if (q_data_dst->fourcc ==V4L2_PIX_FMT_JPEG ) ctx->params.gop_size =1 ; ctx->gopcounter = ctx->params.gop_size -1 ; -v4l2_ctrl_s_ctrl (ctx->mb_err_cnt_ctrl,0 ); +if (ctx->mb_err_cnt_ctrl) +v4l2_ctrl_s_ctrl (ctx->mb_err_cnt_ctrl,0 ); ret = ctx->ops->start_streaming (ctx);if (ctx->inst_type ==CODA_INST_DECODER ) {
This is already fixed by [1] in media-tree/master.
[1] 0b276e470a4d ("media: coda: fix macroblocks count control usage")
regards
Philipp
Hi Philipp,
Quoted 1 line
I don't think this is required though.
and
Quoted 1 line
This is already fixed by [1] in media-tree/master.
Ok, thanks, sorry for the noise.
Signature · 5 lines
Krzysztof Hałasa Sieć Badawcza Łukasiewicz Przemysłowy Instytut Automatyki i Pomiarów PIAP Al. Jerozolimskie 202, 02-486 Warszawa