Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp480146pxj; Tue, 18 May 2021 07:39:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtJzwNf+rALCdpXr5Zj28dglJuduRdmOQi8jxxtax94n/uxyvIfrJur2ZTVWKD9Wfx2dT7 X-Received: by 2002:a05:6402:c8:: with SMTP id i8mr7587807edu.57.1621348791304; Tue, 18 May 2021 07:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621348791; cv=none; d=google.com; s=arc-20160816; b=VN4/xdcMmstGRa4Ejkkdhfuk1L7yDvWQ2THi8Ukale9WrAYkY8W8ggH1qAA2YTRwYM /JPMzNJt6EgufreXsJ9WTIzZ8ZE4WnEZUe30dgjQQ6B1SeUPjGgO3rpObKz/RDXuv1SD I1wC2tY+CWmFHaFvBfQzxtkEvAmLS+lJcFqk2CMi9F36vcD7rebX1+SFU/oFm17Dx3kG fyatuO2u6kEpqpzDD3YbDyYvM3t+fKLAxEANBs9x9ghfi2Ns/DsXee9ah8/rAPaHQQbU gNmTNK6u8yVWLGgOgDs31HIjSdKN8nc9dO5IGG+MPGOyx8IeJ/dsG/WSg0b0Yyfnn4Q+ YPSg== 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=HlPnwPhEF1iq+sfHKhAZ/alMs0PiiMckPkHSfs7TpcQ=; b=A01Uv42wanojWus8INNrybtnOfhIL3NMnjp8yhzn75ysLxlreBxyn8Nbu7UWNdiMuB iYvZluHn0LmFSQ/RRpFR5rbcjD5eNV5WIO7vAKp0bUpPWdT9c3Mh3CZtHJihGEsUM5EW FxjLKsNQblXyo8q28n7YAYBygQ3wsLP4096eM/B/KKxOJMUZ7h/9ZsvuOo6otArOCDKv T/i3d+PIGxXdH/acIPKO0k/ZNhFEV52MnmtluQu27Zt3KCS/cmsLxbszZy333av4/MPT +lVXzn65t3GBWKrjTmZhdk13ibimoxhgvva7l1qvVrrOW41lgbBZsCMnnYS645I4qYfi XfcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="tJWLIuB/"; 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 v22si1741227eja.614.2021.05.18.07.39.27; Tue, 18 May 2021 07:39:51 -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="tJWLIuB/"; 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 S245148AbhEQPr3 (ORCPT + 99 others); Mon, 17 May 2021 11:47:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:53994 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244185AbhEQPb4 (ORCPT ); Mon, 17 May 2021 11:31:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 131386141F; Mon, 17 May 2021 14:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262304; bh=iHKtszs9IIlWoFV7+AuVDwDxIjB0taP5A/9EBFJd1V4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tJWLIuB/hvn+SU3vE4nronZnS/T7a2k5TLV9XT8ES6JAWZArBKnXKgwaF4/89Eqyv cmdSfaI6N5yhxHQaQ+fvW0rKfxl8dVKI/wc2FT2Nr0SgkkNHI4Xzfkrux5wv9Zrhlk MXLpGKvzbXrFcDGjPdDG6ukG4oRhbkBEKtpJFIps= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Govindarajulu Varadarajan , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 157/289] ethernet:enic: Fix a use after free bug in enic_hard_start_xmit Date: Mon, 17 May 2021 16:01:22 +0200 Message-Id: <20210517140310.417272734@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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 643001b47adc844ae33510c4bb93c236667008a3 ] In enic_hard_start_xmit, it calls enic_queue_wq_skb(). Inside enic_queue_wq_skb, if some error happens, the skb will be freed by dev_kfree_skb(skb). But the freed skb is still used in skb_tx_timestamp(skb). My patch makes enic_queue_wq_skb() return error and goto spin_unlock() incase of error. The solution is provided by Govind. See https://lkml.org/lkml/2021/4/30/961. Fixes: fb7516d42478e ("enic: add sw timestamp support") Signed-off-by: Lv Yunlong Acked-by: Govindarajulu Varadarajan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/cisco/enic/enic_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c index fb269d587b74..548d8095c0a7 100644 --- a/drivers/net/ethernet/cisco/enic/enic_main.c +++ b/drivers/net/ethernet/cisco/enic/enic_main.c @@ -768,7 +768,7 @@ static inline int enic_queue_wq_skb_encap(struct enic *enic, struct vnic_wq *wq, return err; } -static inline void enic_queue_wq_skb(struct enic *enic, +static inline int enic_queue_wq_skb(struct enic *enic, struct vnic_wq *wq, struct sk_buff *skb) { unsigned int mss = skb_shinfo(skb)->gso_size; @@ -814,6 +814,7 @@ static inline void enic_queue_wq_skb(struct enic *enic, wq->to_use = buf->next; dev_kfree_skb(skb); } + return err; } /* netif_tx_lock held, process context with BHs disabled, or BH */ @@ -857,7 +858,8 @@ static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb, return NETDEV_TX_BUSY; } - enic_queue_wq_skb(enic, wq, skb); + if (enic_queue_wq_skb(enic, wq, skb)) + goto error; if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS) netif_tx_stop_queue(txq); @@ -865,6 +867,7 @@ static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb, if (!netdev_xmit_more() || netif_xmit_stopped(txq)) vnic_wq_doorbell(wq); +error: spin_unlock(&enic->wq_lock[txq_map]); return NETDEV_TX_OK; -- 2.30.2