Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp1929817ybd; Sun, 23 Jun 2019 20:20:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTTlWWaexk9rCJjcEXSBW+qmHQGJOT8LJ3e7FoCT2hG7+GN1FlZiXJ965mpSxUEiexOQAn X-Received: by 2002:a63:dd53:: with SMTP id g19mr29554674pgj.3.1561346453359; Sun, 23 Jun 2019 20:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561346453; cv=none; d=google.com; s=arc-20160816; b=LPAlO1r8MiAcVxv1pvjyKocyAa8z+yzWivp1MD4ESr8bZ58NBVh5bVtMQMgd2jVfuF B2VvyYDQOHxCqqJIqifukCpbpKsG85pyMzKgDuJDaqmJuvSm8b+ZZMdSSrSpliwAvAQG KvS7j/DvRm9giblAUdkxLA3uXwuPhxs2JB0A+LFbKHZ9/9KycKKmVG9yHSinPA8EBJPl 19Uj6PqsHL5+M5QFkWxAHMGbShq03AGb++DVFLehbw/82T2LjKNszAsr7r8pQ9F2gu7q Xn48moROg+8EV7ezglx1YKzrnwC/KqdzVxUQTrsnwau/oupvEoOBMqfYkMkgIp9X4vNL oi9Q== 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 :message-id:date:subject:to:from; bh=gvXWN2eJD9RFtbcirZucBmZs4tGWfYHYqc6PZCkoovM=; b=nkVCZa9KZ51P+GZfNLJN4Y+aKg9dkYdDkZuiTPO5MJ6IIsr2aYhFnc+joQIHdaXXlj 9frsrYst/iuRncjceDd8Fa7Qqd4HUwTf8zO8mKZ0xS5iorjRyGpMlELFcRiWGpFDUMVf IkEYas5X3aIAhXF5EmGelL2YWgHLzor1bsd6OI0Pk3fJt2C97wqpRBnCpec4CrjWruvF 2qYrZsajywSCKgTFv0Lzuyu7HXJRS9R9Biabp/xiLoUat424mM5U9wLQNUrnHT58SART 3WCG48mILCRz3OSfTb/Jst1NR1GF5zKhcvodoVU61Ew+yTe+3aA8NhdXhEWsBOhGRNTW pfZA== 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 q18si9018288pgv.456.2019.06.23.20.20.37; Sun, 23 Jun 2019 20:20:53 -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 S1727536AbfFXDTl (ORCPT + 99 others); Sun, 23 Jun 2019 23:19:41 -0400 Received: from mail5.windriver.com ([192.103.53.11]:41682 "EHLO mail5.wrs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbfFXDTl (ORCPT ); Sun, 23 Jun 2019 23:19:41 -0400 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id x5O3HmLU005347 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Sun, 23 Jun 2019 20:18:03 -0700 Received: from pek-lpg-core2.corp.ad.wrs.com (128.224.153.41) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.439.0; Sun, 23 Jun 2019 20:17:41 -0700 From: To: , , , , , , , , Subject: [PATCH] netfilter: Fix remainder of pseudo-header protocol 0 Date: Mon, 24 Jun 2019 11:17:38 +0800 Message-ID: <1561346258-272481-1-git-send-email-zhe.he@windriver.com> X-Mailer: git-send-email 2.7.4 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 From: He Zhe Since v5.1-rc1, some types of packets do not get unreachable reply with the following iptables setting. Fox example, $ iptables -A INPUT -p icmp --icmp-type 8 -j REJECT $ ping 127.0.0.1 -c 1 PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. — 127.0.0.1 ping statistics — 1 packets transmitted, 0 received, 100% packet loss, time 0ms We should have got the following reply from command line, but we did not. From 127.0.0.1 icmp_seq=1 Destination Port Unreachable Yi Zhao reported it and narrowed it down to: 7fc38225363d ("netfilter: reject: skip csum verification for protocols that don't support it"), This is because nf_ip_checksum still expects pseudo-header protocol type 0 for packets that are of neither TCP or UDP, and thus ICMP packets are mistakenly treated as TCP/UDP. This patch corrects the conditions in nf_ip_checksum and all other places that still call it with protocol 0. Fixes: 7fc38225363d ("netfilter: reject: skip csum verification for protocols that don't support it") Reported-by: Yi Zhao Signed-off-by: He Zhe --- net/netfilter/nf_conntrack_proto_icmp.c | 2 +- net/netfilter/nf_nat_proto.c | 2 +- net/netfilter/utils.c | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_conntrack_proto_icmp.c b/net/netfilter/nf_conntrack_proto_icmp.c index a824367..dd53e2b 100644 --- a/net/netfilter/nf_conntrack_proto_icmp.c +++ b/net/netfilter/nf_conntrack_proto_icmp.c @@ -218,7 +218,7 @@ int nf_conntrack_icmpv4_error(struct nf_conn *tmpl, /* See ip_conntrack_proto_tcp.c */ if (state->net->ct.sysctl_checksum && state->hook == NF_INET_PRE_ROUTING && - nf_ip_checksum(skb, state->hook, dataoff, 0)) { + nf_ip_checksum(skb, state->hook, dataoff, IPPROTO_ICMP)) { icmp_error_log(skb, state, "bad hw icmp checksum"); return -NF_ACCEPT; } diff --git a/net/netfilter/nf_nat_proto.c b/net/netfilter/nf_nat_proto.c index 07da077..83a24cc 100644 --- a/net/netfilter/nf_nat_proto.c +++ b/net/netfilter/nf_nat_proto.c @@ -564,7 +564,7 @@ int nf_nat_icmp_reply_translation(struct sk_buff *skb, if (!skb_make_writable(skb, hdrlen + sizeof(*inside))) return 0; - if (nf_ip_checksum(skb, hooknum, hdrlen, 0)) + if (nf_ip_checksum(skb, hooknum, hdrlen, IPPROTO_ICMP)) return 0; inside = (void *)skb->data + hdrlen; diff --git a/net/netfilter/utils.c b/net/netfilter/utils.c index 06dc555..51b454d 100644 --- a/net/netfilter/utils.c +++ b/net/netfilter/utils.c @@ -17,7 +17,8 @@ __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook, case CHECKSUM_COMPLETE: if (hook != NF_INET_PRE_ROUTING && hook != NF_INET_LOCAL_IN) break; - if ((protocol == 0 && !csum_fold(skb->csum)) || + if ((protocol != IPPROTO_TCP && protocol != IPPROTO_UDP && + !csum_fold(skb->csum)) || !csum_tcpudp_magic(iph->saddr, iph->daddr, skb->len - dataoff, protocol, skb->csum)) { @@ -26,7 +27,7 @@ __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook, } /* fall through */ case CHECKSUM_NONE: - if (protocol == 0) + if (protocol != IPPROTO_TCP && protocol != IPPROTO_UDP) skb->csum = 0; else skb->csum = csum_tcpudp_nofold(iph->saddr, iph->daddr, -- 2.7.4