Skip to contentSkip to conversation

compat/memory: avoid UB shifts in XENMEM_exchange handling

PATCH In review Jan Beulich 3 participants 4 messages Apr 17, 2025 – Apr 22, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compat/memory: avoid UB shifts in XENMEM_exchange handling

Add an early basic check, yielding the same error code as the more thorough on the the main handler would produce.

Fixes b8a7efe8528a ("Enable compatibility mode operation for HYPERVISOR_memory_op")
xen/common/compat/memory.c +5 -0
@@ -161,6 +161,11 @@ int compat_memory_op(unsigned int cmd, X
             if ( copy_from_guest(&cmp.xchg, arg, 1) )
                 return -EFAULT;
 
+            /* Early coarse check, as max_order() isn't available here. */
+            if ( cmp.xchg.in.extent_order >= BITS_PER_INT ||
+                 cmp.xchg.out.extent_order >= BITS_PER_INT )
+                return -EPERM;
+
             order_delta = cmp.xchg.out.extent_order - cmp.xchg.in.extent_order;
             /* Various sanity checks. */
             if ( (cmp.xchg.nr_exchanged > cmp.xchg.in.nr_extents) ||
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Jan Beulich

Add an early basic check, yielding the same error code as the more thorough on the the main handler would produce.

"as the more thorough check in the main handler"...

Quoted 3 lines
Fixes b8a7efe8528a ("Enable compatibility mode operation for HYPERVISOR_memory_op")

With that:

#2 lore raw
Quoted 5 lines · Jason Andryuk
Quoted 2 lines · Jan Beulich

Add an early basic check, yielding the same error code as the more thorough on the the main handler would produce.

"as the more thorough check in the main handler"...

I had already correct the typo ("on" when "one" was meant).

Quoted 7 lines
Quoted 3 lines
Fixes b8a7efe8528a ("Enable compatibility mode operation for HYPERVISOR_memory_op")

With that:

Thanks.

Jan