Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp66158pxp; Thu, 10 Mar 2022 22:44:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzha7d7UF2O+25AW1xAb3IBHgNRVPAfVvylZFY/kSeM+DIofSpSy8rrKnAJ7tSsFzt0wjV4 X-Received: by 2002:a63:af02:0:b0:375:57f0:8af1 with SMTP id w2-20020a63af02000000b0037557f08af1mr7281169pge.188.1646981067777; Thu, 10 Mar 2022 22:44:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646981067; cv=none; d=google.com; s=arc-20160816; b=NAK5tTo8gh2eHBraOSAJEDNgATszAEhE/Y/DDrvxxTXU7OaJYpy1yp2X31LWiwjnE4 7B9yi5msXRWtaoPIU+lwVOFnmeHcUvY72iFXzBB/XPZMrs40vC1gGcxDKiImlpY9X4lq Z4Vz9K+h0VwLNePILCD0k5oaWoZvrI/Y1k2Swq9vxDLGkDYGWQd8W3qxM9TRWBjwljPv upNgSWz/qRYlmMFYbQ5Xze6EMECWYelBC5Yrkx+VvVNxETLq7mIi/eCAmiWD8DHgW/wl eHW6ou8B1JDkwo1oM1ZkAy95GN6oEeWdIO+D4eVeCEiuuUmbRrC59X5omaejnWGAhykj 5WHA== 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=tlH9wqp/Mo7+qLr1ajSaurNWOULnQzwI2XWQTiRmGmE=; b=j9Chfs26TmGJyGSMDGMcecKHb+kMKBFpck7sF5znSV9lvwUuEYDwxx7TgvlonGqNwP a2eJYZNOYLmm+0gbXjFm2EFpoL9ipPoj7LdVJ1N9PJ7vBDdJS185gtYdSh2u5FFM8AGB q051fx2Jo89+vMdQ9vaVGLx6EnPdFMkAufYdhvCMK4IVlFNYnUZMgXF4KSj4fw5X0qky ddgDmIYYw4uV3oIz19J2ELG+D40UY7e31iPKkixWh/OC9ghaDNYfl+4SoNh1csnTcQei imIpRL1hFNVQfDkUE6XP7xbBLDU/RdzkVr27KaMMgPgKRyPgDHeZ6xsRBfvdIOcSa87H 4ohw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jg2cw7RR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a17090a2b8300b001bd14e0306dsi4051037pjd.69.2022.03.10.22.44.02; Thu, 10 Mar 2022 22:44:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jg2cw7RR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243584AbiCJO11 (ORCPT + 99 others); Thu, 10 Mar 2022 09:27:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243672AbiCJOYt (ORCPT ); Thu, 10 Mar 2022 09:24:49 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12F1515C188; Thu, 10 Mar 2022 06:21:31 -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 ams.source.kernel.org (Postfix) with ESMTPS id F0593B82676; Thu, 10 Mar 2022 14:21:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43856C340EB; Thu, 10 Mar 2022 14:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646922076; bh=Rf8d3UZKqR31JRCPZ7eaY38GzuetOV+dpywHxUuB33c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jg2cw7RRVcC+aiSn+SqHZmAdmWbcAgoyEdxB0nNwzHJW4SqNqVsSfeQAn2Vl+fa5I IVoF2Lmrcc5KnH6kzolq9NdvhUyqbHSdn/+553cE0FYG3+1Mtlemfo4Wqchukn+j+H 3htezVYUtfNkx0hKPnSzDihW+sr0ZsgQ5BIlVbHw= 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 4.14 29/31] xen/9p: use alloc/free_pages_exact() Date: Thu, 10 Mar 2022 15:18:42 +0100 Message-Id: <20220310140808.390344695@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310140807.524313448@linuxfoundation.org> References: <20220310140807.524313448@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=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 @@ -301,9 +301,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, - XEN_9PFS_RING_ORDER - - (PAGE_SHIFT - XEN_PAGE_SHIFT)); + free_pages_exact(priv->rings[i].data.in, + 1UL << (XEN_9PFS_RING_ORDER + + XEN_PAGE_SHIFT)); } gnttab_end_foreign_access(priv->rings[i].ref, 0, 0); free_page((unsigned long)priv->rings[i].intf); @@ -341,8 +341,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, - XEN_9PFS_RING_ORDER - (PAGE_SHIFT - XEN_PAGE_SHIFT)); + bytes = alloc_pages_exact(1UL << (XEN_9PFS_RING_ORDER + XEN_PAGE_SHIFT), + GFP_KERNEL | __GFP_ZERO); if (!bytes) { ret = -ENOMEM; goto out; @@ -373,9 +373,7 @@ out: if (bytes) { for (i--; i >= 0; i--) gnttab_end_foreign_access(ring->intf->ref[i], 0, 0); - free_pages((unsigned long)bytes, - XEN_9PFS_RING_ORDER - - (PAGE_SHIFT - XEN_PAGE_SHIFT)); + free_pages_exact(bytes, 1UL << (XEN_9PFS_RING_ORDER + XEN_PAGE_SHIFT)); } gnttab_end_foreign_access(ring->ref, 0, 0); free_page((unsigned long)ring->intf);