Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4754529pxj; Wed, 12 May 2021 12:28:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypU9pUpqW+Jci1wzEKc9UH8mTeLDngoU8dGzKIZY221nr/gKCQfmXiVtoHXT9ubsJRmi6G X-Received: by 2002:a17:906:7f8e:: with SMTP id f14mr22127128ejr.510.1620847727957; Wed, 12 May 2021 12:28:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620847727; cv=none; d=google.com; s=arc-20160816; b=iVoC/ecDNSorQWJg6PcSJzoNI7nF+5l35WJhpZNLZFxEn4w3zmpwFCayxlnRd8UW7T q2fDVeeavqjMjDg4ecBIF/7bdBLCREZmrO04XpAjMuJW8+xt37nhmYui88q+QCAjEnHi Q+5D2UTjgtvde0Lz7rZ5lD56mIi3HHn1LG3g+JyH4pXCFz5I2ifGmpPEBM/VkdhTjyOK S0mfs1/a9+oDfcxrPB8BOwmvCqSNspveRUaJMbUO96eeqi5tlUYC9HK70Z4aziKXisA5 usVPV10mxFPNZ8VCEL07I0BBHzcV46ZwJFfidn67IV1u1cNClVYQ/HzoLayIWs3m4hQL QijA== 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=mpPhRavMWHDWL+0iLaRDJpE8qO7Y0ZIn6Z7iYFVWKfw=; b=s0trM12SJJVO2ArbaYebDZSND0E4N3VEwZt6G8IZE888GJk4QPr0s4ji+GuQG7GCs+ ThljzG+dIoGUs7zWyEVr5gjF6QBpB84Q7qLAAj21CyblpfiMppic9OcwhMBRBMjXGFXe BgbNdUSiDJD51YOmBUbOs7RNrvL3xFfDvL5IlpReQaQmFAIUKYEB2LziEEWRaauBG17l gsBO7zEsb8pL0Rbqy7OlPPP4JiOyvzvjFdv6NzDfs5zgyTe+48YV1PgwD21/a94AIpiP 9MwgDGlVEmWd7RqnvwpXNKVcQglIculJ4Sr0s9C70xRyGVMdA/9Ipque1pM7+6AK25y5 xNIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="GkFq/6WA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ze15si622012ejb.113.2021.05.12.12.28.23; Wed, 12 May 2021 12:28:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="GkFq/6WA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379316AbhELTTV (ORCPT + 99 others); Wed, 12 May 2021 15:19:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:46966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242846AbhELQuZ (ORCPT ); Wed, 12 May 2021 12:50:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 687AB61D54; Wed, 12 May 2021 16:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620836196; bh=n+AlIZTnt6xoCymPDcnfpVGdh1ubkYkDSmHe4NPqy7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GkFq/6WAWUFjsKcUESFhtrRGj8Hzg6TVouKF+lA6PWNogBf9d3cRGfKVVgTTXwand DMUXCi5QFnzWyR2eRJFXDat0sqhpJaj85OWgSpkl6E8GZEzjKmMnc8qTM/B4IrPydN oknadWKplS/QvWPSrm7R3PcOExb5sSrXt3LXVP7c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , "David S. Miller" , Sasha Levin Subject: [PATCH 5.12 650/677] net:emac/emac-mac: Fix a use after free in emac_mac_tx_buf_send Date: Wed, 12 May 2021 16:51:36 +0200 Message-Id: <20210512144858.965236950@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lv Yunlong [ Upstream commit 6d72e7c767acbbdd44ebc7d89c6690b405b32b57 ] In emac_mac_tx_buf_send, it calls emac_tx_fill_tpd(..,skb,..). If some error happens in emac_tx_fill_tpd(), the skb will be freed via dev_kfree_skb(skb) in error branch of emac_tx_fill_tpd(). But the freed skb is still used via skb->len by netdev_sent_queue(,skb->len). As i observed that emac_tx_fill_tpd() haven't modified the value of skb->len, thus my patch assigns skb->len to 'len' before the possible free and use 'len' instead of skb->len later. Fixes: b9b17debc69d2 ("net: emac: emac gigabit ethernet controller driver") Signed-off-by: Lv Yunlong Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/qualcomm/emac/emac-mac.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/qualcomm/emac/emac-mac.c b/drivers/net/ethernet/qualcomm/emac/emac-mac.c index 117188e3c7de..87b8c032195d 100644 --- a/drivers/net/ethernet/qualcomm/emac/emac-mac.c +++ b/drivers/net/ethernet/qualcomm/emac/emac-mac.c @@ -1437,6 +1437,7 @@ netdev_tx_t emac_mac_tx_buf_send(struct emac_adapter *adpt, { struct emac_tpd tpd; u32 prod_idx; + int len; memset(&tpd, 0, sizeof(tpd)); @@ -1456,9 +1457,10 @@ netdev_tx_t emac_mac_tx_buf_send(struct emac_adapter *adpt, if (skb_network_offset(skb) != ETH_HLEN) TPD_TYP_SET(&tpd, 1); + len = skb->len; emac_tx_fill_tpd(adpt, tx_q, skb, &tpd); - netdev_sent_queue(adpt->netdev, skb->len); + netdev_sent_queue(adpt->netdev, len); /* Make sure the are enough free descriptors to hold one * maximum-sized SKB. We need one desc for each fragment, -- 2.30.2