Skip to contentSkip to conversation

acpi/erst: fix fallthrough code upon validation failure

PATCH In review Ani Sinha 4 participants 5 messages May 13, 2022 – Jun 10, 2022

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

PATCH 1/1 acpi/erst: fix fallthrough code upon validation failure

At any step when any validation fail in check_erst_backend_storage(), there is no need to continue further through other validation checks. Further, by continuing even when record_size is 0, we run the risk of triggering a divide by zero error if we continued with other validation checks. Hence, we should simply return from this function upon validation failure.

CC Peter Maydell <[email protected]>
CC Eric DeVolder <[email protected]>
---
 hw/acpi/erst.c | 3 +++
 1 file changed, 3 insertions(+)
hw/acpi/erst.c +3 -0
index de509c2b48..df856b2669 100644
@@ -440,6 +440,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
         (record_size >= 4096) /* PAGE_SIZE */
         )) {
         error_setg(errp, "ERST record_size %u is invalid", record_size);
+        return;
     }
 
     /* Validity check header */
@@ -450,6 +451,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
         (le16_to_cpu(header->reserved) == 0)
         )) {
         error_setg(errp, "ERST backend storage header is invalid");
+        return;
     }
 
     /* Check storage_size against record_size */
@@ -457,6 +459,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
          (record_size > s->storage_size)) {
         error_setg(errp, "ACPI ERST requires storage size be multiple of "
             "record size (%uKiB)", record_size);
+        return;
     }
 
     /* Compute offset of first and last record storage slot */
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Fri, 13 May 2022 19:40:05 +0530 Ani Sinha <[email protected]> wrote:

At any step when any validation fail in check_erst_backend_storage(), there is no need to continue further through other validation checks. Further, by continuing even when record_size is 0, we run the risk of triggering a divide by zero error if we continued with other validation checks. Hence, we should simply return from this function upon validation failure.

CC Peter Maydell <[email protected]>
CC Eric DeVolder <[email protected]>
Quoted 32 lines
---
 hw/acpi/erst.c | 3 +++
 1 file changed, 3 insertions(+)
hw/acpi/erst.c +3 -0
index de509c2b48..df856b2669 100644
@@ -440,6 +440,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
         (record_size >= 4096) /* PAGE_SIZE */
         )) {
         error_setg(errp, "ERST record_size %u is invalid", record_size);
+        return;
     }
 
     /* Validity check header */
@@ -450,6 +451,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
         (le16_to_cpu(header->reserved) == 0)
         )) {
         error_setg(errp, "ERST backend storage header is invalid");
+        return;
     }
 
     /* Check storage_size against record_size */
@@ -457,6 +459,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
          (record_size > s->storage_size)) {
         error_setg(errp, "ACPI ERST requires storage size be multiple of "
             "record size (%uKiB)", record_size);
+        return;
     }
 
     /* Compute offset of first and last record storage slot */
Reviewed-by on v1 1/1
#2 lore raw
In reply to Ani Sinha
Quoted 9 lines · Ani Sinha

At any step when any validation fail in check_erst_backend_storage(), there is no need to continue further through other validation checks. Further, by continuing even when record_size is 0, we run the risk of triggering a divide by zero error if we continued with other validation checks. Hence, we should simply return from this function upon validation failure.

CC Peter Maydell <[email protected]>
CC Eric DeVolder <[email protected]>

My apologies, I've been away for the past week. Thank you for taking the time to correct this issue! eric

Quoted 33 lines
---
  hw/acpi/erst.c | 3 +++
  1 file changed, 3 insertions(+)
hw/acpi/erst.c +3 -0
index de509c2b48..df856b2669 100644
@@ -440,6 +440,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
          (record_size >= 4096) /* PAGE_SIZE */
          )) {
          error_setg(errp, "ERST record_size %u is invalid", record_size);
+        return;
      }
 
      /* Validity check header */
@@ -450,6 +451,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
          (le16_to_cpu(header->reserved) == 0)
          )) {
          error_setg(errp, "ERST backend storage header is invalid");
+        return;
      }
 
      /* Check storage_size against record_size */
@@ -457,6 +459,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
           (record_size > s->storage_size)) {
          error_setg(errp, "ACPI ERST requires storage size be multiple of "
              "record size (%uKiB)", record_size);
+        return;
      }
 
      /* Compute offset of first and last record storage slot */
author
#3 lore raw
Quoted 10 lines · Eric DeVolder
Quoted 6 lines · Ani Sinha

At any step when any validation fail in check_erst_backend_storage(), there is no need to continue further through other validation checks. Further, by continuing even when record_size is 0, we run the risk of triggering a divide by zero error if we continued with other validation checks. Hence, we should simply return from this function upon validation failure.

Quoted 5 lines
Quoted 3 lines
CC Peter Maydell <[email protected]>
CC Eric DeVolder <[email protected]>

Michael:
Did you forget to queue this for your latest pull request?

Quoted 38 lines

My apologies, I've been away for the past week. Thank you for taking the time to correct this issue! eric

Quoted 33 lines
---
  hw/acpi/erst.c | 3 +++
  1 file changed, 3 insertions(+)
hw/acpi/erst.c +3 -0
index de509c2b48..df856b2669 100644
@@ -440,6 +440,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
          (record_size >= 4096) /* PAGE_SIZE */
          )) {
          error_setg(errp, "ERST record_size %u is invalid", record_size);
+        return;
      }
 
      /* Validity check header */
@@ -450,6 +451,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
          (le16_to_cpu(header->reserved) == 0)
          )) {
          error_setg(errp, "ERST backend storage header is invalid");
+        return;
      }
 
      /* Check storage_size against record_size */
@@ -457,6 +459,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
           (record_size > s->storage_size)) {
          error_setg(errp, "ACPI ERST requires storage size be multiple of "
              "record size (%uKiB)", record_size);
+        return;
      }
 
      /* Compute offset of first and last record storage slot */
#4 lore raw
Quoted 11 lines · Ani Sinha
Quoted 10 lines · Eric DeVolder
Quoted 6 lines · Ani Sinha

At any step when any validation fail in check_erst_backend_storage(), there is no need to continue further through other validation checks. Further, by continuing even when record_size is 0, we run the risk of triggering a divide by zero error if we continued with other validation checks. Hence, we should simply return from this function upon validation failure.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
CC Peter Maydell <[email protected]>
CC Eric DeVolder <[email protected]>

Michael:
Did you forget to queue this for your latest pull request?

I did, thanks for the reminder!

Quoted 38 lines
Quoted 38 lines

My apologies, I've been away for the past week. Thank you for taking the time to correct this issue! eric

Quoted 33 lines
---
  hw/acpi/erst.c | 3 +++
  1 file changed, 3 insertions(+)
hw/acpi/erst.c +3 -0
index de509c2b48..df856b2669 100644
@@ -440,6 +440,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
          (record_size >= 4096) /* PAGE_SIZE */
          )) {
          error_setg(errp, "ERST record_size %u is invalid", record_size);
+        return;
      }
 
      /* Validity check header */
@@ -450,6 +451,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
          (le16_to_cpu(header->reserved) == 0)
          )) {
          error_setg(errp, "ERST backend storage header is invalid");
+        return;
      }
 
      /* Check storage_size against record_size */
@@ -457,6 +459,7 @@ static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
           (record_size > s->storage_size)) {
          error_setg(errp, "ACPI ERST requires storage size be multiple of "
              "record size (%uKiB)", record_size);
+        return;
      }
 
      /* Compute offset of first and last record storage slot */