xen/arm: validate non-common page-table ranges
PATCH v5 1/1 xen/arm: validate non-common page-table ranges
On arm32, all the Xen mappings are common to all the CPUs, except for the domheap mapping, which is per-CPU.
The xen_pt_update function assumed that only the common mappings would be modified, but did not check this assumption.
Add a check to reject modifications to the domheap mapping.
---
v5:
- Moved the check back to pt.c under #ifdef CONFIG_ARM_32.
- Only check the domheap area.
- Added a comment explaining why only Arm32 needs it.
v4:
- Rebased onto staging (v3 was diffed against v2).
v3:
- Dropped accidentally tracked patch file from commit.
v2:
- Inverted polarity of xen_pt_range_is_non_common() as suggested.
- Moved xen_pt_range_is_common() implementation to arch-specific headers (arm32 vs arm64) instead of keeping #ifdef CONFIG_ARM_32 in pt.c (tried IS_ENABLED() for DCE, but ARM64 lacks definitions for DOMHEAP_VIRT_START/TEMPORARY_AREA_ADDR, breaking the build).
- Added ASSERT_UNREACHABLE() on failure path in xen_pt_update().
--- xen/arch/arm/mmu/pt.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
xen/arch/arm/mmu/pt.c +14 -6
@@ -13,6 +13,7 @@#include <asm/current.h> #include <asm/fixmap.h> +#include <asm/mmu/layout.h> #ifdef NDEBUG static inline void
@@ -601,14 +602,21 @@ static int xen_pt_update(unsigned long virt,unsigned long vfn = virt >>PAGE_SHIFT ;unsigned long left = nr_mfns; +const mfn_t root =maddr_to_mfn (READ_SYSREG64 (TTBR0_EL2 )); + +#ifdef CONFIG_ARM_32 /* -* For arm32, page-tables are different on each CPUs. Yet, they share -* some common mappings. It is assumed that only common mappings -* will be modified with this function. -* -* XXX: Add a check. +* Only Arm32 needs this check, as updating the domheap mapping here +* would only affect the current CPU. On Arm64, all the CPUs share the +* same page-tables. */ -const mfn_t root =maddr_to_mfn (READ_SYSREG64 (TTBR0_EL2 )); +if ( virt >=DOMHEAP_VIRT_START || + nr_mfns *PAGE_SIZE >DOMHEAP_VIRT_START - virt ) + { +ASSERT_UNREACHABLE (); +return -EINVAL ; + } +#endif if (flags_has_rwx (flags) ) {
Signature · 1 line
2.56.0
Quoted 37 lines · Gabriel Quintáns Souto
On arm32, all the Xen mappings are common to all the CPUs, except for the domheap mapping, which is per-CPU.
The
xen_pt_updatefunction assumed that only the common mappings would be modified, but did not check this assumption.Add a check to reject modifications to the domheap mapping.
Signed-off-by Gabriel Quintáns Souto <[email protected]>---
v5:
- Moved the check back topt.cunder #ifdefCONFIG_ARM_32.
- Only check the domheap area.
- Added a comment explaining why only Arm32 needs it.v4:
- Rebased onto staging (v3 was diffed against v2).v3:
- Dropped accidentally tracked patch file from commit.v2:
- Inverted polarity ofxen_pt_range_is_non_common()as suggested.
- Movedxen_pt_range_is_common()implementation to arch-specific headers (arm32 vs arm64) instead of keeping #ifdefCONFIG_ARM_32inpt.c(triedIS_ENABLED()for DCE, but ARM64 lacks definitions for DOMHEAP_VIRT_START/TEMPORARY_AREA_ADDR, breaking the build).
- AddedASSERT_UNREACHABLE()on failure path inxen_pt_update().--- xen/arch/arm/mmu/pt.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)xen/arch/arm/mmu/pt.c +0
-0
xen/arch/arm/mmu/pt.c line 16
Quoted 4 lines
xen/arch/arm/mmu/pt.c +1
-0@@ -13,6 +13,7 @@#include <asm/current.h> #include <asm/fixmap.h> +#include <asm/mmu/layout.h>
This was supposed to be dropped.
Quoted 13 lines
xen/arch/arm/mmu/pt.c +3
-2#ifdef NDEBUG static inline void@@ -601,14 +602,21 @@ static int xen_pt_update(unsigned long virt,unsigned long vfn = virt >>PAGE_SHIFT ;unsigned long left = nr_mfns; +const mfn_t root =maddr_to_mfn (READ_SYSREG64 (TTBR0_EL2 )); + +#ifdef CONFIG_ARM_32 /* -* For arm32, page-tables are different on each CPUs. Yet, they share -* some common mappings. It is assumed that only common mappings
xen/arch/arm/mmu/pt.c static int xen_pt_update(unsigned long virt, · line 614
Quoted 10 lines
xen/arch/arm/mmu/pt.c +5
-4-* will be modified with this function. -* -* XXX: Add a check. +* Only Arm32 needs this check, as updating the domheap mapping here +* would only affect the current CPU. On Arm64, all the CPUs share the +* same page-tables. */ -const mfn_t root =maddr_to_mfn (READ_SYSREG64 (TTBR0_EL2 )); +if ( virt >=DOMHEAP_VIRT_START || + nr_mfns *PAGE_SIZE >DOMHEAP_VIRT_START - virt )
On arm32, nr_mfns * PAGE_SIZE could overflow. nr_mfns > PFN_DOWN(DOMHEAP_VIRT_START - virt) fixes that.
I will fix those issues on commit. Thanks.
~Michal