Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp373530pxj; Thu, 20 May 2021 11:17:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeSQ4NT743WriqWLw0P1CzBgzFnsId90kM1INJ67lBQSbBoZ/RrNVhZxCedPowOo8HxZjq X-Received: by 2002:a05:6602:2218:: with SMTP id n24mr6496981ion.87.1621534640711; Thu, 20 May 2021 11:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621534640; cv=none; d=google.com; s=arc-20160816; b=Z92opAIkGXxVRgyIV9h6gJi1GjpyCtCvwWwxhFRh1s6j0F0hzpEiodbIqD5guOxCdA 7nZm3b6TEw16+8zxzcnhzbvCmfIVCTpgSRMQIWJlFi6BeT03ZgihXH0aAp6Zk0QnBaDt Gc6yghi5uJ0cyI8HuQy3UDj+nGW0CCK71b80VEgSqQkA5FTT2kTcIl6de4T8mFeGuE8l UBe6HTf2+FrcJb81PO6PFxmd3wUMmxCd9WEWS3CzKFM8R2IT1LAaJOV+3RMQ3CbZBcpN V6z1/5xiowN8B5VfVtzeYR17tGGthqD5ecrLyIc40661N+5mOTgWlsYKR2kZwzpuk6eh fucQ== 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=cMZ+CgJXwhn1gtY59iRQyWrbQe1qP416Hrk7B1VYSS0=; b=vfEmwWfjW4Di0mLlNtXXadpRbfU+aksQ3E+J81F6EST682eXkBkhQsUihTurSrYMVm LDL7wLXWYW4RQXWqyS3ytfhJfW2ggSC5mkycjimu7WTv2CAdpkcxMdIvppiA4Dj+U3Nm TL41cLj0nf4/kRTAbQTysudHxgb32y3hL6p9iquwaG+TkVqpHnBanxTzfZglpjmGhVKr IpePDYZqrRfQQnd4JNzNuziN3nk2oONYd67KtoY+uG7CaxxmCu4wYjgG772bj2oNnUn9 VqWjH0nTMgFJqwEUreSkVWFELxfVOg0aWRTHGrk25zaLM2jcQqvfki8538nsb7+j80EA x9iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mFHXpMP4; 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 x11si2816148iov.17.2021.05.20.11.17.06; Thu, 20 May 2021 11:17:20 -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=mFHXpMP4; 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 S236334AbhETKPC (ORCPT + 99 others); Thu, 20 May 2021 06:15:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:42436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235616AbhETKHb (ORCPT ); Thu, 20 May 2021 06:07:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 04D5961948; Thu, 20 May 2021 09:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503716; bh=EJkPYekfLXg5uWBlav4/0Gz/XOpaVL1M3WwM/Ixm8j0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mFHXpMP4UEQt/Sxg5onLA9GCGg5y4onvlnS+NFsexn49mUGy7YSf8YfCCAnjDzDZP trlWgHa3c0cMPJmXOp2wA2WSD2gtdDZ9GywJPKM5Pwd+1CNiW28CRtLPaCb73ZuEa3 UMvjdAQylg8rfQJPAbBD/fUzmRNNUtqK3O3xJBfc= 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 4.19 347/425] ethernet:enic: Fix a use after free bug in enic_hard_start_xmit Date: Thu, 20 May 2021 11:21:56 +0200 Message-Id: <20210520092142.813237798@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 810cbe221046..bfe0e820956c 100644 --- a/drivers/net/ethernet/cisco/enic/enic_main.c +++ b/drivers/net/ethernet/cisco/enic/enic_main.c @@ -803,7 +803,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; @@ -849,6 +849,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 */ @@ -892,7 +893,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); @@ -900,6 +902,7 @@ static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb, if (!skb->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