Skip to contentSkip to conversation

target/ppc: Add lower bound check for watchdogNumber

PATCH In review Chinmay Rath 2 participants 4 messages Aug 18 – Aug 23

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 target/ppc: Add lower bound check for watchdogNumber

Add missing lower bound check for H_WATCHDOG H_CALL's watchdogNumber parameter as per PAPR documentation ver 12.10.00 section 14.15.5 'H_WATCHDOG'.

---

Changes from v2:
Renamed watchdogNumber_valid to watchdog_number_valid - Amit Retained Amit's Reviewed-by

 hw/watchdog/spapr_watchdog.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
hw/watchdog/spapr_watchdog.c +11 -5
index 5b3f50de3a..5a72896066 100644
@@ -127,6 +127,12 @@ static void watchdog_expired(void *pw)
     }
 }
 
+static inline bool watchdog_number_valid(target_ulong watchdogNumber,
+                                        SpaprMachineState *spapr)
+{
+    return watchdogNumber >= 1 && watchdogNumber <= ARRAY_SIZE(spapr->wds);
+}
+
 static target_ulong h_watchdog(PowerPCCPU *cpu,
                                SpaprMachineState *spapr,
                                target_ulong opcode, target_ulong *args)
@@ -145,7 +151,7 @@ static target_ulong h_watchdog(PowerPCCPU *cpu,
 
     switch (operation) {
     case PSERIES_WDTF_OP_START:
-        if (watchdogNumber > ARRAY_SIZE(spapr->wds)) {
+        if (!watchdog_number_valid(watchdogNumber, spapr)) {
             return H_P2;
         }
         if (timeoutInMs <= WDT_MIN_TIMEOUT) {
@@ -170,11 +176,11 @@ static target_ulong h_watchdog(PowerPCCPU *cpu,
     case PSERIES_WDTF_OP_STOP:
         if (watchdogNumber == PSERIES_WDT_STOP_ALL) {
             ret = watchdog_stop_all(spapr);
-        } else if (watchdogNumber <= ARRAY_SIZE(spapr->wds)) {
+        } else if (!watchdog_number_valid(watchdogNumber, spapr)) {
+            return H_P2;
+        } else {
             ret = watchdog_stop(watchdogNumber,
                                 &spapr->wds[watchdogNumber - 1]);
-        } else {
-            return H_P2;
         }
         break;
     case PSERIES_WDTF_OP_QUERY:
@@ -184,7 +190,7 @@ static target_ulong h_watchdog(PowerPCCPU *cpu,
         trace_spapr_watchdog_query(args[0]);
         break;
     case PSERIES_WDTF_OP_QUERY_LPM:
-        if (watchdogNumber > ARRAY_SIZE(spapr->wds)) {
+        if (!watchdog_number_valid(watchdogNumber, spapr)) {
             return H_P2;
         }
         args[0] = PSERIES_WDTQL_QUERY_NOT_STOPPED;
Signature · 1 line
2.55.0
#1 lore raw
Quoted 5 lines · Chinmay Rath

Add missing lower bound check for H_WATCHDOG H_CALL's watchdogNumber parameter as per PAPR documentation ver 12.10.00 section 14.15.5 'H_WATCHDOG'.

Quoted 60 lines

---

Changes from v2:
Renamed watchdogNumber_valid to watchdog_number_valid - Amit Retained Amit's Reviewed-by

  hw/watchdog/spapr_watchdog.c | 16 +++++++++++-----
  1 file changed, 11 insertions(+), 5 deletions(-)
hw/watchdog/spapr_watchdog.c +11 -5
index 5b3f50de3a..5a72896066 100644
@@ -127,6 +127,12 @@ static void watchdog_expired(void *pw)
      }
  }
 
+static inline bool watchdog_number_valid(target_ulong watchdogNumber,
+                                        SpaprMachineState *spapr)
+{
+    return watchdogNumber >= 1 && watchdogNumber <= ARRAY_SIZE(spapr->wds);
+}
+
  static target_ulong h_watchdog(PowerPCCPU *cpu,
                                 SpaprMachineState *spapr,
                                 target_ulong opcode, target_ulong *args)
@@ -145,7 +151,7 @@ static target_ulong h_watchdog(PowerPCCPU *cpu,
 
      switch (operation) {
      case PSERIES_WDTF_OP_START:
-        if (watchdogNumber > ARRAY_SIZE(spapr->wds)) {
+        if (!watchdog_number_valid(watchdogNumber, spapr)) {
              return H_P2;
          }
          if (timeoutInMs <= WDT_MIN_TIMEOUT) {
@@ -170,11 +176,11 @@ static target_ulong h_watchdog(PowerPCCPU *cpu,
      case PSERIES_WDTF_OP_STOP:
          if (watchdogNumber == PSERIES_WDT_STOP_ALL) {
              ret = watchdog_stop_all(spapr);
-        } else if (watchdogNumber <= ARRAY_SIZE(spapr->wds)) {
+        } else if (!watchdog_number_valid(watchdogNumber, spapr)) {
+            return H_P2;
+        } else {
              ret = watchdog_stop(watchdogNumber,
                                  &spapr->wds[watchdogNumber - 1]);
-        } else {
-            return H_P2;
          }
          break;
      case PSERIES_WDTF_OP_QUERY:
@@ -184,7 +190,7 @@ static target_ulong h_watchdog(PowerPCCPU *cpu,
          trace_spapr_watchdog_query(args[0]);
          break;
      case PSERIES_WDTF_OP_QUERY_LPM:
-        if (watchdogNumber > ARRAY_SIZE(spapr->wds)) {
+        if (!watchdog_number_valid(watchdogNumber, spapr)) {
              return H_P2;
          }
          args[0] = PSERIES_WDTQL_QUERY_NOT_STOPPED;
#2 lore raw
Quoted 8 lines · Chinmay Rath
Quoted 5 lines · Chinmay Rath

Add missing lower bound check for H_WATCHDOG H_CALL's watchdogNumber parameter as per PAPR documentation ver 12.10.00 section 14.15.5 'H_WATCHDOG'.

Hi Harsh,
I missed adding the correct commit message header here. Should have use hw/watchdog instead of target/ppc. If possible please correct this while you pull in the patch along with the extra Reported-by tag. Lemme know if that works.

TIA,
Chinmay

Quoted 60 lines
Quoted 59 lines

---

Changes from v2:
Renamed watchdogNumber_valid to watchdog_number_valid - Amit Retained Amit's Reviewed-by

  hw/watchdog/spapr_watchdog.c | 16 +++++++++++-----

  1 file changed, 11 insertions(+), 5 deletions(-)
hw/watchdog/spapr_watchdog.c +5 -0
index 5b3f50de3a..5a72896066 100644
@@ -127,6 +127,12 @@ static void watchdog_expired(void *pw)
       }
   }
   +static inline bool watchdog_number_valid(target_ulong watchdogNumber,
+                                        SpaprMachineState *spapr)
+{
+    return watchdogNumber >= 1 && watchdogNumber <= 
 ARRAY_SIZE(spapr->wds);
+}
+
   static target_ulong h_watchdog(PowerPCCPU *cpu,
                                  SpaprMachineState *spapr,

                                 target_ulong opcode, target_ulong *args)

hw/watchdog/spapr_watchdog.c +0 -0
@@ -145,7 +151,7 @@ static target_ulong h_watchdog(PowerPCCPU *cpu,
         switch (operation) {

      case PSERIES_WDTF_OP_START:
-        if (watchdogNumber > ARRAY_SIZE(spapr->wds)) { +        if (!watchdog_number_valid(watchdogNumber, spapr)) { return H_P2;
          }
          if (timeoutInMs <= WDT_MIN_TIMEOUT) {

hw/watchdog/spapr_watchdog.c +0 -0
@@ -170,11 +176,11 @@ static target_ulong h_watchdog(PowerPCCPU *cpu,

      case PSERIES_WDTF_OP_STOP:
          if (watchdogNumber == PSERIES_WDT_STOP_ALL) { ret = watchdog_stop_all(spapr);
-        } else if (watchdogNumber <= ARRAY_SIZE(spapr->wds)) { +        } else if (!watchdog_number_valid(watchdogNumber, spapr)) { +            return H_P2;
+        } else {
              ret = watchdog_stop(watchdogNumber, &spapr->wds[watchdogNumber - 1]);
-        } else {
-            return H_P2;
          }
          break;
      case PSERIES_WDTF_OP_QUERY:

hw/watchdog/spapr_watchdog.c +0 -0
@@ -184,7 +190,7 @@ static target_ulong h_watchdog(PowerPCCPU *cpu,
           trace_spapr_watchdog_query(args[0]);
           break;

      case PSERIES_WDTF_OP_QUERY_LPM:
-        if (watchdogNumber > ARRAY_SIZE(spapr->wds)) { +        if (!watchdog_number_valid(watchdogNumber, spapr)) { return H_P2;
          }
          args[0] = PSERIES_WDTQL_QUERY_NOT_STOPPED;

#3 lore raw
Quoted 7 lines · Chinmay Rath
Quoted 5 lines · Chinmay Rath
Quoted 3 lines · Chinmay Rath

Add missing lower bound check for H_WATCHDOG H_CALL's watchdogNumber parameter as per PAPR documentation ver 12.10.00 section 14.15.5 'H_WATCHDOG'.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Hi Harsh,
I missed adding the correct commit message header here. Should have use hw/watchdog instead of target/ppc. If possible please correct this while you pull in the patch along with the extra Reported-by tag. Lemme know if that works.

Taken care, queued for 11.2, thanks.