Ali Abdallah 54ae06
From 04553e40a19178f50ff56470bc72313632fb9994 Mon Sep 17 00:00:00 2001
Ali Abdallah 54ae06
From: Ali Abdallah <aabdallah@suse.de>
Ali Abdallah 54ae06
Date: Fri, 28 May 2021 12:49:24 +0200
Ali Abdallah 54ae06
Subject: [PATCH] netfilter: conntrack: add new sysctl to disable RST check
Michal Kubecek 9d8252
Patch-mainline: Submitted - 2021-05-27 - https://patchwork.ozlabs.org/project/netfilter-devel/patch/20210527071906.s7z72s7wsene5lib@Fryzen495/
Ali Abdallah 54ae06
References: bsc#1183947 bsc#1185950
Ali Abdallah 54ae06
Ali Abdallah 54ae06
This patch adds a new sysctl tcp_ignore_invalid_rst to disable marking
Ali Abdallah 54ae06
out of segments RSTs as INVALID.
Ali Abdallah 54ae06
Ali Abdallah 54ae06
Signed-off-by: Ali Abdallah <aabdallah@suse.de>
Ali Abdallah 54ae06
Ali Abdallah 54ae06
Acked-by: Ali Abdallah <aabdallah@suse.de>
Ali Abdallah 54ae06
---
Ali Abdallah 54ae06
 Documentation/networking/nf_conntrack-sysctl.txt |  6 ++++++
Ali Abdallah 54ae06
 include/net/netns/conntrack.h                    |  3 +++
Ali Abdallah 54ae06
 net/netfilter/nf_conntrack_proto_tcp.c           |  6 +++++-
Ali Abdallah 54ae06
 net/netfilter/nf_conntrack_standalone.c          | 10 ++++++++++
Ali Abdallah 54ae06
 4 files changed, 24 insertions(+), 1 deletion(-)
Ali Abdallah 54ae06
Ali Abdallah 54ae06
diff --git a/Documentation/networking/nf_conntrack-sysctl.txt b/Documentation/networking/nf_conntrack-sysctl.txt
Ali Abdallah 54ae06
index f75c2ce6e..4d4925826 100644
Ali Abdallah 54ae06
--- a/Documentation/networking/nf_conntrack-sysctl.txt
Ali Abdallah 54ae06
+++ b/Documentation/networking/nf_conntrack-sysctl.txt
Ali Abdallah 54ae06
@@ -103,6 +103,12 @@ nf_conntrack_tcp_be_liberal - BOOLEAN
Ali Abdallah 54ae06
 	Be conservative in what you do, be liberal in what you accept from others.
Ali Abdallah 54ae06
 	If it's non-zero, we mark only out of window RST segments as INVALID.
Ali Abdallah 54ae06
 
Ali Abdallah 54ae06
+nf_conntrack_tcp_ignore_invalid_rst - BOOLEAN
Ali Abdallah 54ae06
+	- 0 - disabled (default)
Ali Abdallah 54ae06
+	- 1 - enabled
Ali Abdallah 54ae06
+
Ali Abdallah 54ae06
+	If it's non-zero, we don't mark out of window RST segments as INVALID.
Ali Abdallah 54ae06
+
Ali Abdallah 54ae06
 nf_conntrack_tcp_loose - BOOLEAN
Ali Abdallah 54ae06
 	0 - disabled
Ali Abdallah 54ae06
 	not 0 - enabled (default)
Ali Abdallah 54ae06
diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
Ali Abdallah 54ae06
index 806454e76..cc8e97940 100644
Ali Abdallah 54ae06
--- a/include/net/netns/conntrack.h
Ali Abdallah 54ae06
+++ b/include/net/netns/conntrack.h
Ali Abdallah 54ae06
@@ -27,6 +27,9 @@ struct nf_tcp_net {
Ali Abdallah 54ae06
 	int tcp_loose;
Ali Abdallah 54ae06
 	int tcp_be_liberal;
Ali Abdallah 54ae06
 	int tcp_max_retrans;
Ali Abdallah 54ae06
+#ifndef __GENKSYMS__
Ali Abdallah 54ae06
+	int tcp_ignore_invalid_rst;
Ali Abdallah 54ae06
+#endif
Ali Abdallah 54ae06
 };
Ali Abdallah 54ae06
 
Ali Abdallah 54ae06
 enum udp_conntrack {
Ali Abdallah 54ae06
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
Ali Abdallah 54ae06
index 9d825992c..35ee0fa95 100644
Ali Abdallah 54ae06
--- a/net/netfilter/nf_conntrack_proto_tcp.c
Ali Abdallah 54ae06
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
Ali Abdallah 54ae06
@@ -36,6 +36,8 @@
Ali Abdallah 54ae06
     If it's non-zero, we mark only out of window RST segments as INVALID. */
Ali Abdallah 54ae06
 static int nf_ct_tcp_be_liberal __read_mostly = 0;
Ali Abdallah 54ae06
 
Ali Abdallah 54ae06
+static int nf_ct_tcp_ignore_invalid_rst __read_mostly = 0;
Ali Abdallah 54ae06
+
Ali Abdallah 54ae06
 /* If it is set to zero, we disable picking up already established
Ali Abdallah 54ae06
    connections. */
Ali Abdallah 54ae06
 static int nf_ct_tcp_loose __read_mostly = 1;
Ali Abdallah 54ae06
@@ -1078,7 +1080,8 @@ int nf_conntrack_tcp_packet(struct nf_conn *ct,
Ali Abdallah 54ae06
 			if (seq == 0 && !nf_conntrack_tcp_established(ct))
Ali Abdallah 54ae06
 				break;
Ali Abdallah 54ae06
 
Ali Abdallah 54ae06
-			if (before(seq, ct->proto.tcp.seen[!dir].td_maxack)) {
Ali Abdallah 54ae06
+			if (before(seq, ct->proto.tcp.seen[!dir].td_maxack) &&
Ali Abdallah 54ae06
+			    !tn->tcp_ignore_invalid_rst) {
Ali Abdallah 54ae06
 				/* Invalid RST  */
Ali Abdallah 54ae06
 				spin_unlock_bh(&ct->lock);
Ali Abdallah 54ae06
 				nf_ct_l4proto_log_invalid(skb, ct, "invalid rst");
Ali Abdallah 54ae06
@@ -1452,6 +1455,7 @@ void nf_conntrack_tcp_init_net(struct net *net)
Ali Abdallah 54ae06
 	tn->tcp_loose = nf_ct_tcp_loose;
Ali Abdallah 54ae06
 	tn->tcp_be_liberal = nf_ct_tcp_be_liberal;
Ali Abdallah 54ae06
 	tn->tcp_max_retrans = nf_ct_tcp_max_retrans;
Ali Abdallah 54ae06
+	tn->tcp_ignore_invalid_rst = nf_ct_tcp_ignore_invalid_rst;
Ali Abdallah 54ae06
 }
Ali Abdallah 54ae06
 
Ali Abdallah 54ae06
 const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp =
Ali Abdallah 54ae06
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
Ali Abdallah 54ae06
index 0006503d2..638e49f57 100644
Ali Abdallah 54ae06
--- a/net/netfilter/nf_conntrack_standalone.c
Ali Abdallah 54ae06
+++ b/net/netfilter/nf_conntrack_standalone.c
Ali Abdallah 54ae06
@@ -565,6 +565,7 @@ enum nf_ct_sysctl_index {
Ali Abdallah 54ae06
 	NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_UNACK,
Ali Abdallah 54ae06
 	NF_SYSCTL_CT_PROTO_TCP_LOOSE,
Ali Abdallah 54ae06
 	NF_SYSCTL_CT_PROTO_TCP_LIBERAL,
Ali Abdallah 54ae06
+	NF_SYSCTL_CT_PROTO_TCP_IGNORE_INVALID_RST,
Ali Abdallah 54ae06
 	NF_SYSCTL_CT_PROTO_TCP_MAX_RETRANS,
Ali Abdallah 54ae06
 	NF_SYSCTL_CT_PROTO_TIMEOUT_UDP,
Ali Abdallah 54ae06
 	NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_STREAM,
Ali Abdallah 54ae06
@@ -770,6 +771,14 @@ static struct ctl_table nf_ct_sysctl_table[] = {
Ali Abdallah 54ae06
 		.extra1 	= &zero,
Ali Abdallah 54ae06
 		.extra2 	= &one,
Ali Abdallah 54ae06
 	},
Ali Abdallah 54ae06
+	[NF_SYSCTL_CT_PROTO_TCP_IGNORE_INVALID_RST] = {
Ali Abdallah 54ae06
+		.procname	= "nf_conntrack_tcp_ignore_invalid_rst",
Ali Abdallah 54ae06
+		.maxlen		= sizeof(int),
Ali Abdallah 54ae06
+		.mode		= 0644,
Ali Abdallah 54ae06
+		.proc_handler	= proc_dointvec_minmax,
Ali Abdallah 54ae06
+		.extra1		= &zero,
Ali Abdallah 54ae06
+		.extra2		= &one,
Ali Abdallah 54ae06
+	},
Ali Abdallah 54ae06
 	[NF_SYSCTL_CT_PROTO_TCP_MAX_RETRANS] = {
Ali Abdallah 54ae06
 		.procname	= "nf_conntrack_tcp_max_retrans",
Ali Abdallah 54ae06
 		.maxlen		= sizeof(unsigned int),
Ali Abdallah 54ae06
@@ -962,6 +971,7 @@ static void nf_conntrack_standalone_init_tcp_sysctl(struct net *net,
Ali Abdallah 54ae06
 	XASSIGN(LOOSE, &tn->tcp_loose);
Ali Abdallah 54ae06
 	XASSIGN(LIBERAL, &tn->tcp_be_liberal);
Ali Abdallah 54ae06
 	XASSIGN(MAX_RETRANS, &tn->tcp_max_retrans);
Ali Abdallah 54ae06
+	XASSIGN(IGNORE_INVALID_RST, &tn->tcp_ignore_invalid_rst);
Ali Abdallah 54ae06
 #undef XASSIGN
Ali Abdallah 54ae06
 }
Ali Abdallah 54ae06
 
Ali Abdallah 54ae06
-- 
Ali Abdallah 54ae06
2.26.2
Ali Abdallah 54ae06