Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4631517pxj; Wed, 12 May 2021 09:38:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+x5OU0LHFraLcYxphCC5NvON+OxPzUAJEVJU9nqqhkaasrQ4MpT9VGmDV3U3CK1AnZZDX X-Received: by 2002:ac2:4216:: with SMTP id y22mr26036269lfh.422.1620837496126; Wed, 12 May 2021 09:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837496; cv=none; d=google.com; s=arc-20160816; b=ZFpQhiK+3sZib4gh5ujI3YLRtJK7uup9r5zcXbs3m82hpHN4ULL12bKBaKooRDjjo8 oHD0BUsrajnYWuK3JN2N97X9wno642BgkUmp3azK48YOoyklPqojxI5ryEFcjg0117Bv cx+3zSY1tQPziekJuxKmNhydE1qZBhi7DcB7dt9zV90NA3f+tL0I4pfNVarB8LALCCUD IwUE0+upaNHX4nQmQ7bFVEYTBfM4QXwtrHUIXpJxMz8d6nNRzE5v1DzdgPBdL5h7ZxSy V+XsXjuEvYn/Vu7lbw4FscUEyvIuy1qa4zINzbbkS/UKau17woaCcb09+ncYMjaK72cT bBpA== 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=ThA6lsXKNDzDt4Qon8OkwEjSgwoXwUP38r9JpGuEGDmvGUHUjPGu5heLINNVTGOlt3 h/oGseH2eVMqNDNSreoow5tOayVtjcAGzRxqQcj/zVSfijM1CsoG7qXMH+bGjhOaqT76 Bls/YJeoGh1tzU3iU5EGLNLP1kY1SEpDc++dqo0nCynm4KAcquqHjRCjCtRxa0n4rMkx yq8egnMTHi0m9M3W3KGKxYvfRJp3eYjSPmroGvG+mdqCTzelw32J+p+EcIIRnsBaNwd6 XL51FgMbF1xHaw2fmlOtukqO0w3wvEWZ7fcHx6siKsL7aAQ1dw8q1cLQKYhi7rKh10FV HA2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BK6hsVCZ; 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 y11si323251ljc.371.2021.05.12.09.37.43; Wed, 12 May 2021 09:38:16 -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=BK6hsVCZ; 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 S243194AbhELQg5 (ORCPT + 99 others); Wed, 12 May 2021 12:36:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:41718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235567AbhELPpM (ORCPT ); Wed, 12 May 2021 11:45:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C8B061C95; Wed, 12 May 2021 15:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832987; bh=n+AlIZTnt6xoCymPDcnfpVGdh1ubkYkDSmHe4NPqy7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BK6hsVCZwgDCcBMXrf01E66ruUwIpvtnnGraZgJ/6p9yf0WxudkFz2pZfbOkymugU pgJ39dCxZYOZMl8F1oZOXBJAt3+qVWczFpTO4XdP8HboU6FyyMNUcFAnexY7yW5FSQ bTHTYYuzSiJy2DzUIDbcZMf9udurY9nzm/7jEaho= 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.10 503/530] net:emac/emac-mac: Fix a use after free in emac_mac_tx_buf_send Date: Wed, 12 May 2021 16:50:13 +0200 Message-Id: <20210512144836.283805541@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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