hwmon: asus_atk0110: NULL buf.pointer after free
Subsystems (2)
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
@@ -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
Guenter Roeck
maintainerQuoted 29 lines · Purva Yeshi
Fix Smatch-detected issue:
drivers/hwmon/asus_atk0110.c:987atk_enumerate_old_hwmon()error:
double free of 'buf.pointer' (line 966)drivers/hwmon/asus_atk0110.c:1008atk_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 eachACPI_FREEto prevent possible use-after-free bugs.Signed-off-by Purva Yeshi <[email protected]>--- drivers/hwmon/asus_atk0110.c | 3 +++ 1 file changed, 3 insertions(+)drivers/hwmon/asus_atk0110.c +1
-0@@ -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
Quoted 43 lines · Guenter Roeck
Quoted 29 lines · Purva Yeshi
Fix Smatch-detected issue:
drivers/hwmon/asus_atk0110.c:987atk_enumerate_old_hwmon()error:
double free of 'buf.pointer' (line 966)drivers/hwmon/asus_atk0110.c:1008atk_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 eachACPI_FREEto prevent possible use-after-free bugs.Signed-off-by Purva Yeshi <[email protected]>--- drivers/hwmon/asus_atk0110.c | 3 +++ 1 file changed, 3 insertions(+)drivers/hwmon/asus_atk0110.c +1
-0@@ -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_BUFFERto trigger buffer allocation inacpi_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
-0return count; }Signature · 1 line
2.34.1
Best regards,
Purva