Skip to contentSkip to conversation

drm/panthor: harden firmware build-info bounds checks

PATCH In review Osama Abdelkader 2 participants 2 messages Jul 20 – Jul 29

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

PATCH 1/1 drm/panthor: harden firmware build-info bounds checks

panthor_fw_read_build_info() checks whether the metadata range fits in the firmware image with hdr.meta_start + hdr.meta_size. Both fields are u32, so the addition can wrap and let an out-of-bounds range pass validation.

The function also reads the "git_sha: " prefix without first checking that the metadata is long enough, and meta_size == 0 can underflow the NULL terminator index.

Use subtraction-based bounds checking and reject metadata that is too short to contain the expected prefix and trailing NULL byte.

Fixes 2718d91816ee ("drm/panthor: Add the FW logical block")
---
 drivers/gpu/drm/panthor/panthor_fw.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_fw.c +2 -1
index 6335893d3f16..9d0e1fafdce2 100644
@@ -709,7 +709,8 @@ static int panthor_fw_read_build_info(struct panthor_device *ptdev,
 		return ret;
 
 	if (hdr.meta_start > fw->size ||
-	    hdr.meta_start + hdr.meta_size > fw->size) {
+	    hdr.meta_size > fw->size - hdr.meta_start ||
+	    hdr.meta_size <= header_len) {
 		drm_err(&ptdev->base, "Firmware build info corrupt\n");
 		/* We don't need the build info, so continue */
 		return 0;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Osama Abdelkader

panthor_fw_read_build_info() checks whether the metadata range fits in the firmware image with hdr.meta_start + hdr.meta_size. Both fields are u32, so the addition can wrap and let an out-of-bounds range pass validation.

The function also reads the "git_sha: " prefix without first checking that the metadata is long enough, and meta_size == 0 can underflow the NULL terminator index.

Quoted 6 lines

Use subtraction-based bounds checking and reject metadata that is too short to contain the expected prefix and trailing NULL byte.

Fixes 2718d91816ee ("drm/panthor: Add the FW logical block")

I'll push this to drm-misc-fixes.

Thanks,
Steve

Quoted 18 lines
---
 drivers/gpu/drm/panthor/panthor_fw.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_fw.c +2 -1
index 6335893d3f16..9d0e1fafdce2 100644
@@ -709,7 +709,8 @@ static int panthor_fw_read_build_info(struct panthor_device *ptdev,
 		return ret;
 
 	if (hdr.meta_start > fw->size ||
-	    hdr.meta_start + hdr.meta_size > fw->size) {
+	    hdr.meta_size > fw->size - hdr.meta_start ||
+	    hdr.meta_size <= header_len) {
 		drm_err(&ptdev->base, "Firmware build info corrupt\n");
 		/* We don't need the build info, so continue */
 		return 0;