From nobody Mon Nov 23 22:28:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794322411; cv=none; d=zohomail.com; s=zohoarc; b=lzoCHn7AQpkQvo8hRkiV0xHf0cSHVC1Ate6G32n03M9ioBQskhQrugFAo3whrpbMH7+YVpjbgHFUcskPaSXsiFaNURJBEx+fRf8mO3SdAP0kQP4EYsVhfuDTx2kISf3OWFdyC7a9LGkXW9BwxkGOhYi/AfQVs4BWo30SDV2kwzI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794322411; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1FKVHSKIBfpVkaisuY8vlvieNA/N/Wpk2HUySPa0RXo=; b=gKKLydC8RO0NDYMEnogVdI9b7K/IANBSZawRtsLDtZXWqbvV5ZcmUS75cZArbtZwc7XQzZPfhm8xrhcLpcC9zHsNNZqbxmrNBKMMTyM7GVbhnvssGsmQ23Txf2YErKG2wJiPoqlSH2xdIagpwZGuUlC5A8VVSb0TDQXuD7RDhCQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1794322411058332.61635999519547; Tue, 10 Nov 2026 06:53:31 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1481934.1685822 (Exim 4.92) (envelope-from ) id 1xQnDk-0006Op-8K; Tue, 10 Nov 2026 14:53:12 +0000 Received: by outflank-mailman (output) from mailman id 1481934.1685822; Tue, 10 Nov 2026 14:53:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xQnDk-0006Od-56; Tue, 10 Nov 2026 14:53:12 +0000 Received: by outflank-mailman (input) for mailman id 1481934; Tue, 10 Nov 2026 14:53:11 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xQnDi-0006OU-Up for xen-devel@lists.xenproject.org; Tue, 10 Nov 2026 14:53:11 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xQnDi-007hhR-B3 for xen-devel@lists.xenproject.org; Tue, 10 Nov 2026 15:53:10 +0100 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af32fd0-e002-0a2a0a5209dd-0a2a450bb192-14 for ; Tue, 10 Nov 2026 15:53:10 +0100 Received: from [209.85.221.41] (helo=mail-wr1-f41.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af32fd6-b7e8-0a2a450b0019-d155dd29c824-3 for ; Tue, 10 Nov 2026 15:53:10 +0100 Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-490c3ae81d3so1407134f8f.2 for ; Tue, 10 Nov 2026 06:53:10 -0800 (PST) Received: from ws-fedora.tail006fee.ts.net ([139.47.58.79]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-498357648f0sm5424579f8f.12.2026.11.10.06.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 06:53:09 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794322390; x=1794927190; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1FKVHSKIBfpVkaisuY8vlvieNA/N/Wpk2HUySPa0RXo=; b=Ngk3cHLngSHyQNAJXXWZPvR97ohp88YtbfzROAkMHKM/rFDR9eLxnNpAPBF1eE6BhX G0Ei62aPASyLy8UvBLxzc0cEvvwnMm0/Zm0lpr3V2YTd1Uc8Zp0K01p/aNI3evJwifgs 2DTEILGKEdAxuu09PBNT8JteF4AL9iIOlry14yUfLpahZgQunywyxUQID2Tj+jJv6h3u A4GaIOBV4EjptSEqSSPwDQew8C9TUFCWz/XCfjU8Fn+E/dT8L6F5TudJxp4+w7nYf+V8 LVMdrUHqPocFJGV1vAleeDJarm7Hu0fJyeX7O+Ken1tX+nNexSGeqJkpxMFsP4McDswg kXcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794322390; x=1794927190; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=1FKVHSKIBfpVkaisuY8vlvieNA/N/Wpk2HUySPa0RXo=; b=CQK9r+dnVFQU16m1kNhSDt9Xlo9F5bi0cjifZ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BVQMtD0= X-Received: by 2002:a05:6000:2006:b0:48e:720a:ccaf with SMTP id ffacd0b85a97d-4982b28a87amr5488991f8f.5.1794322389581; Tue, 10 Nov 2026 06:53:09 -0800 (PST) From: =?UTF-8?q?Gabriel=20Quint=C3=A1ns=20Souto?= To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, julien@xen.org, bertrand.marquis@arm.com, michal.orzel@amd.com, Volodymyr_Babchuk@epam.com, =?UTF-8?q?Gabriel=20Quint=C3=A1ns=20Souto?= Subject: [PATCH v4] xen/arm: validate non-common page-table ranges Date: Tue, 10 Nov 2026 15:52:31 +0100 Message-ID: <20261110145231.7409-1-gabi.qs.mail@gmail.com> X-Mailer: git-send-email 2.56.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1794322390-AB2DC9EA-56F5F0B5/0/0 X-purgate-type: clean X-purgate-size: 4108 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1794322413324158500 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=C3=A1ns Souto --- 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/include/asm/arm32/mm.h | 24 ++++++++++++++++++++++++ xen/arch/arm/include/asm/arm64/mm.h | 10 ++++++++++ xen/arch/arm/mmu/pt.c | 14 +++++++------- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/include/asm/arm32/mm.h b/xen/arch/arm/include/asm= /arm32/mm.h index 856f2db..c7d09d3 100644 --- a/xen/arch/arm/include/asm/arm32/mm.h +++ b/xen/arch/arm/include/asm/arm32/mm.h @@ -16,6 +16,30 @@ static inline bool arch_mfns_in_directmap(unsigned long = mfn, unsigned long nr) return false; } =20 +static inline bool ranges_overlap(unsigned long start1, unsigned long size= 1, + unsigned long start2, unsigned long size2) +{ + if ( start1 < start2 ) + return start2 - start1 < size1; + + return start1 - start2 < size2; +} + +/* + * On ARM32, page-tables differ between CPUs, so not all mappings are comm= on. + */ +static inline bool xen_pt_range_is_common(unsigned long virt, + unsigned long size) +{ + unsigned long temporary_start =3D TEMPORARY_AREA_ADDR(0); + unsigned long temporary_size =3D XEN_PT_LEVEL_SIZE(1); + + return !ranges_overlap(virt, size, + DOMHEAP_VIRT_START, DOMHEAP_VIRT_SIZE) && + !ranges_overlap(virt, size, + temporary_start, temporary_size); +} + bool init_domheap_mappings(unsigned int cpu); =20 static inline void arch_setup_page_tables(void) diff --git a/xen/arch/arm/include/asm/arm64/mm.h b/xen/arch/arm/include/asm= /arm64/mm.h index b4f7545..a3cb56d 100644 --- a/xen/arch/arm/include/asm/arm64/mm.h +++ b/xen/arch/arm/include/asm/arm64/mm.h @@ -12,6 +12,16 @@ static inline bool arch_mfns_in_directmap(unsigned long = mfn, unsigned long nr) return true; } =20 +/* + * On ARM64, the Xen page-tables are shared by all the CPUs, + * any range is therefore common. + */ +static inline bool xen_pt_range_is_common(unsigned long virt, + unsigned long size) +{ + return true; +} + void arch_setup_page_tables(void); =20 void update_boot_mapping(bool enable); diff --git a/xen/arch/arm/mmu/pt.c b/xen/arch/arm/mmu/pt.c index 81fe121..42fa79a 100644 --- a/xen/arch/arm/mmu/pt.c +++ b/xen/arch/arm/mmu/pt.c @@ -13,6 +13,7 @@ =20 #include #include +#include =20 #ifdef NDEBUG static inline void @@ -601,15 +602,14 @@ static int xen_pt_update(unsigned long virt, unsigned long vfn =3D virt >> PAGE_SHIFT; unsigned long left =3D nr_mfns; =20 - /* - * 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 =3D maddr_to_mfn(READ_SYSREG64(TTBR0_EL2)); =20 + if ( !xen_pt_range_is_common(virt, nr_mfns * PAGE_SIZE) ) + { + ASSERT_UNREACHABLE(); + return -EINVAL; + } + if ( flags_has_rwx(flags) ) { mm_printk("Mappings should not be both Writeable and Executable.\n= "); --=20 2.56.0