mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
compat/memory: avoid UB shifts in XENMEM_exchange handling
Add an early basic check, yielding the same error code as the more
thorough one the main handler would produce.
Fixes: b8a7efe852 ("Enable compatibility mode operation for HYPERVISOR_memory_op")
Reported-by: Manuel Andreas <manuel.andreas@tum.de>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
1 parent
142f0a43a1
commit
560c51be8f
1 file changed
+5
@@ -161,6 +161,11 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
|
||||
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) ||
|
||||
|
||||