Skip to contentSkip to conversation

media: synopsys: hdmirx: fix integer overflow in hdmirx_get_edid()

PATCH In review Dan Carpenter 2 participants 2 messages Jan 8

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

PATCH 1/1 media: synopsys: hdmirx: fix integer overflow in hdmirx_get_edid()

The "edid->blocks" variable comes from the user via the ioctl. It's a u32 and "edid->start_block" is a u32 too. The addition operation could have an integer wrapping bug, so use the size_add() function to prevent that.

Fixes 7b59b132ad43 ("media: platform: synopsys: Add support for HDMI input driver")
---
 drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c +1 -1
index c3007e09bc9f..f054e30cbfb0 100644
@@ -717,7 +717,7 @@ static int hdmirx_get_edid(struct file *file, void *fh, struct v4l2_edid *edid)
 	if (edid->start_block >= hdmirx_dev->edid_blocks_written || !edid->blocks)
 		return -EINVAL;
 
-	if (edid->start_block + edid->blocks > hdmirx_dev->edid_blocks_written)
+	if (size_add(edid->start_block, edid->blocks) > hdmirx_dev->edid_blocks_written)
 		edid->blocks = hdmirx_dev->edid_blocks_written - edid->start_block;
 
 	memcpy(edid->edid, hdmirx_dev->edid, edid->blocks * EDID_BLOCK_SIZE);
Signature · 1 line
2.51.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Dan Carpenter

The "edid->blocks" variable comes from the user via the ioctl. It's a u32 and "edid->start_block" is a u32 too. The addition operation could have an integer wrapping bug, so use the size_add() function to prevent that.

Fixes 7b59b132ad43 ("media: platform: synopsys: Add support for HDMI input driver")
---
 drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c +0 -0
index c3007e09bc9f..f054e30cbfb0 100644

drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c static int hdmirx_get_edid(struct file *file, void *fh, struct v4l2_edid *edid) · line 723

Quoted 8 lines
drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c +1 -1
@@ -717,7 +717,7 @@ static int hdmirx_get_edid(struct file *file, void *fh, struct v4l2_edid *edid)
 	if (edid->start_block >= hdmirx_dev->edid_blocks_written || !edid->blocks)
 		return -EINVAL;
 
-	if (edid->start_block + edid->blocks > hdmirx_dev->edid_blocks_written)
+	if (size_add(edid->start_block, edid->blocks) > hdmirx_dev->edid_blocks_written)
 		edid->blocks = hdmirx_dev->edid_blocks_written - edid->start_block;
 
 	memcpy(edid->edid, hdmirx_dev->edid, edid->blocks * EDID_BLOCK_SIZE);
Signature · 2 lines
Best regards,
Dmitry