Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3080859pxj; Mon, 17 May 2021 17:16:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxV64Q3bDGBd+bwRK1Vq585P6gobaQmyHiHDlsXboFBNnivm9Sphez/S5P+Shrr+e1wVzLa X-Received: by 2002:a05:6402:203c:: with SMTP id ay28mr3410531edb.100.1621297008868; Mon, 17 May 2021 17:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621297008; cv=none; d=google.com; s=arc-20160816; b=xStxOcyjgc/cRSXUfyUG+fkt7anb5vwtB9B+5JLRPEiQaDUaq0Pl45SDO7p7K19Ls1 wVfnyfJ/VwCKqySf+3+9y+4i6mAkkfQ5zimySyYE2sDxgEQclSz7DP6DF9addpVpOVtX 8mVZoaH9fpdhnNTKVPqtNye3TzQO76/Glh0egRQWQwLUNyLrdaCa9cmjK8xFuXC+PtT4 zv+on/W4C9e0LIOLEmYZyDfZFAKMiu07RtF76adkJSOsNtDS4IaNgO9dtfU6/+mW412u xJtytpWLw8DSdCPE0ojls1duzpA+zfrRJHVvfMyqmY2ygpK158m5TbkiZ7E+KSEbNa4O W4/g== 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=WC3TvTH8FfvI7TCzgLVmpSFGeVtgKf3s9tMkxb8widA=; b=KF3AtimqpNz7TrTocKXIxIj6/nWlwbTxhDyMg1dyl6tEZ3/6L5hDF/oXreqT0J8f7r cyTGcfEoRyydAlaHTXNxyXQlDMD/ETV9eJF+/bAIpJ/l3t8AawfM8tjvJsmInERfw18i K5zzBgBCvkFfGUxqc+Ot9qO3zn8PD7fnckyr1n2EEFDVonY1yCLtl9ZirV3M8sAUfg0G h8HoWD4JyhDNCXuIkywT5OLVZh3BGxIGm93+Fvhk48UadFYi8gBAjC6vJ43/wiVGxCe1 uNxevb5oUFDd8GmW9mCJaT5onJqHGOnlhioiQovJT1og9EFWmaDgsycSXbnDIEbQvCA7 pNNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Sw6NaOs9; 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 gn24si16533026ejc.674.2021.05.17.17.16.25; Mon, 17 May 2021 17:16:48 -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=Sw6NaOs9; 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 S237556AbhEQO0A (ORCPT + 99 others); Mon, 17 May 2021 10:26:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:35960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239218AbhEQOW0 (ORCPT ); Mon, 17 May 2021 10:22:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A5955613AA; Mon, 17 May 2021 14:11:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260717; bh=AC16IW192HrSBsgpdXfcmar38kp7AyGLt094U3qEL14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sw6NaOs9XCuAuKe6dxtvChSKf0wDoR6ZV+VE+zgNXjnuyiVc+Ps8OJ3I6WkwY3C+W UxLBi31Brdun2EL/1Q1egL3hlcgB8dQ9OdbkJ72RYPA0xNiQM2E+lcWS5IzgHUeNn3 5JHoPrxhioLrca9y925g2to8HaQNSgLd78BJ1vHw= 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.12 207/363] ethernet:enic: Fix a use after free bug in enic_hard_start_xmit Date: Mon, 17 May 2021 16:01:13 +0200 Message-Id: <20210517140309.581930719@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 f04ec53544ae..b1443ff439de 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