Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp987314yba; Thu, 4 Apr 2019 01:49:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyymG4LuFIfolsCU+spu0nBWky4iw2ErOUB8YQIgxkyw9LEABRRUBzEU6LfE33+XR32ugSt X-Received: by 2002:a17:902:ba88:: with SMTP id k8mr5181806pls.268.1554367770934; Thu, 04 Apr 2019 01:49:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554367770; cv=none; d=google.com; s=arc-20160816; b=wAGDoEYt50u80eAD/CqvhRwEANOr8OiPIWsSNI8gXv7NZNzFIvbca0FPhKMwB6Zj6X +jTU4J68veaWWOylGm4kcidbESmmgk1iTNp2o01MnOyNvQOMh1d+D/0ktGUIPA5oqWSo PRhKjWCldOumdqJbXsrvBmDJsdBIgFZ9qcmzWeqVOIDYM/L+9gzafMAunbUjhSxlIiG/ ohijjbAAvecfjN1lY8vd3y+VqR6wnxFlHy1uLdTCt72LqA8HNW1sbcoQMr8EdwE1jRyU PxJ+U0oXqce0/K+4tfkUf9leE8QpM+pQ8TrM9a4o+Fb31GGTInhZ03VbF1JkcY423ZST 60Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Qx4REFVTXXqbNNogYz5Tf0w79X5e/+HwS0lUfsggOHw=; b=JmheYFjvymxNgpz6UuIED8ca9MZulxzEhrftTQ9/jfK+2g/X5kDIcpkkc6qWiIgLRb yr0t5E2311qnXoLcmqREJedOYiR/cDvXWs+AqnsHmgGxJm+x/N6mdV4fEBulNV6VfuNe /TaF8zRVD8t9npvyWmCNeXeSHDWPhBr5dkO3TCcmEC7CUbbwI01xJRU0D/pBYZ5J2+0z Gentt1xLBGBUoCun/LmgPXWZZ9WLtWu7J5T3I+E9WcMUCb5vD5cbxWzsmAzpStnnCJjw 4cLm4cjfwFVDJk8lO4rThfA2GtkT+hE6h2tHsuPOQ2F4vQjXZ45ymPGJ7NBhmHXpsxPt eDHg== ARC-Authentication-Results: i=1; mx.google.com; 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 y13si15979587plp.238.2019.04.04.01.49.16; Thu, 04 Apr 2019 01:49:30 -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; 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 S1728758AbfDDIrP (ORCPT + 99 others); Thu, 4 Apr 2019 04:47:15 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6248 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728672AbfDDIrH (ORCPT ); Thu, 4 Apr 2019 04:47:07 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B790CF2E92CE66AB8C37; Thu, 4 Apr 2019 16:47:03 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.408.0; Thu, 4 Apr 2019 16:46:53 +0800 From: Yonglong Liu To: CC: , , , , , Subject: [PATCH net 1/6] net: hns: fix KASAN: use-after-free in hns_nic_net_xmit_hw() Date: Thu, 4 Apr 2019 16:46:42 +0800 Message-ID: <1554367607-130891-2-git-send-email-liuyonglong@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1554367607-130891-1-git-send-email-liuyonglong@huawei.com> References: <1554367607-130891-1-git-send-email-liuyonglong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liubin Shu 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 --- 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 60e7d7a..e5a7c07 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.8.1