Skip to contentSkip to conversation

hwmon: asus_atk0110: NULL buf.pointer after free

PATCH In review Purva Yeshi 2 participants 3 messages Apr 10, 2025 – Apr 11, 2025

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

PATCH 1/1 hwmon: asus_atk0110: NULL buf.pointer after free

Fix Smatch-detected issue:
drivers/hwmon/asus_atk0110.c:987 atk_enumerate_old_hwmon() error:
double free of 'buf.pointer' (line 966) drivers/hwmon/asus_atk0110.c:1008 atk_enumerate_old_hwmon() error:
double free of 'buf.pointer' (line 987)

Smatch warns about double free of 'buf.pointer'.
This happens because the same buffer struct is reused multiple times without resetting the pointer after free. Set buf.pointer = NULL after each ACPI_FREE to prevent possible use-after-free bugs.

---
 drivers/hwmon/asus_atk0110.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hwmon/asus_atk0110.c +3 -0
index c80350e499e9..83ee7f25bb8e 100644
@@ -964,6 +964,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data)
 			count++;
 	}
 	ACPI_FREE(buf.pointer);
+	buf.pointer = NULL;
 
 	/* Temperatures */
 	buf.length = ACPI_ALLOCATE_BUFFER;
@@ -985,6 +986,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data)
 			count++;
 	}
 	ACPI_FREE(buf.pointer);
+	buf.pointer = NULL;
 
 	/* Fans */
 	buf.length = ACPI_ALLOCATE_BUFFER;
@@ -1006,6 +1008,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data)
 			count++;
 	}
 	ACPI_FREE(buf.pointer);
+	buf.pointer = NULL;
 
 	return count;
 }
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 29 lines · Purva Yeshi

Fix Smatch-detected issue:
drivers/hwmon/asus_atk0110.c:987 atk_enumerate_old_hwmon() error:
double free of 'buf.pointer' (line 966) drivers/hwmon/asus_atk0110.c:1008 atk_enumerate_old_hwmon() error:
double free of 'buf.pointer' (line 987)

Smatch warns about double free of 'buf.pointer'.
This happens because the same buffer struct is reused multiple times without resetting the pointer after free. Set buf.pointer = NULL after each ACPI_FREE to prevent possible use-after-free bugs.

---
 drivers/hwmon/asus_atk0110.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hwmon/asus_atk0110.c +1 -0
index c80350e499e9..83ee7f25bb8e 100644
@@ -964,6 +964,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data)
 			count++;
 	}
 	ACPI_FREE(buf.pointer);
+	buf.pointer = NULL;
 
 	/* Temperatures */
 	buf.length = ACPI_ALLOCATE_BUFFER;

drivers/hwmon/asus_atk0110.c static int atk_enumerate_old_hwmon(struct atk_data *data) · line 992

Quoted 7 lines
drivers/hwmon/asus_atk0110.c +1 -0
@@ -985,6 +986,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data)
 			count++;
 	}
 	ACPI_FREE(buf.pointer);
+	buf.pointer = NULL;
 
 	/* Fans */
 	buf.length = ACPI_ALLOCATE_BUFFER;

buf.length is set to ACPI_ALLOCATE_BUFFER to trigger buffer allocation in acpi_evaluate_object_typed(). The old content of buf.pointer is irrelevant (and not initialized to start with in the first call). The problem you describe does not exist.

Guenter

Quoted 12 lines
drivers/hwmon/asus_atk0110.c +1 -0
@@ -1006,6 +1008,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data)
 			count++;
 	}
 	ACPI_FREE(buf.pointer);
+	buf.pointer = NULL;
 
 	return count;
 }
Signature · 1 line
2.34.1
#2 lore raw
Quoted 43 lines · Guenter Roeck
Quoted 29 lines · Purva Yeshi

Fix Smatch-detected issue:
drivers/hwmon/asus_atk0110.c:987 atk_enumerate_old_hwmon() error:
double free of 'buf.pointer' (line 966) drivers/hwmon/asus_atk0110.c:1008 atk_enumerate_old_hwmon() error:
double free of 'buf.pointer' (line 987)

Smatch warns about double free of 'buf.pointer'.
This happens because the same buffer struct is reused multiple times without resetting the pointer after free. Set buf.pointer = NULL after each ACPI_FREE to prevent possible use-after-free bugs.

---
  drivers/hwmon/asus_atk0110.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/hwmon/asus_atk0110.c +1 -0
index c80350e499e9..83ee7f25bb8e 100644
@@ -964,6 +964,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data)
  			count++;
  	}
  	ACPI_FREE(buf.pointer);
+	buf.pointer = NULL;
 
  	/* Temperatures */
  	buf.length = ACPI_ALLOCATE_BUFFER;

drivers/hwmon/asus_atk0110.c static int atk_enumerate_old_hwmon(struct atk_data *data) · line 992

Quoted 7 lines
drivers/hwmon/asus_atk0110.c +1 -0
@@ -985,6 +986,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data)
  			count++;
  	}
  	ACPI_FREE(buf.pointer);
+	buf.pointer = NULL;
 
  	/* Fans */
  	buf.length = ACPI_ALLOCATE_BUFFER;

buf.length is set to ACPI_ALLOCATE_BUFFER to trigger buffer allocation in acpi_evaluate_object_typed(). The old content of buf.pointer is irrelevant (and not initialized to start with in the first call). The problem you describe does not exist.

Quoted 1 line

Guenter

Thank you for the clarification, Guenter. I appreciate your review.

Quoted 7 lines
Quoted 7 lines
drivers/hwmon/asus_atk0110.c +1 -0
@@ -1006,6 +1008,7 @@ static int atk_enumerate_old_hwmon(struct atk_data *data)
  			count++;
  	}
  	ACPI_FREE(buf.pointer);
+	buf.pointer = NULL;
 
Quoted 6 lines
Quoted 6 lines
drivers/hwmon/asus_atk0110.c +0 -0
  	return count;
  }
Signature · 1 line
2.34.1

Best regards,
Purva