Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp811882rwb; Mon, 26 Sep 2022 06:14:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72st0bcXHf6Vx9NWuoP5XIO6w5En2FzgWWPjmhoPVjg6+KPYV3Za9zMhVPbkvqqe+CxLna X-Received: by 2002:a17:902:9f90:b0:178:1a1c:85d with SMTP id g16-20020a1709029f9000b001781a1c085dmr21872354plq.85.1664198062284; Mon, 26 Sep 2022 06:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198062; cv=none; d=google.com; s=arc-20160816; b=PlYHeeR0FSmoCGBjQ3IJn/PyYeoNl5S3Wyi4vAPwIQjVStsGpjgnwDrG7Fks6I83av mzwMV6bPiKyWdOKcWXmYMEqO7fSGnCOLLiOjVmhtRywitkckrgZyjXhQVERDMEuoxrY2 ChvRMeYpKiAci+hZcn7AomaJ1YlgDrwV1FaaopfjR5nJV72OTRYVcCqvURPlVVg/ai8u OHMs9pM45rjmF//bK5nUBuhigEvLz27KYfzaVn6pu1SzBCuUzs7J8EPmZD0tF0pw1j+m X/4HgLBg/y2TI8sCU+IFovGchOFu3B6YhCBp5onuMiT/97HG8SusoL2kbySrbBEwT9iY 241g== 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=ctaFpSGRSvwWabUPrCrfp+wvwju95MymXXUqdJNe6Vg=; b=uwgjODm1j/au6AKBOInX/OsIpW6YZeM/H9gs4dWE3i37YBX4I2eBIlvdqvtCs1g5OI P6g96hIDz4b6GgbLIv/XhIQJpsD2zbJdErC6EEQ02eNsslGEemH1vli5ZNHbsGc9vu8r tpXukephu1OjEZpNY6Sn1rPWeiZhkq8QOkipCB+caRujFue4kKsIx+pWXp2TakQh+JeU Nu94xFiDifak1P1E+eFSvUq7GFyNEi3iGpGW6Ci8jkNiw5nWc2Hsrcf4oq1fWDp3GnSO h2rMxdf/GtN9+IU1I+WQ8Lc1UrTdh8gNtKB6jhoCV4HZl+hC7Oe3sxnuWTEjb1BcejQF 1FvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=REkQDGtE; 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 n7-20020a170902d2c700b0017555e9de54si11785897plc.427.2022.09.26.06.14.10; Mon, 26 Sep 2022 06:14:22 -0700 (PDT) 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=REkQDGtE; 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 S237951AbiIZL1G (ORCPT + 99 others); Mon, 26 Sep 2022 07:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233879AbiIZL0X (ORCPT ); Mon, 26 Sep 2022 07:26:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE6D46211; Mon, 26 Sep 2022 03:40:46 -0700 (PDT) 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 D6BDAB80883; Mon, 26 Sep 2022 10:39:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26018C433D7; Mon, 26 Sep 2022 10:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188772; bh=5pLLS9Urf5bHg4CbM0144OhQE+ORH192FwdqClHUpsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=REkQDGtEeInPdYZ1DF4NDRBYWqZY4XYTOOC3R3IUl9EYGoVp3S3clVCrrjXruth+V FUUKWM29ef634gaBFohvdDqiRapdGJJ/KxDuhU4ztsAiDDRkcz3PXbkDlegkE9cAnv SFgoMDHjkq09SOpV8S6Q3Om5O/YqyPZfj+JewM10= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Gospodarek , Michael Chan , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 115/148] bnxt: prevent skb UAF after handing over to PTP worker Date: Mon, 26 Sep 2022 12:12:29 +0200 Message-Id: <20220926100800.446331604@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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 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: Jakub Kicinski [ Upstream commit c31f26c8f69f776759cbbdfb38e40ea91aa0dd65 ] When reading the timestamp is required bnxt_tx_int() hands over the ownership of the completed skb to the PTP worker. The skb should not be used afterwards, as the worker may run before the rest of our code and free the skb, leading to a use-after-free. Since dev_kfree_skb_any() accepts NULL make the loss of ownership more obvious and set skb to NULL. Fixes: 83bb623c968e ("bnxt_en: Transmit and retrieve packet timestamps") Reviewed-by: Andy Gospodarek Reviewed-by: Michael Chan Link: https://lore.kernel.org/r/20220921201005.335390-1-kuba@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 6962abe2358b..a6ca7ba5276c 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -709,7 +709,6 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts) for (i = 0; i < nr_pkts; i++) { struct bnxt_sw_tx_bd *tx_buf; - bool compl_deferred = false; struct sk_buff *skb; int j, last; @@ -718,6 +717,8 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts) skb = tx_buf->skb; tx_buf->skb = NULL; + tx_bytes += skb->len; + if (tx_buf->is_push) { tx_buf->is_push = 0; goto next_tx_int; @@ -738,8 +739,9 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts) } if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { if (bp->flags & BNXT_FLAG_CHIP_P5) { + /* PTP worker takes ownership of the skb */ if (!bnxt_get_tx_ts_p5(bp, skb)) - compl_deferred = true; + skb = NULL; else atomic_inc(&bp->ptp_cfg->tx_avail); } @@ -748,9 +750,7 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts) next_tx_int: cons = NEXT_TX(cons); - tx_bytes += skb->len; - if (!compl_deferred) - dev_kfree_skb_any(skb); + dev_kfree_skb_any(skb); } netdev_tx_completed_queue(txq, nr_pkts, tx_bytes); -- 2.35.1