qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 07/36] target/arm: Check addresses for disabled regimes
Date: Thu, 12 Mar 2020 16:44:30 +0000	[thread overview]
Message-ID: <20200312164459.25924-8-peter.maydell@linaro.org> (raw)
In-Reply-To: <20200312164459.25924-1-peter.maydell@linaro.org>

From: Richard Henderson <richard.henderson@linaro.org>

We fail to validate the upper bits of a virtual address on a
translation disabled regime, as per AArch64.TranslateAddressS1Off.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20200308012946.16303-2-richard.henderson@linaro.org
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/arm/helper.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/target/arm/helper.c b/target/arm/helper.c
index fc1192d1204..b61ee73d18a 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -11780,7 +11780,40 @@ bool get_phys_addr(CPUARMState *env, target_ulong address,
     /* Definitely a real MMU, not an MPU */
 
     if (regime_translation_disabled(env, mmu_idx)) {
-        /* MMU disabled. */
+        /*
+         * MMU disabled.  S1 addresses within aa64 translation regimes are
+         * still checked for bounds -- see AArch64.TranslateAddressS1Off.
+         */
+        if (mmu_idx != ARMMMUIdx_Stage2) {
+            int r_el = regime_el(env, mmu_idx);
+            if (arm_el_is_aa64(env, r_el)) {
+                int pamax = arm_pamax(env_archcpu(env));
+                uint64_t tcr = env->cp15.tcr_el[r_el].raw_tcr;
+                int addrtop, tbi;
+
+                tbi = aa64_va_parameter_tbi(tcr, mmu_idx);
+                if (access_type == MMU_INST_FETCH) {
+                    tbi &= ~aa64_va_parameter_tbid(tcr, mmu_idx);
+                }
+                tbi = (tbi >> extract64(address, 55, 1)) & 1;
+                addrtop = (tbi ? 55 : 63);
+
+                if (extract64(address, pamax, addrtop - pamax + 1) != 0) {
+                    fi->type = ARMFault_AddressSize;
+                    fi->level = 0;
+                    fi->stage2 = false;
+                    return 1;
+                }
+
+                /*
+                 * When TBI is disabled, we've just validated that all of the
+                 * bits above PAMax are zero, so logically we only need to
+                 * clear the top byte for TBI.  But it's clearer to follow
+                 * the pseudocode set of addrdesc.paddress.
+                 */
+                address = extract64(address, 0, 52);
+            }
+        }
         *phys_ptr = address;
         *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
         *page_size = TARGET_PAGE_SIZE;
-- 
2.20.1



  parent reply	other threads:[~2020-03-12 16:52 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12 16:44 [PULL 00/36] target-arm queue Peter Maydell
2020-03-12 16:44 ` [PULL 01/36] hw/intc/armv7m_nvic: Rebuild hflags on reset Peter Maydell
2020-03-12 16:44 ` [PULL 02/36] target/arm: Update hflags in trans_CPS_v7m() Peter Maydell
2020-03-12 16:44 ` [PULL 03/36] target/arm: Recalculate hflags correctly after writes to CONTROL Peter Maydell
2020-03-12 16:44 ` [PULL 04/36] target/arm: Fix some comment typos Peter Maydell
2020-03-12 16:44 ` [PULL 05/36] aspeed/smc: Add some tracing Peter Maydell
2020-03-12 16:44 ` [PULL 06/36] aspeed/smc: Fix User mode select/unselect scheme Peter Maydell
2020-03-12 16:44 ` Peter Maydell [this message]
2020-03-12 16:44 ` [PULL 08/36] target/arm: Disable clean_data_tbi for system mode Peter Maydell
2020-03-12 16:44 ` [PULL 09/36] hw/arm/cubieboard: make sure SOC object isn't leaked Peter Maydell
2020-03-12 16:44 ` [PULL 10/36] hw/arm/fsl-imx25: Wire up eSDHC controllers Peter Maydell
2020-03-12 16:44 ` [PULL 11/36] hw/arm/fsl-imx25: Wire up USB controllers Peter Maydell
2020-03-12 16:44 ` [PULL 12/36] hw/arm: add Allwinner H3 System-on-Chip Peter Maydell
2020-03-12 16:44 ` [PULL 13/36] hw/arm: add Xunlong Orange Pi PC machine Peter Maydell
2020-03-12 16:44 ` [PULL 14/36] hw/arm/allwinner-h3: add Clock Control Unit Peter Maydell
2020-03-12 16:44 ` [PULL 15/36] hw/arm/allwinner-h3: add USB host controller Peter Maydell
2020-03-12 16:44 ` [PULL 16/36] hw/arm/allwinner-h3: add System Control module Peter Maydell
2020-03-12 16:44 ` [PULL 17/36] hw/arm/allwinner: add CPU Configuration module Peter Maydell
2020-03-12 16:44 ` [PULL 18/36] hw/arm/allwinner: add Security Identifier device Peter Maydell
2020-03-12 16:44 ` [PULL 19/36] hw/arm/allwinner: add SD/MMC host controller Peter Maydell
2020-03-12 16:44 ` [PULL 20/36] hw/arm/allwinner-h3: add EMAC ethernet device Peter Maydell
2020-03-12 16:44 ` [PULL 21/36] hw/arm/allwinner-h3: add Boot ROM support Peter Maydell
2020-03-20 12:07   ` Peter Maydell
2020-03-21 17:17     ` Niek Linnenbank
2020-03-21 19:47       ` Peter Maydell
2020-03-12 16:44 ` [PULL 22/36] hw/arm/allwinner-h3: add SDRAM controller device Peter Maydell
2020-03-20 15:46   ` Peter Maydell
2020-03-22 20:23     ` Niek Linnenbank
2020-03-22 21:17       ` Peter Maydell
2020-03-12 16:44 ` [PULL 23/36] hw/arm/allwinner: add RTC device support Peter Maydell
2020-03-12 16:44 ` [PULL 24/36] tests/boot_linux_console: Add a quick test for the OrangePi PC board Peter Maydell
2020-03-12 16:44 ` [PULL 25/36] tests/boot_linux_console: Add initrd test for the Orange Pi " Peter Maydell
2020-03-12 16:44 ` [PULL 26/36] tests/boot_linux_console: Add a SD card test for the OrangePi " Peter Maydell
2020-03-12 16:44 ` [PULL 27/36] tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi PC Peter Maydell
2020-03-12 16:44 ` [PULL 28/36] tests/boot_linux_console: Test booting NetBSD via U-Boot " Peter Maydell
2020-03-12 16:44 ` [PULL 29/36] docs: add Orange Pi PC document Peter Maydell
2020-03-12 16:44 ` [PULL 30/36] hw/arm/virt: Document 'max' value in gic-version property description Peter Maydell
2020-03-12 16:44 ` [PULL 31/36] hw/arm/virt: Introduce VirtGICType enum type Peter Maydell
2020-03-12 16:44 ` [PULL 32/36] hw/arm/virt: Introduce finalize_gic_version() Peter Maydell
2020-03-12 16:44 ` [PULL 33/36] target/arm/kvm: Let kvm_arm_vgic_probe() return a bitmap Peter Maydell
2020-03-12 16:44 ` [PULL 34/36] hw/arm/virt: kvm: Restructure finalize_gic_version() Peter Maydell
2020-03-12 16:44 ` [PULL 35/36] hw/arm/virt: kvm: allow gicv3 by default if v2 cannot work Peter Maydell
2020-03-12 16:44 ` [PULL 36/36] target/arm: kvm: Inject events at the last stage of sync Peter Maydell
2020-03-12 20:32 ` [PULL 00/36] target-arm queue Peter Maydell

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=20200312164459.25924-8-peter.maydell@linaro.org \
    --to=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).