[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1] xen/arm: validate non-common page-table ranges


  • To: Gabriel Quintáns Souto <gabi.qs.mail@xxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Alejandro Vallejo" <alejandro.garciavallejo@xxxxxxx>
  • Date: Mon, 05 Oct 2026 15:35:19 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ED5LdYnpf0elcnvO8paeZu7OmqB67hI5teJUGQ0NAjc=; b=qHsHKm1vVtuIbfWTBI7mnO7gikGxQvB+0bIWmXf9GaJ2XY85Vj+S/BrPECKLCkZddAFnSuALYDN5mjUqAxBkAGDjmJEuhJ4Y8T5D4f5TilRutK9iqgmuUFIDoL91upaZ9/BlgU16mwv65g87z6rmcgZd3CfqXcNGSUe1QNpyJePpAPcQ1ZQkIPq7pqYpK+tT/9qSUIFT03YCDt24cxBLB3TG9TY3KB2bUoX5hriqv9rV25ljz/I+qT6DIrJBDkET7KS/qSSKU1t8cBhEOGZ8ElvaiJf+F298blzCWT3zn7mNI0Xvut1o9b8A1bLroYp07eV3tiEGcTmPaFHu5oDJFg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KAe0uWBXWIt2dBMt+eRXoaX12QlhsN6H/gVU0mkL7Lgx60hiRqvVog6fAdUYwXVE2/IhRJqzGWcCrQySRBc1DKYC9AgNRphewO2tvKZr4g1zvN4p6VO07yirDMre7aOBrtUw1W78MPNfJjOS5jVonWhi3MpNHC712iFvyFHHZ/+yTAsBez2Eq33nxkaC56EFcdwYD8pt37sjqeeLNJQ45NGbSHf8Bnj6tZ1/xI8RuVF4SThK1oQ+oyBnqiUIO6QnycjxccFlIm8iNB5qUs7hCwxATcKkO4PVOrasJdRulzEYiqs3IvuAQr0QBRCkfY8yef5msb55NgrmUCcj0a4y3A==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-Id:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: <michal.orzel@xxxxxxx>, <julien@xxxxxxx>, <bertrand.marquis@xxxxxxx>, <sstabellini@xxxxxxxxxx>
  • Delivery-date: Mon, 05 Oct 2026 13:37:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri Oct 2, 2026 at 9:14 PM CEST, Gabriel Quintáns Souto wrote:
> On arm32, page-tables are different on each CPUs, although they share some
> common mappings.
>
> The xen_pt_update function assumed that only said mappings would be
> modified, but did not check this assumption.
>
> Add a range check to reject modifications to non-common mappings.
>
> Signed-off-by: Gabriel Quintáns Souto <gabi.qs.mail@xxxxxxxxx>

I'm not an arm person, so take this with a serious pinch of salt.

> ---
>  xen/arch/arm/mmu/pt.c | 36 +++++++++++++++++++++++++++++-------
>  1 file changed, 29 insertions(+), 7 deletions(-)
>
> diff --git a/xen/arch/arm/mmu/pt.c b/xen/arch/arm/mmu/pt.c
> index 621b47d..ad0d1e6 100644
> --- a/xen/arch/arm/mmu/pt.c
> +++ b/xen/arch/arm/mmu/pt.c
> @@ -13,6 +13,7 @@
>  
>  #include <asm/current.h>
>  #include <asm/fixmap.h>
> +#include <asm/mmu/layout.h>
>  
>  #ifdef NDEBUG
>  static inline void
> @@ -589,6 +590,29 @@ static unsigned int xen_pt_check_contig(unsigned long 
> vfn, mfn_t mfn,
>      return XEN_PT_4K_NR_CONTIG;
>  }
>  
> +#ifdef CONFIG_ARM_32
> +static bool ranges_overlap(unsigned long start1, unsigned long size1,
> +                           unsigned long start2, unsigned long size2)
> +{
> +    if ( start1 < start2 )
> +        return start2 - start1 < size1;
> +
> +    return start1 - start2 < size2;
> +}
> +
> +static bool xen_pt_range_is_non_common(unsigned long virt,

We typically prefer positive helpers so you never end up with
!xen_pt_range_is_non_common(), which is awkward to read.

IMO, this should be xen_pt_range_is_common() with the reverse polarity
in the code elsewhere.

> +                                       unsigned long size)
> +{
> +    unsigned long temporary_start = TEMPORARY_AREA_ADDR(0);
> +    unsigned long temporary_size = XEN_PT_LEVEL_SIZE(1);
> +

All ifdefs can go away if you do:

  if ( !IS_ENABLED(CONFIG_ARM_32) )
      return 0;

... here. Everything else drops with DCE when compiling with ARM_32=n
both with DEBUG=y and DEBUG=n.

And codegen would be identical.

> +    return ranges_overlap(virt, size,
> +                          DOMHEAP_VIRT_START, DOMHEAP_VIRT_SIZE) ||
> +           ranges_overlap(virt, size,
> +                          temporary_start, temporary_size);
> +}
> +#endif
> +
>  static DEFINE_SPINLOCK(xen_pt_lock);
>  
>  static int xen_pt_update(unsigned long virt,
> @@ -601,15 +625,13 @@ static int xen_pt_update(unsigned long virt,
>      unsigned long vfn = virt >> PAGE_SHIFT;
>      unsigned long left = nr_mfns;
>  
> -    /*
> -     * 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.
> -     */
>      const mfn_t root = maddr_to_mfn(READ_SYSREG64(TTBR0_EL2));
>  
> +    #ifdef CONFIG_ARM_32
> +    if ( xen_pt_range_is_non_common(virt, nr_mfns * PAGE_SIZE) )

nit: Perhaps ASSERT_UNREACHABLE() here? Presumably this path is a
logical error.

> +        return -EINVAL;
> +    #endif
> +
>      if ( flags_has_rwx(flags) )
>      {
>          mm_printk("Mappings should not be both Writeable and Executable.\n");

Cheers,
Alejandro



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.