Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2536410yba; Mon, 6 May 2019 07:39:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIcxrNjSmcWnzCYFRz1k3tu/pr+5qX31KGOnDCNTFWyBI4BdBCJbwnBOksMt+T2JKDK3Sx X-Received: by 2002:a17:902:b782:: with SMTP id e2mr10297103pls.228.1557153585591; Mon, 06 May 2019 07:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557153585; cv=none; d=google.com; s=arc-20160816; b=kXZYJhh1ky2Md3pCkH4uhaI8eJ+elc7jtEENv4oJpW23wut8HF6lDF8r9uP7Of3Qic KJPXA4M+o5tRhnhF3QiobiBARtCqji2Ybca6a+thhEVDEMJZTQkmrTa8Uhow24sUMg3A Axtt+l/W/IpNHbzJiGZJQ/FSFG+8qsTrNAG6f7AVEMTqq9NLcIYpphLFbIqMygS8hR5o cn2oG7Z03wplM0GkXgWh2EQxzLKKwfoSqRYRgO1kiDuhyG47yManTDVSryxjrXOl7yKd nOSiQGCFrtmwsoGjqDypyhuUuaoHVhRjKSJ6ciT4EYphP/cC0dFfNzdsLXLd7Po0XtcX fu2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r4OE9lpMe41k2KuCvcVOjwk2oQX3vXOB7h86dymbXH4=; b=Kn2SvByNAAEXyIE0MoqIOfm4LvLbsokaBwob0ECBNCjDTuzjKd14WmmGEp74RAlCV6 6/xsYbd8ZwaGPBCupqpz0UcDK13elAnT1ixoA9Bv5l0A6XTpq8HFzcXV11osPml/8hA2 y5k0Pf33QzfgUz1/biVqQCj8YySX+KvLYc5hlx9zwWMYfxV8n6RB8PYrt3GHR5udIgdR mreyMC+fluJRzpYxIj1dnfWpl4hI/GfbspotiNjBnolwkVvwkF1qd3Kea61xBax2gEA0 nzO4Uex9iDixU/d94nAw9p1dPiwVxL1JrydWFRkYoGW9CEUJ/n2ZGwVwJ6e2Ao6n5nyq i45g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c5aDIOiE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 142si15848651pfu.129.2019.05.06.07.39.29; Mon, 06 May 2019 07:39:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c5aDIOiE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727170AbfEFOg2 (ORCPT + 99 others); Mon, 6 May 2019 10:36:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:56754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727140AbfEFOgY (ORCPT ); Mon, 6 May 2019 10:36:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50A5D204EC; Mon, 6 May 2019 14:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153383; bh=kYdkehRzot1GFxvAqo7mGmhZMsdT2QYXRUSv1Iyes1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c5aDIOiEleIIDqFUwbEiTd+cUXSpJ3Q5Iujfv/kxclqWmoT1nBbcQkYr9PJQkSD1L +1MMWyW0DVt/ZcXPKFx5DB+k6JbAmqFQVGhLc5XAgvesBYvRyqQGRsCC1egRfRp7Mc +xSzFLilRLytmWRyEh0zYEU4eiTMKtBXtSehaOuk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liubin Shu , Zhen Lei , Yonglong Liu , Peng Li , "David S. Miller" , "Sasha Levin (Microsoft)" Subject: [PATCH 5.0 068/122] net: hns: fix KASAN: use-after-free in hns_nic_net_xmit_hw() Date: Mon, 6 May 2019 16:32:06 +0200 Message-Id: <20190506143101.081622139@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 3a39a12ad364a9acd1038ba8da67cd8430f30de4 ] This patch is trying to fix the issue due to: [27237.844750] BUG: KASAN: use-after-free in hns_nic_net_xmit_hw+0x708/0xa18[hns_enet_drv] After hnae_queue_xmit() in hns_nic_net_xmit_hw(), can be interrupted by interruptions, and than call hns_nic_tx_poll_one() to handle the new packets, and free the skb. So, when turn back to hns_nic_net_xmit_hw(), calling skb->len will cause use-after-free. This patch update tx ring statistics in hns_nic_tx_poll_one() to fix the bug. Signed-off-by: Liubin Shu Signed-off-by: Zhen Lei Signed-off-by: Yonglong Liu Signed-off-by: Peng Li Signed-off-by: David S. Miller Signed-off-by: Sasha Levin (Microsoft) --- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c index 60e7d7ae3787..e5a7c0761dbd 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c @@ -376,8 +376,6 @@ netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev, wmb(); /* commit all data before submit */ assert(skb->queue_mapping < priv->ae_handle->q_num); hnae_queue_xmit(priv->ae_handle->qs[skb->queue_mapping], buf_num); - ring->stats.tx_pkts++; - ring->stats.tx_bytes += skb->len; return NETDEV_TX_OK; @@ -999,6 +997,9 @@ static int hns_nic_tx_poll_one(struct hns_nic_ring_data *ring_data, /* issue prefetch for next Tx descriptor */ prefetch(&ring->desc_cb[ring->next_to_clean]); } + /* update tx ring statistics. */ + ring->stats.tx_pkts += pkts; + ring->stats.tx_bytes += bytes; NETIF_TX_UNLOCK(ring); -- 2.20.1