Skip to contentSkip to conversation

xen/rangeset: Fix rangeset_remove_range() with e == ~0UL

PATCH In review Stefano Stabellini 2 participants 2 messages Oct 24 – Oct 26

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/rangeset: Fix rangeset_remove_range() with e == ~0UL

When the removal spans several ranges, the last one is trimmed by setting its start to e + 1, and destroyed if that leaves it empty. For e == ~0UL, e + 1 wraps to 0, so the range is kept as [0, end] and the removal adds everything below it.

This is hit by pv_shim_shutdown(), whose iomem_deny_access(d, 0, ~0UL) on resume turns the guest's grant frame permissions into [0, highest grant frame]. arch_iommu_hwdom_init() can hit it too, for a PVH hardware domain with an E820 entry above its 48-bit iomem_caps.

Destroy the range when it ends within [s, e] instead.

---
 xen/common/rangeset.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
xen/common/rangeset.c +3 -2
index 0e3b9acd35..2c0c1bfc08 100644
@@ -239,9 +239,10 @@ int rangeset_remove_range(
             destroy_range(r, t);
         }
 
-        x->s = e + 1;
-        if ( x->s > x->e )
+        if ( x->e <= e )
             destroy_range(r, x);
+        else
+            x->s = e + 1;
     }
 
  out:
Signature · 1 line
2.43.0
#1 lore raw
Quoted 10 lines · Stefano Stabellini

When the removal spans several ranges, the last one is trimmed by setting its start to e + 1, and destroyed if that leaves it empty. For e == ~0UL, e + 1 wraps to 0, so the range is kept as [0, end] and the removal adds everything below it.

This is hit by pv_shim_shutdown(), whose iomem_deny_access(d, 0, ~0UL) on resume turns the guest's grant frame permissions into [0, highest grant frame]. arch_iommu_hwdom_init() can hit it too, for a PVH hardware domain with an E820 entry above its 48-bit iomem_caps.

Quoted 4 lines

Destroy the range when it ends within [s, e] instead.

This again could have done with a Fixes: tag. Yes, digging out offending commits is extra work, but if patch authors don't do so, someone else will (often) need to do so in their stead.

Jan