target/ppc: Add lower bound check for watchdogNumber
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
@@ -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
Quoted 5 lines · Chinmay Rath
Add missing lower bound check for
H_WATCHDOGH_CALL's watchdogNumber parameter as per PAPR documentation ver 12.10.00 section 14.15.5 'H_WATCHDOG'.
Quoted 60 lines
Signed-off-by Chinmay Rath <[email protected]>---
Changes from v2:
RenamedwatchdogNumber_validtowatchdog_number_valid- Amit Retained Amit's Reviewed-byhw/watchdog/spapr_watchdog.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)hw/watchdog/spapr_watchdog.c +11
-5@@ -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 ;
Quoted 8 lines · Chinmay Rath
Quoted 5 lines · Chinmay Rath
Add missing lower bound check for
H_WATCHDOGH_CALL's watchdogNumber parameter as per PAPR documentation ver 12.10.00 section 14.15.5 'H_WATCHDOG'.Reported-by huntr bubble <[email protected]>
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
Signed-off-by Chinmay Rath <[email protected]>---
Changes from v2:
RenamedwatchdogNumber_validtowatchdog_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@@ -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_ulongopcode,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)) { returnH_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)) { + returnH_P2;
+ } else {
ret =watchdog_stop(watchdogNumber, &spapr->wds[watchdogNumber - 1]);
- } else {
- returnH_P2;
}
break;
casePSERIES_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)) { returnH_P2;
}
args[0] =PSERIES_WDTQL_QUERY_NOT_STOPPED;
Quoted 7 lines · Chinmay Rath
Quoted 5 lines · Chinmay Rath
Quoted 3 lines · Chinmay Rath
Add missing lower bound check for
H_WATCHDOGH_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
Reported-by huntr bubble <[email protected]>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.