Skip to contentSkip to conversation

accel/ivpu: Add buffer overflow check in MS get_info_ioctl

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 buffer overflow check in MS get_info_ioctl

Add validation that the info size returned from the metric stream info query is not exceeded when checked against the allocated buffer size. If the firmware returns a size larger than the buffer, reject the operation with -EOVERFLOW instead of proceeding with an incorrect buffer copy.

Fixes cdfad4db7756 ("accel/ivpu: Add NPU profiling support")
Cc <[email protected]> # v6.18+
---
 drivers/accel/ivpu/ivpu_ms.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/accel/ivpu/ivpu_ms.c +7 -0
index be43851f5f32..cd176e77b9a0 100644
@@ -291,6 +291,13 @@ int ivpu_ms_get_info_ioctl(struct drm_device *dev, void *data, struct drm_file *
 	if (ret)
 		goto unlock;
 
+	if (info_size > ivpu_bo_size(bo)) {
+		ivpu_warn_ratelimited(vdev, "MS info overflow: %#llx > %#zx\n",
+				      info_size, ivpu_bo_size(bo));
+		ret = -EOVERFLOW;
+		goto unlock;
+	}
+
 	if (args->buffer_size < info_size) {
 		ret = -ENOSPC;
 		goto unlock;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrzej Kacprowski

Add validation that the info size returned from the metric stream info query is not exceeded when checked against the allocated buffer size. If the firmware returns a size larger than the buffer, reject the operation with -EOVERFLOW instead of proceeding with an incorrect buffer copy.

Fixes cdfad4db7756 ("accel/ivpu: Add NPU profiling support")
Cc <[email protected]> # v6.18+
Quoted 22 lines
---
  drivers/accel/ivpu/ivpu_ms.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/accel/ivpu/ivpu_ms.c +7 -0
index be43851f5f32..cd176e77b9a0 100644
@@ -291,6 +291,13 @@ int ivpu_ms_get_info_ioctl(struct drm_device *dev, void *data, struct drm_file *
  	if (ret)
  		goto unlock;
 
+	if (info_size > ivpu_bo_size(bo)) {
+		ivpu_warn_ratelimited(vdev, "MS info overflow: %#llx > %#zx\n",
+				      info_size, ivpu_bo_size(bo));
+		ret = -EOVERFLOW;
+		goto unlock;
+	}
+
  	if (args->buffer_size < info_size) {
  		ret = -ENOSPC;
  		goto unlock;
maintainer Applied
#2 lore raw
Quoted 7 lines · Karol
Quoted 6 lines · Andrzej Kacprowski

Add validation that the info size returned from the metric stream info query is not exceeded when checked against the allocated buffer size. If the firmware returns a size larger than the buffer, reject the operation with -EOVERFLOW instead of proceeding with an incorrect buffer copy.

Quoted 5 lines
Quoted 3 lines
Fixes cdfad4db7756 ("accel/ivpu: Add NPU profiling support")
Cc <[email protected]> # v6.18+

Applied to drm-misc-fixes.

Quoted 25 lines
Quoted 23 lines

---
  drivers/accel/ivpu/ivpu_ms.c | 7 +++++++

  1 file changed, 7 insertions(+)
drivers/accel/ivpu/ivpu_ms.c +7 -0
index be43851f5f32..cd176e77b9a0 100644
@@ -291,6 +291,13 @@ int ivpu_ms_get_info_ioctl(struct drm_device 
 *dev, void *data, struct drm_file *
       if (ret)
           goto unlock;
+    if (info_size > ivpu_bo_size(bo)) {
+        ivpu_warn_ratelimited(vdev, "MS info overflow: %#llx > %#zx\n",
+                      info_size, ivpu_bo_size(bo));
+        ret = -EOVERFLOW;
+        goto unlock;
+    }
+
       if (args->buffer_size < info_size) {
           ret = -ENOSPC;
           goto unlock;