[PATCH 1/4] xen/domain: Disallow XENMEM_claim_pages on dying domains

Andrew Cooper posted 4 patches 1 day, 15 hours ago
[PATCH 1/4] xen/domain: Disallow XENMEM_claim_pages on dying domains
Posted by Andrew Cooper 1 day, 15 hours ago
XENMEM_claim_pages can be issued on a domain in the later stages of
domain_kill().  In that case, the claimed memory is leaked, as there's no way
to subsequently release the claim.

Claims are intended for use during domain construction; to reserve sufficient
RAM to construct the domain fully.  There's no legitimate reason to be calling
it on a dying domain.

Fixes: 65c9792df600 ("mmu: Introduce XENMEM_claim_pages (subop of memory ops)")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Anthony PERARD <anthony.perard@vates.tech>
CC: Michal Orzel <michal.orzel@amd.com>
CC: Jan Beulich <jbeulich@suse.com>
CC: Julien Grall <julien@xen.org>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/memory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/xen/common/memory.c b/xen/common/memory.c
index 3688e6dd5032..ae805ccbe4d1 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -1681,6 +1681,9 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         rc = xsm_claim_pages(XSM_PRIV, d);
 
+        if ( !rc && d->is_dying )
+            rc = -EINVAL;
+
         if ( !rc )
             rc = domain_set_outstanding_pages(d, reservation.nr_extents);
 
-- 
2.39.5


Re: [PATCH 1/4] xen/domain: Disallow XENMEM_claim_pages on dying domains
Posted by Jan Beulich 1 day ago
On 16.12.2025 17:32, Andrew Cooper wrote:
> XENMEM_claim_pages can be issued on a domain in the later stages of
> domain_kill().  In that case, the claimed memory is leaked, as there's no way
> to subsequently release the claim.
> 
> Claims are intended for use during domain construction; to reserve sufficient
> RAM to construct the domain fully.  There's no legitimate reason to be calling
> it on a dying domain.
> 
> Fixes: 65c9792df600 ("mmu: Introduce XENMEM_claim_pages (subop of memory ops)")
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>