Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp453037pxj; Thu, 20 May 2021 13:17:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwf2EZt4HDnBWlSTP1PWyKJIoR94TK0mGa4Z235/GxnH1NTJhB3TdWyP/SjPjcMtEIugIzG X-Received: by 2002:a92:c54a:: with SMTP id a10mr3163189ilj.140.1621541862377; Thu, 20 May 2021 13:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621541862; cv=none; d=google.com; s=arc-20160816; b=n5GMCEL8NhxXkLfVo9afLcL8v6SDHhdFjVUm1heG626eJRFtZa+oHRY9v19jM9X9iN LaeSanoaLiV8GEJ5RuMKt8L2GOIluOP/TxcjBudcZbpnsb9FVS3TqpS0fgF1E3Y6FBYe 1yxCj29FSB2bsM3nXjxO0onqMqFim1HgBBd0afDBDMiZZNH5vWsUNfLCjI5q9paznbkX t/fWxh0oDLenoP8O+MP/EfN+ThcVdZweGjf2dFr0OPvz1NrJoNrN8oCGbQsnvr9kmGVE t1xVtZL1IiOEBXeAwR8iIC4iQymNNmTjpIdcrT9nqJOaN3p/GDFXlwZzdWZGfx+y64/Z 397Q== 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=nJrXr/MaaG2wc09iM49Qje+i9wmFpUcUu7vuu8GkYco=; b=BlRFCvxv1e1iSeqfJ9UdtQOM1O4C/AxLivh76Eecv8VumU0CaMfsCCwBtr/1zp46gL 4LlVZwgC+7IknHW+yG47BFNLRNXlaO9yY0V3jXNCekaSTLqWCr2OiwjMOyHPyvm6aOnN liw/mTtevpweUW1ex31/NhFBRbT3s7po9FLLh9fsElLg4wfKOegrF2XnOVAOI2FznrlK 8CWlawSX1owgCeVhQTStw6EYojLTJvITBdfwtVeU6BnPAXOLsTBo/KZM6tCcUQRuB491 52vROeaBd3CUyHOen13OH74upPWXanXiME3cN9J5HzBebv9mwAkK9I/LYMpeaWe9xfKJ RErg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YadODJ8j; 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 g8si3507935ilk.127.2021.05.20.13.17.28; Thu, 20 May 2021 13:17:42 -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=YadODJ8j; 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 S238756AbhETKuQ (ORCPT + 99 others); Thu, 20 May 2021 06:50:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:33278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237405AbhETKeQ (ORCPT ); Thu, 20 May 2021 06:34:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 73C5661C4E; Thu, 20 May 2021 09:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504393; bh=+kLHwROEIgv5ph2zdEqrUmAQL6AVz54tVtpSmP3VTkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YadODJ8jKVMx5Rqz3ngOUmaRxS/RbXXsaDkl2kXSY8HlwIp4JscdNjnptNOG9TYjw tA+9oMqLKF1KdCiCmCu041dzb09CbWVAnOzi+/Q+wQZvmkhnN73b5YvbL6RfgAgt8b SrwDVel/D+yi4Wr7o2EYYUeDPsTTJIdpAicxXiGU= 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 4.14 225/323] net:emac/emac-mac: Fix a use after free in emac_mac_tx_buf_send Date: Thu, 20 May 2021 11:21:57 +0200 Message-Id: <20210520092127.854814690@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 44f797ab5d15..57f509a6c449 100644 --- a/drivers/net/ethernet/qualcomm/emac/emac-mac.c +++ b/drivers/net/ethernet/qualcomm/emac/emac-mac.c @@ -1458,6 +1458,7 @@ int emac_mac_tx_buf_send(struct emac_adapter *adpt, struct emac_tx_queue *tx_q, { struct emac_tpd tpd; u32 prod_idx; + int len; memset(&tpd, 0, sizeof(tpd)); @@ -1477,9 +1478,10 @@ int emac_mac_tx_buf_send(struct emac_adapter *adpt, struct emac_tx_queue *tx_q, 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