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

From: Hyunjung Ko

Date: Tue Nov 17 2026 - 04:45:39 EST


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")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hyunjung Ko <hj351016@xxxxxxxxx>
---
drivers/media/i2c/tda1997x.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/media/i2c/tda1997x.c b/drivers/media/i2c/tda1997x.c
index 30dfd8a7b42b..a523fc2b2b71 100644
--- a/drivers/media/i2c/tda1997x.c
+++ b/drivers/media/i2c/tda1997x.c
@@ -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);

--
2.43.0