From patchwork Thu Aug 27 11:21:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 1352503 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bcgnm0p6bz9sTS for ; Thu, 27 Aug 2020 21:42:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728823AbgH0Llx (ORCPT ); Thu, 27 Aug 2020 07:41:53 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:52428 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728804AbgH0LlP (ORCPT ); Thu, 27 Aug 2020 07:41:15 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3DB081522D01B034F7A2; Thu, 27 Aug 2020 19:23:15 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 27 Aug 2020 19:23:07 +0800 From: Miaohe Lin To: , , , , , , , , , , CC: , , Subject: [PATCH] net: exit immediately when encounter ipv6 fragment in skb_checksum_setup_ipv6() Date: Thu, 27 Aug 2020 07:21:59 -0400 Message-ID: <20200827112159.43242-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org skb_checksum_setup_ipv6() always return -EPROTO if ipv6 packet is fragment. So we should not continue to parse other header type in this case. Also remove unnecessary local variable 'fragment'. Signed-off-by: Miaohe Lin --- net/core/skbuff.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c3496bd8e99e..4dc92290becd 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4894,11 +4894,9 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) u8 nexthdr; unsigned int off; unsigned int len; - bool fragment; bool done; __sum16 *csum; - fragment = false; done = false; off = sizeof(struct ipv6hdr); @@ -4956,8 +4954,11 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) hp = OPT_HDR(struct frag_hdr, skb, off); - if (hp->frag_off & htons(IP6_OFFSET | IP6_MF)) - fragment = true; + /* Exit immediately when encounter ipv6 fragment. */ + if (hp->frag_off & htons(IP6_OFFSET | IP6_MF)) { + err = -EPROTO; + goto out; + } nexthdr = hp->nexthdr; off += sizeof(struct frag_hdr); @@ -4970,8 +4971,7 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) } err = -EPROTO; - - if (!done || fragment) + if (!done) goto out; csum = skb_checksum_setup_ip(skb, nexthdr, off);