Skip to contentSkip to conversation

accel/ivpu: Add bounds check for firmware runtime memory

PATCH Applied Andrzej Kacprowski 2 participants 3 messages May 29 – Jun 2

Subsystems (3)
lore
Share & tools
lore

Andrzej Kacprowski

author maintainer
#0 lore raw

PATCH 1/1 accel/ivpu: Add bounds check for firmware runtime memory

Validate that the firmware runtime memory specified in the image header is properly aligned and sized to hold the firmware image. This prevents errors during memory allocation and image transfer.

Fixes 2007e210b6a1 ("accel/ivpu: Split FW runtime and global memory buffers")
Cc <[email protected]> # v7.0+
---
 drivers/accel/ivpu/ivpu_fw.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/accel/ivpu/ivpu_fw.c +16 -0
index 107f8ad31050..33c50779c06b 100644
@@ -259,6 +259,22 @@ static int ivpu_fw_parse(struct ivpu_device *vdev)
 		return -EINVAL;
 	}
 
+	if (!PAGE_ALIGNED(runtime_addr)) {
+		ivpu_err(vdev, "Runtime address 0x%llx not page aligned\n", runtime_addr);
+		return -EINVAL;
+	}
+
+	if (!PAGE_ALIGNED(runtime_size)) {
+		ivpu_err(vdev, "Runtime size %llu not page aligned\n", runtime_size);
+		return -EINVAL;
+	}
+
+	if (runtime_size < image_size) {
+		ivpu_err(vdev, "Runtime size too small: %llu, image size: %llu\n",
+			 runtime_size, image_size);
+		return -EINVAL;
+	}
+
 	if (!ivpu_is_within_range(image_load_addr, image_size, &vdev->hw->ranges.runtime)) {
 		ivpu_err(vdev, "Invalid firmware load address: 0x%llx and size %llu\n",
 			 image_load_addr, image_size);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Andrzej Kacprowski

Validate that the firmware runtime memory specified in the image header is properly aligned and sized to hold the firmware image. This prevents errors during memory allocation and image transfer.

Fixes 2007e210b6a1 ("accel/ivpu: Split FW runtime and global memory buffers")
Cc <[email protected]> # v7.0+
Quoted 31 lines
---
  drivers/accel/ivpu/ivpu_fw.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
drivers/accel/ivpu/ivpu_fw.c +16 -0
index 107f8ad31050..33c50779c06b 100644
@@ -259,6 +259,22 @@ static int ivpu_fw_parse(struct ivpu_device *vdev)
  		return -EINVAL;
  	}
 
+	if (!PAGE_ALIGNED(runtime_addr)) {
+		ivpu_err(vdev, "Runtime address 0x%llx not page aligned\n", runtime_addr);
+		return -EINVAL;
+	}
+
+	if (!PAGE_ALIGNED(runtime_size)) {
+		ivpu_err(vdev, "Runtime size %llu not page aligned\n", runtime_size);
+		return -EINVAL;
+	}
+
+	if (runtime_size < image_size) {
+		ivpu_err(vdev, "Runtime size too small: %llu, image size: %llu\n",
+			 runtime_size, image_size);
+		return -EINVAL;
+	}
+
  	if (!ivpu_is_within_range(image_load_addr, image_size, &vdev->hw->ranges.runtime)) {
  		ivpu_err(vdev, "Invalid firmware load address: 0x%llx and size %llu\n",
  			 image_load_addr, image_size);
maintainer Applied
#2 lore raw
Quoted 11 lines · Karol
Quoted 7 lines · Andrzej Kacprowski

Validate that the firmware runtime memory specified in the image header is properly aligned and sized to hold the firmware image. This prevents errors during memory allocation and image transfer.

Fixes 2007e210b6a1 ("accel/ivpu: Split FW runtime and global memory buffers")
Cc <[email protected]> # v7.0+

Applied to drm-misc-fixes.

Quoted 36 lines
Quoted 34 lines

---
  drivers/accel/ivpu/ivpu_fw.c | 16 ++++++++++++++++

  1 file changed, 16 insertions(+)
drivers/accel/ivpu/ivpu_fw.c +16 -0
index 107f8ad31050..33c50779c06b 100644
@@ -259,6 +259,22 @@ static int ivpu_fw_parse(struct ivpu_device *vdev)
           return -EINVAL;
       }
+    if (!PAGE_ALIGNED(runtime_addr)) {
+        ivpu_err(vdev, "Runtime address 0x%llx not page aligned\n", 
 runtime_addr);
+        return -EINVAL;
+    }
+
+    if (!PAGE_ALIGNED(runtime_size)) {
+        ivpu_err(vdev, "Runtime size %llu not page aligned\n", 
 runtime_size);
+        return -EINVAL;
+    }
+
+    if (runtime_size < image_size) {
+        ivpu_err(vdev, "Runtime size too small: %llu, image size: 
 %llu\n",
+             runtime_size, image_size);
+        return -EINVAL;
+    }
+

      if (!ivpu_is_within_range(image_load_addr, image_size, &vdev-

Quoted 1 line

hw->ranges.runtime)) {

          ivpu_err(vdev, "Invalid firmware load address: 0x%llx and size %llu\n", image_load_addr, image_size);