Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp798375pxp; Fri, 11 Mar 2022 15:26:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJ2QAKZZYa+VQog9J9p139fvUqhmB2BOJldofl5qoaeP/B+c3WRKoh+waRKR3zoWmIvQH3 X-Received: by 2002:a65:4144:0:b0:374:315a:7dff with SMTP id x4-20020a654144000000b00374315a7dffmr10321012pgp.506.1647041167604; Fri, 11 Mar 2022 15:26:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647041167; cv=none; d=google.com; s=arc-20160816; b=N10TX5KQ1ev7hmaXY3pKQn6vnBMVRTEA4o6U2zTf00RVF4PmHyakh8HRyOzU3xzdk5 vDRUe2AolrgB+LZuXV/JxAN4lMYCzvwgvUBvx+OQtilMtQWbk93cAtNhklFcZ05O9DTc ael4hIkRWVjnsNurTagGXglqNwK0Ms/4xa6VSjTSxOuiGe/x/IsfTQyYOq0IMP9OHS62 vLSCiFb9e9sntkjB5v6XlFnroxVHxnUg1qsHxI87eiD+mALFJfpSfARu4GqE3rV+2R8e 06oo4vJkgMVO1BlHHElczBgAM8lGetOSlTM71dIXJv+Nx4flm0vXfx0BW/35i4KQIyPn 34dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+ikKK98FdW600Iuip5eOvgUSE1kcF29cnROYdqeiqGQ=; b=wA2OkJ+Ep2UuRMQ+EyHAHjBCfESZ6vPSFO9wpbfvF6sA8gwMuk30bbxZuw5Vo6/29b iSBB9tvHq9aFPuFxDOKaahJ1DDLm2MycqscrAZmLelc2MI0jWrM2zY75vRcs+9DHVxjS Q64N72zlt0dX+SStLsg9LooxGyyqx0lMKwtaEhlVzcrqToi4HnxMxv3RVh9+/3GmaCWf 5Q3JgMe0ijiqg2yVt8wvDktS0LCmUZyGKsubXKS8Xflg69Am0/njtjefopr4CNHAIU6M 2UnQ42agD3MvodZlTRuLTtHr5KWUbiR1lBcWtNRGeXyrhzS8UzlrzGH6Q9hRw22+yuGF 3POw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K2UT2QnJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n4-20020a170902e54400b00151bf332ad4si9624986plf.2.2022.03.11.15.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 15:26:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K2UT2QnJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 94BB3275574; Fri, 11 Mar 2022 14:12:46 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243228AbiCJOQn (ORCPT + 99 others); Thu, 10 Mar 2022 09:16:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243174AbiCJOQM (ORCPT ); Thu, 10 Mar 2022 09:16:12 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78F04A9E17; Thu, 10 Mar 2022 06:12:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C8BB861BA3; Thu, 10 Mar 2022 14:12:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9D95C340E8; Thu, 10 Mar 2022 14:12:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646921560; bh=KoqgjawotcTUnzxOmTOceGJDLcd5aqX3AQO94bdCzbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K2UT2QnJwhmZr/5yERQwpMDx+cVrt1e57uHYT6n3kFP+r6hST7BBZsmODHs/NhP3X tAioBRUH7AjtEQSgy0B6dcILA/ivsoLCFUNynVa6pojBSEPOKv5mE6lPGT68diFQwD YLJ+zoc+RS/pUkFoW4EygeKHXZCEnsw/D9BYFMuY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Simon Gaiser , Juergen Gross , Jan Beulich Subject: [PATCH 5.16 49/53] xen/9p: use alloc/free_pages_exact() Date: Thu, 10 Mar 2022 15:09:54 +0100 Message-Id: <20220310140813.243670002@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310140811.832630727@linuxfoundation.org> References: <20220310140811.832630727@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juergen Gross Commit 5cadd4bb1d7fc9ab201ac14620d1a478357e4ebd upstream. Instead of __get_free_pages() and free_pages() use alloc_pages_exact() and free_pages_exact(). This is in preparation of a change of gnttab_end_foreign_access() which will prohibit use of high-order pages. By using the local variable "order" instead of ring->intf->ring_order in the error path of xen_9pfs_front_alloc_dataring() another bug is fixed, as the error path can be entered before ring->intf->ring_order is being set. By using alloc_pages_exact() the size in bytes is specified for the allocation, which fixes another bug for the case of order < (PAGE_SHIFT - XEN_PAGE_SHIFT). This is part of CVE-2022-23041 / XSA-396. Reported-by: Simon Gaiser Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich Signed-off-by: Greg Kroah-Hartman --- net/9p/trans_xen.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) --- a/net/9p/trans_xen.c +++ b/net/9p/trans_xen.c @@ -281,9 +281,9 @@ static void xen_9pfs_front_free(struct x ref = priv->rings[i].intf->ref[j]; gnttab_end_foreign_access(ref, 0, 0); } - free_pages((unsigned long)priv->rings[i].data.in, - priv->rings[i].intf->ring_order - - (PAGE_SHIFT - XEN_PAGE_SHIFT)); + free_pages_exact(priv->rings[i].data.in, + 1UL << (priv->rings[i].intf->ring_order + + XEN_PAGE_SHIFT)); } gnttab_end_foreign_access(priv->rings[i].ref, 0, 0); free_page((unsigned long)priv->rings[i].intf); @@ -322,8 +322,8 @@ static int xen_9pfs_front_alloc_dataring if (ret < 0) goto out; ring->ref = ret; - bytes = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, - order - (PAGE_SHIFT - XEN_PAGE_SHIFT)); + bytes = alloc_pages_exact(1UL << (order + XEN_PAGE_SHIFT), + GFP_KERNEL | __GFP_ZERO); if (!bytes) { ret = -ENOMEM; goto out; @@ -354,9 +354,7 @@ out: if (bytes) { for (i--; i >= 0; i--) gnttab_end_foreign_access(ring->intf->ref[i], 0, 0); - free_pages((unsigned long)bytes, - ring->intf->ring_order - - (PAGE_SHIFT - XEN_PAGE_SHIFT)); + free_pages_exact(bytes, 1UL << (order + XEN_PAGE_SHIFT)); } gnttab_end_foreign_access(ring->ref, 0, 0); free_page((unsigned long)ring->intf);