From 11ad7d71610c3d3fc5edd545d05a6328cdba235f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 27 Mar 2025 15:02:49 +0100 Subject: [PATCH] x86/xlat: fix UB pointer arithmetic in COMPAT_ARG_XLAT_VIRT_BASE MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit UBSAN complains with: UBSAN: Undefined behaviour in common/compat/memory.c:90:9 pointer operation overflowed ffff820080000000 to 0000020080000000 [...] Xen call trace: [] R common/ubsan/ubsan.c#ubsan_epilogue+0xa/0xc0 [] F __ubsan_handle_pointer_overflow+0xcb/0x100 [] F compat_memory_op+0xf1/0x4d20 [] F hvm_memory_op+0x55/0xe0 [] F hvm_hypercall+0xae8/0x21b0 [] F svm_vmexit_handler+0x1252/0x2450 [] F svm_stgi_label+0x5/0x15 Adjust the calculations in COMPAT_ARG_XLAT_VIRT_BASE to subtract from the per-domain area to obtain the mirrored linear address in the 4th slot, instead of overflowing the per-domain linear address. Signed-off-by: Roger Pau Monné Acked-by: Andrew Cooper master commit: fc302866f42f552337ae7d8d78877aec36e6e2ff master date: 2025-03-20 12:28:30 +0100 --- xen/arch/x86/include/asm/x86_64/uaccess.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/include/asm/x86_64/uaccess.h b/xen/arch/x86/include/asm/x86_64/uaccess.h index c6fa3fd381..9f515b2638 100644 --- a/xen/arch/x86/include/asm/x86_64/uaccess.h +++ b/xen/arch/x86/include/asm/x86_64/uaccess.h @@ -9,9 +9,9 @@ * a secondary mapping installed, which needs to be used for such accesses in * the PV case, and will also be used for HVM to avoid extra conditionals. */ -#define COMPAT_ARG_XLAT_VIRT_BASE ((void *)ARG_XLAT_START(current) + \ - (PERDOMAIN_ALT_VIRT_START - \ - PERDOMAIN_VIRT_START)) +#define COMPAT_ARG_XLAT_VIRT_BASE ((void *)ARG_XLAT_START(current) - \ + PERDOMAIN_VIRT_START + \ + PERDOMAIN_ALT_VIRT_START) #define COMPAT_ARG_XLAT_SIZE (2*PAGE_SIZE) struct vcpu; int setup_compat_arg_xlat(struct vcpu *v); -- 2.39.5