* [PATCH RESENT] MEDIA CODA: Fix NULL ptr dereference in the encoder.
@ 2021-06-07 11:05 Krzysztof Halasa
2021-06-08 9:55 ` Philipp Zabel
0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Halasa @ 2021-06-07 11:05 UTC (permalink / raw)
To: Philipp Zabel; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel
ctx->mb_err_cnt_ctrl could 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 <khalasa@piap.pl>
Cc: stable@vger.kernel.org # 5.11+
diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index 2f42808c43a4..26e37cbfe8dd 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -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 ||
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 96802b8f47ea..285c80f87b65 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -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) {
--
Krzysztof Hałasa
Sieć Badawcza Łukasiewicz
Przemysłowy Instytut Automatyki i Pomiarów PIAP
Al. Jerozolimskie 202, 02-486 Warszawa
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH RESENT] MEDIA CODA: Fix NULL ptr dereference in the encoder.
2021-06-07 11:05 [PATCH RESENT] MEDIA CODA: Fix NULL ptr dereference in the encoder Krzysztof Halasa
@ 2021-06-08 9:55 ` Philipp Zabel
2021-06-10 6:14 ` Krzysztof Hałasa
0 siblings, 1 reply; 3+ messages in thread
From: Philipp Zabel @ 2021-06-08 9:55 UTC (permalink / raw)
To: Krzysztof Halasa; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel
Hi Krzysztof,
thank you for the patch.
On Mon, 2021-06-07 at 13:05 +0200, Krzysztof Halasa wrote:
> ctx->mb_err_cnt_ctrl could 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 <khalasa@piap.pl>
> Cc: stable@vger.kernel.org # 5.11+
>
> diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
> index 2f42808c43a4..26e37cbfe8dd 100644
> --- a/drivers/media/platform/coda/coda-bit.c
> +++ b/drivers/media/platform/coda/coda-bit.c
> @@ -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 ||
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.
> diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
> index 96802b8f47ea..285c80f87b65 100644
> --- a/drivers/media/platform/coda/coda-common.c
> +++ b/drivers/media/platform/coda/coda-common.c
> @@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESENT] MEDIA CODA: Fix NULL ptr dereference in the encoder.
2021-06-08 9:55 ` Philipp Zabel
@ 2021-06-10 6:14 ` Krzysztof Hałasa
0 siblings, 0 replies; 3+ messages in thread
From: Krzysztof Hałasa @ 2021-06-10 6:14 UTC (permalink / raw)
To: Philipp Zabel; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel
Hi Philipp,
> I don't think this is required though.
and
> This is already fixed by [1] in media-tree/master.
Ok, thanks, sorry for the noise.
--
Krzysztof Hałasa
Sieć Badawcza Łukasiewicz
Przemysłowy Instytut Automatyki i Pomiarów PIAP
Al. Jerozolimskie 202, 02-486 Warszawa
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-10 6:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-07 11:05 [PATCH RESENT] MEDIA CODA: Fix NULL ptr dereference in the encoder Krzysztof Halasa
2021-06-08 9:55 ` Philipp Zabel
2021-06-10 6:14 ` Krzysztof Hałasa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).