From: Timofey Kutergin <tkutergin@gmail.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, Timofey Kutergin <tkutergin@gmail.com>
Subject: [PATCH] target/arm: Fixed Privileged Access Never (PAN) for aarch32
Date: Wed, 19 Oct 2022 15:15:37 +0300 [thread overview]
Message-ID: <20221019121537.255477-1-tkutergin@gmail.com> (raw)
- synchronize PSTATE.PAN with changes in CPSR.PAN in aarch32 mode
- set PAN bit automatically on exception entry if SCTLR_SPAN bit
is set
- throw permission fault during address translation when PAN is
enabled and kernel tries to access user acessible page
- ignore SCTLR_XP bit for armv7 and armv8 (conflicts with SCTLR_SPAN).
Signed-off-by: Timofey Kutergin <tkutergin@gmail.com>
---
target/arm/helper.c | 6 ++++++
target/arm/ptw.c | 11 ++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/target/arm/helper.c b/target/arm/helper.c
index dde64a487a..5299f67e3f 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -9052,6 +9052,11 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask,
}
mask &= ~CACHED_CPSR_BITS;
env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask);
+ if (env->uncached_cpsr & CPSR_PAN) {
+ env->pstate |= PSTATE_PAN;
+ } else {
+ env->pstate &= ~PSTATE_PAN;
+ }
if (rebuild_hflags) {
arm_rebuild_hflags(env);
}
@@ -9592,6 +9597,7 @@ static void take_aarch32_exception(CPUARMState *env, int new_mode,
/* ... the target is EL1 and SCTLR.SPAN is 0. */
if (!(env->cp15.sctlr_el[new_el] & SCTLR_SPAN)) {
env->uncached_cpsr |= CPSR_PAN;
+ env->pstate |= PSTATE_PAN;
}
break;
}
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index 23f16f4ff7..204a73350f 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -659,6 +659,13 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t address,
goto do_fault;
}
+ if (regime_is_pan(env, mmu_idx) && !regime_is_user(env, mmu_idx) &&
+ simple_ap_to_rw_prot_is_user(ap >> 1, 1) &&
+ access_type != MMU_INST_FETCH) {
+ fi->type = ARMFault_Permission;
+ goto do_fault;
+ }
+
if (arm_feature(env, ARM_FEATURE_V6K) &&
(regime_sctlr(env, mmu_idx) & SCTLR_AFE)) {
/* The simplified model uses AP[0] as an access control bit. */
@@ -2506,7 +2513,9 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
if (regime_using_lpae_format(env, mmu_idx)) {
return get_phys_addr_lpae(env, address, access_type, mmu_idx,
is_secure, false, result, fi);
- } else if (regime_sctlr(env, mmu_idx) & SCTLR_XP) {
+ } else if (arm_feature(env, ARM_FEATURE_V7) ||
+ arm_feature(env, ARM_FEATURE_V8) || (
+ regime_sctlr(env, mmu_idx) & SCTLR_XP)) {
return get_phys_addr_v6(env, address, access_type, mmu_idx,
is_secure, result, fi);
} else {
--
2.25.1
next reply other threads:[~2022-10-19 13:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 12:15 Timofey Kutergin [this message]
2022-10-25 13:45 ` [PATCH] target/arm: Fixed Privileged Access Never (PAN) for aarch32 Peter Maydell
2022-10-27 9:22 ` Timofey Kutergin
2022-10-27 9:35 ` Peter Maydell
2022-10-27 10:43 ` Timofey Kutergin
-- strict thread matches above, loose matches on Subject: below --
2022-10-27 11:26 Timofey Kutergin
2022-10-28 18:17 ` Peter Maydell
2022-10-31 13:45 ` Peter Maydell
2022-10-19 12:03 Timofey Kutergin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221019121537.255477-1-tkutergin@gmail.com \
--to=tkutergin@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).