Skip to contentSkip to conversation

media: hantro: Harden MPEG-2 control access against NULL

PATCH In review Tharit Tangkijwanichakul 2 participants 2 messages Jul 31 – Aug 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: hantro: Harden MPEG-2 control access against NULL

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")

---
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(+)
drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c +5 -0
index e0d6bd0a6e44..6a942f4b8a2d 100644
@@ -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) |
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 1/1
#1 lore raw

Le vendredi 31 juillet 2026 à 14:07 +0000, Tharit Tangkijwanichakul a écrit :

Quoted 5 lines

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.

Quoted 7 lines

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")

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

Quoted 25 lines

---
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(+)
drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c +0 -0
index e0d6bd0a6e44..6a942f4b8a2d 100644
@@ -161,8 +161,13 @@ int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)


  seq = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_MPEG2_SEQUENCE);

drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c +3 -0
+	if (WARN_ON(!seq))
+		return -EINVAL;
+

  pic = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_MPEG2_PICTURE);

drivers/media/platform/verisilicon/hantro_g1_mpeg2_dec.c +2 -0
+	if (WARN_ON(!pic))
+		return -EINVAL;


  reg = G1_REG_DEC_AXI_RD_ID(0) |
        G1_REG_DEC_TIMEOUT_E(1) |