Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp168688ybg; Mon, 27 Jul 2020 19:20:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRDHriHKJIa1zLegSXAUi0Di+CXZmLkaicxB61x3ODDWG8jkSecQ4kWDG9RjZjxlZzWsRs X-Received: by 2002:a17:906:65b:: with SMTP id t27mr24664789ejb.457.1595902816407; Mon, 27 Jul 2020 19:20:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595902816; cv=none; d=google.com; s=arc-20160816; b=bHJWOZjkfRn637dTwj7XOnbsSz8yGpMyKLpzdSCDJ/5Y1KTiukg0jrrjAGdK9YfYFK UkJbPiEjFAbSuQfJgLAeISt8DhKqyxIIpZpYpxWlJMzeJyUePbXw5LPylaRBKP5GrQV2 YK5m4QckAb8Vt1EmIAMqXixDomjEuo9LEq3MyMC7sBJ6slIXJoGnmIdigdWyiNIB3E9H PpMF2zY1z0C8tP09WFqN0dFJsLiiHeD5UUReDgeRyuQCV3MbaXwXylzuHkcpxSPAkERR FVqDPo/zr26LmrxDiEHDhL6J2jMBbxV3ibMwkHgW3su4J60EwFdKRpV2PB8Vcb6sIloh sr4g== 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=JDo5Oelgb3vpHDBKk459UoSRDAY9iJsZa204gOV9Gck=; b=HGfLcPb3yh9MwIerlvXDvxjjrpJW3xWiLns5kht2LTn4WpS5fCYzfo1wwtZxLtdqkF 9uoHRoywLNj5MtR9P8TEgEQ9g8KWMVJI8HdSxVbUjomZZgveXRvT2mhC5GBVHTrwKjQ5 H7HDoy4x3qjVquZiPKxBHGruXVguxu5K1IfCMPz+aKmN75Q+SMBqvMVFUffTd3TtxCsS lhRMw1UGHhPE5v/UReDhh+5bRtcLYprodpkAtLPU8g1Z7W3cfdP1/zhhJhBpihDGTVSx NebYXq4XEGx8V1M23JybOZxjZNs9nnXqBScbINvSF/bKDOINy5cX0c2ipHQi/g1lNIip uJhw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nb1si6169659ejb.565.2020.07.27.19.19.53; Mon, 27 Jul 2020 19:20:16 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726989AbgG1CTK (ORCPT + 99 others); Mon, 27 Jul 2020 22:19:10 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8284 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726362AbgG1CTJ (ORCPT ); Mon, 27 Jul 2020 22:19:09 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 827C03F2D34CF3D04A81; Tue, 28 Jul 2020 10:19:07 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 28 Jul 2020 10:18:59 +0800 From: Huazhong Tan To: CC: , , , , , , Yunsheng Lin , Huazhong Tan Subject: [PATCH net 1/5] net: hns3: fix desc filling bug when skb is expanded or lineared Date: Tue, 28 Jul 2020 10:16:48 +0800 Message-ID: <1595902612-12880-2-git-send-email-tanhuazhong@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595902612-12880-1-git-send-email-tanhuazhong@huawei.com> References: <1595902612-12880-1-git-send-email-tanhuazhong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yunsheng Lin The linear and frag data part may be changed when the skb is expanded or lineared in skb_cow_head() or skb_checksum_help(), which is called by hns3_fill_skb_desc(), so the linear len return by skb_headlen() before the calling of hns3_fill_skb_desc() is unreliable. Move hns3_fill_skb_desc() before the calling of skb_headlen() to fix this bug. Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC") Signed-off-by: Yunsheng Lin Signed-off-by: Huazhong Tan --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 33c481d..3328500 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -1093,16 +1093,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv, int k, sizeoflast; dma_addr_t dma; - if (type == DESC_TYPE_SKB) { - struct sk_buff *skb = (struct sk_buff *)priv; - int ret; - - ret = hns3_fill_skb_desc(ring, skb, desc); - if (unlikely(ret < 0)) - return ret; - - dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE); - } else if (type == DESC_TYPE_FRAGLIST_SKB) { + if (type == DESC_TYPE_FRAGLIST_SKB || + type == DESC_TYPE_SKB) { struct sk_buff *skb = (struct sk_buff *)priv; dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE); @@ -1439,6 +1431,10 @@ netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev) next_to_use_head = ring->next_to_use; + ret = hns3_fill_skb_desc(ring, skb, &ring->desc[ring->next_to_use]); + if (unlikely(ret < 0)) + goto fill_err; + ret = hns3_fill_skb_to_desc(ring, skb, DESC_TYPE_SKB); if (unlikely(ret < 0)) goto fill_err; -- 2.7.4