From patchwork Thu Jun 6 14:52:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 10979745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE080924 for ; Thu, 6 Jun 2019 14:55:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD039285A9 for ; Thu, 6 Jun 2019 14:55:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1AEB28A0F; Thu, 6 Jun 2019 14:55:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C31D0288E4 for ; Thu, 6 Jun 2019 14:55:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hYtlJ-0000K6-Du; Thu, 06 Jun 2019 14:53:05 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hYtlI-0000K1-9B for xen-devel@lists.xenproject.org; Thu, 06 Jun 2019 14:53:04 +0000 X-Inumbo-ID: c76f255c-886a-11e9-96f1-1bb4731b1534 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c76f255c-886a-11e9-96f1-1bb4731b1534; Thu, 06 Jun 2019 14:53:01 +0000 (UTC) Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=SoftFail smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: SoftFail (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com is inclined to not designate 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 include:spf.citrix.com include:spf2.citrix.com include:ironport.citrix.com exists:%{i}._spf.mta.salesforce.com ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: VJBci8yLgHLq7/lsdm+c/GuKKshgW2NjrMR3o2NCWJJnhXpQfkHlKmYSdRtWalos4qrothrFBR kmWWXwDl5GP5iTpUXoJ37ilYZA8UUZKvbEP4KwG3F9A9aFkIzONl074+B429slRRi8E0QbMYVS QaUqjnlAo8iSIAa4KxDAkLDokQXS7MmASYBCoJdeXYmp/cS/8Ttc2o26WjPeynIRG3uyWNxCOr OX8CbMbpTXwXDNARxWmwPrdPnOxOv+8rAR1lppfCtuzR3bMS/B8wgMiAsWIxMzsqFY8504kowe UL4= X-SBRS: -0.9 X-MesageID: 1413492 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,559,1557201600"; d="scan'208";a="1413492" From: Andrew Cooper To: Xen-devel Date: Thu, 6 Jun 2019 15:52:57 +0100 Message-ID: <1559832777-7818-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/pv: Fix undefined behaviour in check_descriptor() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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) ================================================================================ Switch to an unsigned shift. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné --- xen/arch/x86/x86_64/mm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index d8f558b..1721dcb 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 & (0xffu << 24)) | ((b & 0xff) << 16) | (a >> 16); limit = (b & 0xf0000) | (a & 0xffff); limit++; /* We add one because limit is inclusive. */