From: Andrew Cooper Date: Thu, 6 Jun 2019 14:44:21 +0000 (+0100) Subject: x86/pv: Fix undefined behaviour in check_descriptor() X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=bd5be40ce2307ea5e8f52e3103d1b48ca9dfdce9;p=people%2Fsstabellini%2Fxen-unstable.git%2F.git x86/pv: Fix undefined behaviour in check_descriptor() UBSAN reports: (XEN) ================================================================================ (XEN) UBSAN: Undefined behaviour in x86_64/mm.c:1108:31 (XEN) left shift of 255 by 24 places cannot be represented in type 'int' (XEN) ----[ Xen-4.13-unstable x86_64 debug=y Tainted: H ]---- (XEN) CPU: 60 (XEN) RIP: e008:[] ubsan.c#ubsan_epilogue+0xa/0xc2 (XEN) Xen call trace: (XEN) [] ubsan.c#ubsan_epilogue+0xa/0xc2 (XEN) [] __ubsan_handle_shift_out_of_bounds+0x15d/0x16c (XEN) [] check_descriptor+0x191/0x3dd (XEN) [] do_update_descriptor+0x7f/0x2b6 (XEN) [] compat_update_descriptor+0x1e/0x20 (XEN) [] pv_hypercall+0x87f/0xa6f (XEN) [] do_entry_int82+0x53/0x58 (XEN) [] entry_int82+0xbb/0xc0 (XEN) (XEN) ================================================================================ As this is a constant, express it in longhand for correctness, and consistency with the surrounding code. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index d8f558bc3a..899b883b2d 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -1105,7 +1105,7 @@ int check_descriptor(const struct domain *dom, seg_desc_t *d) * 0xf6800000. Extend these to allow access to the larger read-only * M2P table available in 32on64 mode. */ - base = (b & (0xff << 24)) | ((b & 0xff) << 16) | (a >> 16); + base = (b & 0xff000000) | ((b & 0xff) << 16) | (a >> 16); limit = (b & 0xf0000) | (a & 0xffff); limit++; /* We add one because limit is inclusive. */