Skip to contentSkip to conversation

accel/ivpu: Add bounds checks for firmware log indices

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 checks for firmware log indices

Add validation that read and write indices in the firmware log buffer are within valid bounds (< data_size) before using them. If out-of-bounds indices are encountered (from firmware), clamp them to safe values instead of proceeding with invalid offsets.

This prevents potential out-of-bounds buffer access when firmware supplies invalid log indices.

Fixes 1fc1251149a7 ("accel/ivpu: Refactor functions in ivpu_fw_log.c")
Cc <[email protected]> # v6.18+
---
 drivers/accel/ivpu/ivpu_fw_log.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/accel/ivpu/ivpu_fw_log.c +5 -0
index 337c906b0210..275baf844b56 100644
@@ -98,6 +98,11 @@ static void fw_log_print_buffer(struct vpu_tracing_buffer_header *log, const cha
 	u32 log_start = only_new_msgs ? READ_ONCE(log->read_index) : 0;
 	u32 log_end = READ_ONCE(log->write_index);
 
+	if (log_start >= data_size)
+		log_start = 0;
+	if (log_end > data_size)
+		log_end = data_size;
+
 	if (log->wrap_count == log->read_wrap_count) {
 		if (log_end <= log_start) {
 			drm_printf(p, "==== %s \"%s\" log empty ====\n", prefix, log->name);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Andrzej Kacprowski

Add validation that read and write indices in the firmware log buffer are within valid bounds (< data_size) before using them. If out-of-bounds indices are encountered (from firmware), clamp them to safe values instead of proceeding with invalid offsets.

This prevents potential out-of-bounds buffer access when firmware supplies invalid log indices.

Fixes 1fc1251149a7 ("accel/ivpu: Refactor functions in ivpu_fw_log.c")
Cc <[email protected]> # v6.18+
Quoted 20 lines
---
  drivers/accel/ivpu/ivpu_fw_log.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/accel/ivpu/ivpu_fw_log.c +5 -0
index 337c906b0210..275baf844b56 100644
@@ -98,6 +98,11 @@ static void fw_log_print_buffer(struct vpu_tracing_buffer_header *log, const cha
  	u32 log_start = only_new_msgs ? READ_ONCE(log->read_index) : 0;
  	u32 log_end = READ_ONCE(log->write_index);
 
+	if (log_start >= data_size)
+		log_start = 0;
+	if (log_end > data_size)
+		log_end = data_size;
+
  	if (log->wrap_count == log->read_wrap_count) {
  		if (log_end <= log_start) {
  			drm_printf(p, "==== %s \"%s\" log empty ====\n", prefix, log->name);
maintainer Applied
#2 lore raw
Quoted 6 lines · Karol
Quoted 5 lines · Andrzej Kacprowski

Add validation that read and write indices in the firmware log buffer are within valid bounds (< data_size) before using them. If out-of-bounds indices are encountered (from firmware), clamp them to safe values instead of proceeding with invalid offsets.

Quoted 9 lines
Quoted 6 lines

This prevents potential out-of-bounds buffer access when firmware supplies invalid log indices.

Fixes 1fc1251149a7 ("accel/ivpu: Refactor functions in ivpu_fw_log.c")
Cc <[email protected]> # v6.18+

Applied to drm-misc-fixes.

Quoted 22 lines
Quoted 20 lines

---
  drivers/accel/ivpu/ivpu_fw_log.c | 5 +++++

  1 file changed, 5 insertions(+)
drivers/accel/ivpu/ivpu_fw_log.c +0 -0
index 337c906b0210..275baf844b56 100644
@@ -98,6 +98,11 @@ static void fw_log_print_buffer(struct 

vpu_tracing_buffer_header *log, const cha
      u32 log_start = only_new_msgs ? READ_ONCE(log->read_index) : 0; u32 log_end = READ_ONCE(log->write_index);
+    if (log_start >= data_size)
+        log_start = 0;
+    if (log_end > data_size)
+        log_end = data_size;
+
      if (log->wrap_count == log->read_wrap_count) {
          if (log_end <= log_start) {
              drm_printf(p, "==== %s \"%s\" log empty ====\n", prefix, log->name);