Skip to contentSkip to conversation

amdgpu: prevent NULL pointer dereference if ATIF is not supported

PATCH In review Antonio Quartulli 3 participants 5 messages Oct 31, 2024 – Nov 1, 2024

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

PATCH v2 1/1 amdgpu: prevent NULL pointer dereference if ATIF is not supported

acpi_evaluate_object() may return AE_NOT_FOUND (failure), which would result in dereferencing buffer.pointer (obj) while being NULL.

Although this case may be unrealistic for the current code, it is still better to protect against possible bugs.

Bail out also when status is AE_NOT_FOUND.

This fixes 1 FORWARD_NULL issue reported by Coverity
Report: CID 1600951: Null pointer dereferences (FORWARD_NULL)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +2 -2
index cce85389427f..b8d4e07d2043 100644
@@ -172,8 +172,8 @@ static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif,
 				      &buffer);
 	obj = (union acpi_object *)buffer.pointer;
 
-	/* Fail if calling the method fails and ATIF is supported */
-	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
+	/* Fail if calling the method fails */
+	if (ACPI_FAILURE(status)) {
 		DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
 				 acpi_format_exception(status));
 		kfree(obj);
Signature · 1 line
2.45.2
Reviewed-by on v2 1/1
#2 lore raw
In reply to Antonio Quartulli
Quoted 6 lines · Antonio Quartulli

acpi_evaluate_object() may return AE_NOT_FOUND (failure), which would result in dereferencing buffer.pointer (obj) while being NULL.

Although this case may be unrealistic for the current code, it is still better to protect against possible bugs.

Quoted 6 lines

Bail out also when status is AE_NOT_FOUND.

This fixes 1 FORWARD_NULL issue reported by Coverity
Report: CID 1600951: Null pointer dereferences (FORWARD_NULL)

Can you please dig up the right Fixes: tag?

Besides that, LGTM.

Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +2 -2
index cce85389427f..b8d4e07d2043 100644
@@ -172,8 +172,8 @@ static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif,
  				      &buffer);
  	obj = (union acpi_object *)buffer.pointer;
 
-	/* Fail if calling the method fails and ATIF is supported */
-	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
+	/* Fail if calling the method fails */
+	if (ACPI_FAILURE(status)) {
  		DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
  				 acpi_format_exception(status));
  		kfree(obj);
#3 lore raw
Quoted 7 lines · Mario Limonciello
Quoted 6 lines · Antonio Quartulli

acpi_evaluate_object() may return AE_NOT_FOUND (failure), which would result in dereferencing buffer.pointer (obj) while being NULL.

Although this case may be unrealistic for the current code, it is still better to protect against possible bugs.

Quoted 8 lines
Quoted 6 lines

Bail out also when status is AE_NOT_FOUND.

This fixes 1 FORWARD_NULL issue reported by Coverity
Report: CID 1600951:  Null pointer dereferences  (FORWARD_NULL)

Can you please dig up the right Fixes: tag?

Fixes c9b7c809b89f ("drm/amd: Guard against bad data for ATIF ACPI method")

Your commit :)

Should I send v3 with the Fixes tag in it?

Interestingly, this pattern of checking for AE_NOT_FOUND is shared by other functions, however, they don't try to dereference the pointer to the buffer before the return statement (which caused the Coverity report). It's the caller that checks if the return value is NULL or not.

For this function it was the same, until you added this extra check on obj->type, without checking if obj was NULL or not.

If we want to keep the original pattern and continue checking for AE_NOT_FOUND, we could rather do:

- if (obj->type != ACPI_TYPE_BUFFER) {
+ if (obj && obj->type != ACPI_TYPE_BUFFER) {

But this feel more like "bike shed color picking" than anything else :)
Anyway, up to you Mario, I am open to change the patch again if the latter pattern is more preferable.

Regards,

Quoted 25 lines

Besides that, LGTM.

Quoted 19 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +2 -2
index cce85389427f..b8d4e07d2043 100644
@@ -172,8 +172,8 @@ static union acpi_object *amdgpu_atif_call(struct 
 amdgpu_atif *atif,
                         &buffer);
       obj = (union acpi_object *)buffer.pointer;
-    /* Fail if calling the method fails and ATIF is supported */
-    if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
+    /* Fail if calling the method fails */
+    if (ACPI_FAILURE(status)) {
           DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
                    acpi_format_exception(status));
           kfree(obj);
Signature · 5 lines
Antonio Quartulli

CEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com
#4 lore raw
Quoted 15 lines · Antonio Quartulli
Quoted 14 lines · Mario Limonciello
Quoted 12 lines · Antonio Quartulli

acpi_evaluate_object() may return AE_NOT_FOUND (failure), which would result in dereferencing buffer.pointer (obj) while being NULL.

Although this case may be unrealistic for the current code, it is still better to protect against possible bugs.

Bail out also when status is AE_NOT_FOUND.

This fixes 1 FORWARD_NULL issue reported by Coverity
Report: CID 1600951:  Null pointer dereferences  (FORWARD_NULL)

Quoted 7 lines
Quoted 1 line

Can you please dig up the right Fixes: tag?

Fixes c9b7c809b89f ("drm/amd: Guard against bad data for ATIF ACPI method")

Your commit :)

Should I send v3 with the Fixes tag in it?

Don't worry about it, I'll pick it up while we commit it.

Thanks!

Quoted 42 lines

Interestingly, this pattern of checking for AE_NOT_FOUND is shared by other functions, however, they don't try to dereference the pointer to the buffer before the return statement (which caused the Coverity report). It's the caller that checks if the return value is NULL or not.

For this function it was the same, until you added this extra check on obj->type, without checking if obj was NULL or not.

If we want to keep the original pattern and continue checking for AE_NOT_FOUND, we could rather do:

-       if (obj->type != ACPI_TYPE_BUFFER) { +       if (obj && obj->type != ACPI_TYPE_BUFFER) {

But this feel more like "bike shed color picking" than anything else :)
Anyway, up to you Mario, I am open to change the patch again if the latter pattern is more preferable.

Regards,

Quoted 25 lines

Besides that, LGTM.

Quoted 19 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +2 -2
index cce85389427f..b8d4e07d2043 100644
@@ -172,8 +172,8 @@ static union acpi_object *amdgpu_atif_call(struct 
 amdgpu_atif *atif,
                         &buffer);
       obj = (union acpi_object *)buffer.pointer;
-    /* Fail if calling the method fails and ATIF is supported */
-    if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
+    /* Fail if calling the method fails */
+    if (ACPI_FAILURE(status)) {
           DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
                    acpi_format_exception(status));
           kfree(obj);