From patchwork Tue Jul 30 16:44:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11066193 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 4FD1614DB for ; Tue, 30 Jul 2019 16:45:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 423EB284DB for ; Tue, 30 Jul 2019 16:45:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36C6F2857E; Tue, 30 Jul 2019 16:45:57 +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 BEA4B284DB for ; Tue, 30 Jul 2019 16:45:56 +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 1hsVEO-0003sD-MW; Tue, 30 Jul 2019 16:44:08 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hsVEN-0003s3-FB for xen-devel@lists.xenproject.org; Tue, 30 Jul 2019 16:44:07 +0000 X-Inumbo-ID: 3e8d2704-b2e9-11e9-8980-bc764e045a96 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 3e8d2704-b2e9-11e9-8980-bc764e045a96; Tue, 30 Jul 2019 16:44:06 +0000 (UTC) Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: WHQGUY3xml/8j8VtVLAAQQUc4MHwxnztbkyHXElZfwuRaN40Yvf/fNcvu4jMf53nPXhtmnqbbC nxlqHS6ndwVvOzS2TI3Eh4LbfarBkts9XVxofKhWz+u7rBn22NNLQB3BgdFQYMANe3VCYFWAY7 rgkQ9X2u51adsEkQJ0iyySw1Q1/gUe1FCn5XllkQ0o/E5s7jrYpnVTb0He555Ns/d2g9a/fSWt sk7UibJWm5tQ8xSPZbvOyVVj4E9DO5QcTvJQu3Gmx/Kp9S9921hKDVnaRpjfZP3tQAtz2dUvzw qrc= X-SBRS: 2.7 X-MesageID: 3754868 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,327,1559534400"; d="scan'208";a="3754868" From: Paul Durrant To: Date: Tue, 30 Jul 2019 17:44:01 +0100 Message-ID: <20190730164401.34097-1-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] fix BUG in gnttab_unpopulate_status_frames() 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: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Paul Durrant , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Since commit ec83f825627 "mm.h: add helper function to test-and-clear _PGC_allocated" (and subsequent fix-up 44a887d021d "mm.h: fix BUG_ON() condition in put_page_alloc_ref()") setting grant table version from 2 back to 1 has been vulnerable to hitting the BUG_ON in put_page_alloc_ref() during gnttab_unpopulate_status_frames() because that function does not acquire a local page reference. This patch fixes the problem by first acquiring a local page reference on a status frame (which should always succeed and so a failure results in a domain_crash()) before attempting to 'unassign' it from the guest by dropping the allocation reference. The local reference can then be dropped. Signed-off-by: Paul Durrant --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu --- xen/common/grant_table.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 97695a221a..b9ca388051 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1682,6 +1682,14 @@ gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt) struct page_info *pg = virt_to_page(gt->status[i]); gfn_t gfn = gnttab_get_frame_gfn(gt, true, i); + if ( !get_page(pg, d) ) + { + gprintk(XENLOG_ERR, + "Could not get a reference to status frame %u\n", i); + domain_crash(d); + return -EINVAL; + } + /* * For translated domains, recovering from failure after partial * changes were made is more complicated than it seems worth @@ -1708,6 +1716,7 @@ gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt) BUG_ON(page_get_owner(pg) != d); put_page_alloc_ref(pg); + put_page(pg); if ( pg->count_info & ~PGC_xen_heap ) {