Skip to contentSkip to conversation

target/arm: Forbid unprivileged mode for M Baseline

PATCH Superseded Julia Suvorova 2 participants 3 messages Jul 4, 2018 – Jul 5, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Forbid unprivileged mode for M Baseline

MSR handling is the only place where CONTROL.nPRIV is modified.

---
 target/arm/helper.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/arm/helper.c +4 -2
index 5ee229eb35..83cca554ad 100644
@@ -10781,8 +10781,10 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
             !arm_v7m_is_handler_mode(env)) {
             write_v7m_control_spsel(env, (val & R_V7M_CONTROL_SPSEL_MASK) != 0);
         }
-        env->v7m.control[env->v7m.secure] &= ~R_V7M_CONTROL_NPRIV_MASK;
-        env->v7m.control[env->v7m.secure] |= val & R_V7M_CONTROL_NPRIV_MASK;
+        if (arm_feature(env, ARM_FEATURE_M_MAIN)) {
+            env->v7m.control[env->v7m.secure] &= ~R_V7M_CONTROL_NPRIV_MASK;
+            env->v7m.control[env->v7m.secure] |= val & R_V7M_CONTROL_NPRIV_MASK;
+        }
         break;
     default:
     bad_reg:
Signature · 1 line
2.17.1
#1 lore raw
Quoted 15 lines · Julia Suvorova

MSR handling is the only place where CONTROL.nPRIV is modified.

---
 target/arm/helper.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/arm/helper.c +0 -0
index 5ee229eb35..83cca554ad 100644
@@ -10781,8 +10781,10 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
             !arm_v7m_is_handler_mode(env)) {
             write_v7m_control_spsel(env, (val & R_V7M_CONTROL_SPSEL_MASK) != 0);
         }

target/arm/helper.c void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)

Quoted 10 lines
target/arm/helper.c +4 -3
-        env->v7m.control[env->v7m.secure] &= ~R_V7M_CONTROL_NPRIV_MASK;
-        env->v7m.control[env->v7m.secure] |= val & R_V7M_CONTROL_NPRIV_MASK;
+        if (arm_feature(env, ARM_FEATURE_M_MAIN)) {
+            env->v7m.control[env->v7m.secure] &= ~R_V7M_CONTROL_NPRIV_MASK;
+            env->v7m.control[env->v7m.secure] |= val & R_V7M_CONTROL_NPRIV_MASK;
+        }
         break;
     default:
     bad_reg:
--

Could you also guard the similar code in the CONTROL_NS case a little earlier, in the function, please?

            env->v7m.control[M_REG_NS] &= ~R_V7M_CONTROL_NPRIV_MASK;
            env->v7m.control[M_REG_NS] |= val & R_V7M_CONTROL_NPRIV_MASK;

That won't be executed for v6M but for v8M it matters.

Otherwise I agree this is all we need to do to avoid the guest incorrectly getting into nonpriviliged mode.

thanks
-- PMM

#2 lore raw
Quoted 30 lines · Peter Maydell
Quoted 15 lines · Julia Suvorova

MSR handling is the only place where CONTROL.nPRIV is modified.

---
  target/arm/helper.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
target/arm/helper.c +0 -0
index 5ee229eb35..83cca554ad 100644
@@ -10781,8 +10781,10 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
              !arm_v7m_is_handler_mode(env)) {
              write_v7m_control_spsel(env, (val & R_V7M_CONTROL_SPSEL_MASK) != 0);
          }

target/arm/helper.c void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)

Quoted 10 lines
target/arm/helper.c +4 -3
-        env->v7m.control[env->v7m.secure] &= ~R_V7M_CONTROL_NPRIV_MASK;
-        env->v7m.control[env->v7m.secure] |= val & R_V7M_CONTROL_NPRIV_MASK;
+        if (arm_feature(env, ARM_FEATURE_M_MAIN)) {
+            env->v7m.control[env->v7m.secure] &= ~R_V7M_CONTROL_NPRIV_MASK;
+            env->v7m.control[env->v7m.secure] |= val & R_V7M_CONTROL_NPRIV_MASK;
+        }
          break;
      default:
      bad_reg:
--

Could you also guard the similar code in the CONTROL_NS case a little earlier, in the function, please?

Quoted 4 lines
             env->v7m.control[M_REG_NS] &= ~R_V7M_CONTROL_NPRIV_MASK;
             env->v7m.control[M_REG_NS] |= val & R_V7M_CONTROL_NPRIV_MASK;

That won't be executed for v6M but for v8M it matters.

Sure, I'll send v2.

Best regards, Julia Suvorova.