Skip to contentSkip to conversation

media: i2c: tda1997x: fix out-of-bounds read with a one-block EDID

PATCH New Hyunjung Ko 1 participant 1 message Nov 17

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

PATCH 1/1 media: i2c: tda1997x: fix out-of-bounds read with a one-block EDID

tda1997x_set_edid() accepts one or two EDID blocks, but always reads 256 bytes from edid->edid: once when programming the CEA extension registers and once when saving the EDID in the driver state. For a one-block EDID the buffer allocated by the V4L2 core is only 128 bytes, so VIDIOC_SUBDEV_S_EDID with blocks = 1 reads 128 bytes past the end of it and writes that data to the chip.

Copy only the blocks that were passed in, zero the rest, and program the chip from the saved copy.

Fixes 9ac0038db9a7 ("media: i2c: Add TDA1997x HDMI receiver driver")
---
 drivers/media/i2c/tda1997x.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/media/i2c/tda1997x.c +7 -6
index 30dfd8a7b42b..a523fc2b2b71 100644
@@ -1891,17 +1891,18 @@ static int tda1997x_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
 
 	tda1997x_disable_edid(sd);
 
+	/* store state */
+	memset(state->edid.edid, 0, sizeof(state->edid.edid));
+	memcpy(state->edid.edid, edid->edid, edid->blocks * 128);
+	state->edid.blocks = edid->blocks;
+
 	/* write base EDID */
 	for (i = 0; i < 128; i++)
-		io_write(sd, REG_EDID_IN_BYTE0 + i, edid->edid[i]);
+		io_write(sd, REG_EDID_IN_BYTE0 + i, state->edid.edid[i]);
 
 	/* write CEA Extension */
 	for (i = 0; i < 128; i++)
-		io_write(sd, REG_EDID_IN_BYTE128 + i, edid->edid[i+128]);
-
-	/* store state */
-	memcpy(state->edid.edid, edid->edid, 256);
-	state->edid.blocks = edid->blocks;
+		io_write(sd, REG_EDID_IN_BYTE128 + i, state->edid.edid[i + 128]);
 
 	tda1997x_enable_edid(sd);
 
Signature · 1 line
2.43.0