* [PATCH] media: hantro: Harden MPEG-2 control access against NULL
@ 2026-07-31 14:07 Tharit Tangkijwanichakul
2026-08-10 14:09 ` Nicolas Dufresne
0 siblings, 1 reply; 2+ messages in thread
From: Tharit Tangkijwanichakul @ 2026-07-31 14:07 UTC (permalink / raw)
To: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel, linux-media
Cc: Mauro Carvalho Chehab, Hans Verkuil, Ezequiel Garcia,
Jernej Skrabec, linux-rockchip, linux-kernel,
linux-kernel-mentees, skhan, me, jkoolstra,
Tharit Tangkijwanichakul
The MPEG-2 sequence and picture controls are validated
before a job is queued, so hantro_get_ctrl() is not expected to return
NULL in hantro_g1_mpeg2_dec_run(). The controls are nonetheless
dereferenced unconditionally.
Harden the invariant by checking the sequence and picture controls with
WARN_ON().
Found by code inspection.
Fixes: f329e21e9dad ("media: uapi: mpeg2: Split sequence and picture parameters")
Signed-off-by: Tharit Tangkijwanichakul <tharitt97@gmail.com>
---
Tested on a Rockchip RK3588 (Rock 5B) board with Fluster:
MPEG-2 (MPEG2_VIDEO-MAIN): 23/43, unchanged
drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c b/drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c
index e0d6bd0a6e44..6a942f4b8a2d 100644
--- a/drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c
+++ b/drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c
@@ -161,8 +161,13 @@ int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
seq = hantro_get_ctrl(ctx,
V4L2_CID_STATELESS_MPEG2_SEQUENCE);
+ if (WARN_ON(!seq))
+ return -EINVAL;
+
pic = hantro_get_ctrl(ctx,
V4L2_CID_STATELESS_MPEG2_PICTURE);
+ if (WARN_ON(!pic))
+ return -EINVAL;
reg = G1_REG_DEC_AXI_RD_ID(0) |
G1_REG_DEC_TIMEOUT_E(1) |
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] media: hantro: Harden MPEG-2 control access against NULL
2026-07-31 14:07 [PATCH] media: hantro: Harden MPEG-2 control access against NULL Tharit Tangkijwanichakul
@ 2026-08-10 14:09 ` Nicolas Dufresne
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Dufresne @ 2026-08-10 14:09 UTC (permalink / raw)
To: Tharit Tangkijwanichakul, Benjamin Gaignard, Philipp Zabel,
linux-media
Cc: Mauro Carvalho Chehab, Hans Verkuil, Ezequiel Garcia,
Jernej Skrabec, linux-rockchip, linux-kernel,
linux-kernel-mentees, skhan, me, jkoolstra
[-- Attachment #1: Type: text/plain, Size: 1886 bytes --]
Le vendredi 31 juillet 2026 à 14:07 +0000, Tharit Tangkijwanichakul a écrit :
> The MPEG-2 sequence and picture controls are validated
> before a job is queued, so hantro_get_ctrl() is not expected to return
> NULL in hantro_g1_mpeg2_dec_run(). The controls are nonetheless
> dereferenced unconditionally.
>
> Harden the invariant by checking the sequence and picture controls with
> WARN_ON().
>
> Found by code inspection.
>
> Fixes: f329e21e9dad ("media: uapi: mpeg2: Split sequence and picture parameters")
> Signed-off-by: Tharit Tangkijwanichakul <tharitt97@gmail.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
p.s. this is a bit cosmetic, since only a programming error could lead to that,
once a control is registered, it has a value. But that makes it consistent with
all other use of hantro_get_ctrl() in this driver, which I like.
Nicolas
> ---
> Tested on a Rockchip RK3588 (Rock 5B) board with Fluster:
> MPEG-2 (MPEG2_VIDEO-MAIN): 23/43, unchanged
>
> drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c b/drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c
> index e0d6bd0a6e44..6a942f4b8a2d 100644
> --- a/drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c
> +++ b/drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c
> @@ -161,8 +161,13 @@ int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
>
> seq = hantro_get_ctrl(ctx,
> V4L2_CID_STATELESS_MPEG2_SEQUENCE);
> + if (WARN_ON(!seq))
> + return -EINVAL;
> +
> pic = hantro_get_ctrl(ctx,
> V4L2_CID_STATELESS_MPEG2_PICTURE);
> + if (WARN_ON(!pic))
> + return -EINVAL;
>
> reg = G1_REG_DEC_AXI_RD_ID(0) |
> G1_REG_DEC_TIMEOUT_E(1) |
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-10 14:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-31 14:07 [PATCH] media: hantro: Harden MPEG-2 control access against NULL Tharit Tangkijwanichakul
2026-08-10 14:09 ` Nicolas Dufresne
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox