From: dmkhn@proton.me
To: Julien Grall <julien@xen.org>
Cc: xen-devel@lists.xenproject.org,
"Julien Grall" <jgrall@amazon.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Bertrand Marquis" <bertrand.marquis@arm.com>,
"Michal Orzel" <michal.orzel@amd.com>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Oleksii Kurochko" <oleksii.kurochko@gmail.com>
Subject: Re: [PATCH] P2M: Don't try to free the existing PTE if we can't allocate a new table
Date: Sat, 26 Jul 2025 21:08:11 +0000 [thread overview]
Message-ID: <aIVDt5hNXPBo4hUN@kraken> (raw)
In-Reply-To: <20250726122607.75950-1-julien@xen.org>
On Sat, Jul 26, 2025 at 01:26:07PM +0100, Julien Grall wrote:
> From: Julien Grall <jgrall@amazon.com>
>
> When we can't split a superpage (on Arm p2m_split_superpage() returns false,
> on x86 ept_split_superpage() returns 0), the caller is expected to clean
> any PTE that may have been allocated. However, when we can't allocate
> the page-tables 'entry' (arm) / 'ept_entry' still points to a live PTE.
> So we will end up to free a PTE that is still used.
>
> In practice for:
> * x86: We don't do any refcounting for 2MB/1GB mappings. So this is
> harmless
> * arm: We do refcounting for 2MB mapping (not for 1GB ones). This is
> only used for static memory.
>
> So there is a security issue on Arm but this doesn't meet the criteria
> for an XSA (static memory is not security supported).
>
> Solve the issue by clearing the PTE if we can't allocate the table.
>
> Reported-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
>
> ----
>
> I decided to not split the patch in two as the issue for x86 and
> arm is the same. But I am happy to split if this is preferred.
> ---
> xen/arch/arm/mmu/p2m.c | 8 ++++++++
> xen/arch/x86/mm/p2m-ept.c | 9 +++++++++
> 2 files changed, 17 insertions(+)
>
> diff --git a/xen/arch/arm/mmu/p2m.c b/xen/arch/arm/mmu/p2m.c
> index 51abf3504fcf..9a1fb44a0204 100644
> --- a/xen/arch/arm/mmu/p2m.c
> +++ b/xen/arch/arm/mmu/p2m.c
> @@ -888,7 +888,15 @@ static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry,
>
> page = p2m_alloc_page(p2m->domain);
> if ( !page )
> + {
> + /*
> + * The caller is in charge to free the sub-tree. So tell the
^^^
Looks like the "So tell the" can be dropped from the commentary.
Same comment for the p2m-ept.c below.
> + * As we didn't manage to allocate anything, just tell the
> + * caller there is nothing to free by invalidating the PTE.
> + */
> + memset(entry, 0, sizeof(*entry));
> return false;
> + }
>
> page_list_add(page, &p2m->pages);
> table = __map_domain_page(page);
> diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
> index 62fc8e50689f..1efac27835d2 100644
> --- a/xen/arch/x86/mm/p2m-ept.c
> +++ b/xen/arch/x86/mm/p2m-ept.c
> @@ -261,7 +261,16 @@ static bool ept_split_super_page(
>
> table = ept_set_middle_entry(p2m, &new_ept);
> if ( !table )
> + {
> + /*
> + * The caller is in charge to free the sub-tree. So tell the
> + * As we didn't manage to allocate anything, just tell the
> + * caller there is nothing to free by invalidating the PTE.
> + */
> + memset(ept_entry, 0, sizeof(*ept_entry));
> +
> return 0;
> + }
>
> trunk = 1UL << ((level - 1) * EPT_TABLE_ORDER);
>
> --
> 2.47.3
>
>
prev parent reply other threads:[~2025-07-26 21:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-26 12:26 [PATCH] P2M: Don't try to free the existing PTE if we can't allocate a new table Julien Grall
2025-07-26 21:08 ` dmkhn [this message]
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=aIVDt5hNXPBo4hUN@kraken \
--to=dmkhn@proton.me \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=bertrand.marquis@arm.com \
--cc=jbeulich@suse.com \
--cc=jgrall@amazon.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=oleksii.kurochko@gmail.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.