Skip to content

Commit fe000c4

Browse files
pm215Michael Tokarev
authored andcommitted
target/arm: Don't enforce NSE,NS check for EL3->EL3 returns
In the Arm ARM, rule R_TYTWB that defines illegal exception return cases includes the case: If FEAT_RME is implemented, then if SCR_EL3.{NSE, NS} is {1, 0}, an exception return from EL3 to a lower Exception level Our implementation of this check fails to check that the return is to a lower exception level, so it will incorrectly fire on EL3->EL3 exception returns. Fix the check condition. This requires us to move it further down in the function to a point where we know the new_el value. Fixes: 35aa671 ("target/arm: Catch illegal-exception-return from EL3 with bad NSE/NS") Cc: [email protected] Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3016 Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-id: [email protected] (cherry picked from commit c563cd7e61d074f58eef413322144461dd243716) Signed-off-by: Michael Tokarev <[email protected]>
1 parent cae6ddf commit fe000c4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

target/arm/tcg/helper-a64.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -653,15 +653,6 @@ void HELPER(exception_return)(CPUARMState *env, uint64_t new_pc)
653653
spsr &= ~PSTATE_SS;
654654
}
655655

656-
/*
657-
* FEAT_RME forbids return from EL3 with an invalid security state.
658-
* We don't need an explicit check for FEAT_RME here because we enforce
659-
* in scr_write() that you can't set the NSE bit without it.
660-
*/
661-
if (cur_el == 3 && (env->cp15.scr_el3 & (SCR_NS | SCR_NSE)) == SCR_NSE) {
662-
goto illegal_return;
663-
}
664-
665656
new_el = el_from_spsr(spsr);
666657
if (new_el == -1) {
667658
goto illegal_return;
@@ -673,6 +664,17 @@ void HELPER(exception_return)(CPUARMState *env, uint64_t new_pc)
673664
goto illegal_return;
674665
}
675666

667+
/*
668+
* FEAT_RME forbids return from EL3 to a lower exception level
669+
* with an invalid security state.
670+
* We don't need an explicit check for FEAT_RME here because we enforce
671+
* in scr_write() that you can't set the NSE bit without it.
672+
*/
673+
if (cur_el == 3 && new_el < 3 &&
674+
(env->cp15.scr_el3 & (SCR_NS | SCR_NSE)) == SCR_NSE) {
675+
goto illegal_return;
676+
}
677+
676678
if (new_el != 0 && arm_el_is_aa64(env, new_el) != return_to_aa64) {
677679
/* Return to an EL which is configured for a different register width */
678680
goto illegal_return;

0 commit comments

Comments
 (0)