netfilter: conntrack: add new sysctl to disable RST check
Subsystems (3)
PATCH 1/1 netfilter: conntrack: add new sysctl to disable RST check
This patch adds a new sysctl tcp_ignore_invalid_rst to disable marking out of segments RSTs as INVALID.
--- Documentation/networking/nf_conntrack-sysctl.rst | 6 ++++++ include/net/netns/conntrack.h | 1 + net/netfilter/nf_conntrack_proto_tcp.c | 6 +++++- net/netfilter/nf_conntrack_standalone.c | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-)
Documentation/networking/nf_conntrack-sysctl.rst +6 -0
@@ -110,6 +110,12 @@ nf_conntrack_tcp_be_liberal - BOOLEAN Be conservative in what you do, be liberal in what you accept from others. If it's non-zero, we mark only out of window RST segments as INVALID. +nf_conntrack_tcp_ignore_invalid_rst - BOOLEAN + - 0 - disabled (default) + - not 0 - enabled + + If it's non-zero, we don't mark out of window RST segments as INVALID. + nf_conntrack_tcp_loose - BOOLEAN - 0 - disabled - not 0 - enabled (default)
include/net/netns/conntrack.h +1 -0
@@ -27,6 +27,7 @@ struct nf_tcp_net {u8 tcp_loose;u8 tcp_be_liberal;u8 tcp_max_retrans; +u8 tcp_ignore_invalid_rst; };enum udp_conntrack {
net/netfilter/nf_conntrack_proto_tcp.c +5 -1
@@ -1032,7 +1032,8 @@ int nf_conntrack_tcp_packet(struct nf_conn *ct,if (ct->proto.tcp.seen[!dir].flags &IP_CT_TCP_FLAG_MAXACK_SET ) {u32 seq =ntohl (th->seq); -if (before (seq, ct->proto.tcp.seen[!dir].td_maxack)) { +if (before (seq, ct->proto.tcp.seen[!dir].td_maxack) && + !tn->tcp_ignore_invalid_rst) {/* Invalid RST */ spin_unlock_bh (&ct->lock);nf_ct_l4proto_log_invalid (skb, ct,"invalid rst" );
@@ -1436,6 +1437,9 @@ void nf_conntrack_tcp_init_net(struct net *net)*/ tn->tcp_be_liberal =0 ; +/* If it's non-zero, we turn off RST sequence number check */ + tn->tcp_ignore_invalid_rst =0 ; +/* Max number of the retransmitted packets without receiving an (acceptable) * ACK from the destination. If this number is reached, a shorter timer * will be started.
net/netfilter/nf_conntrack_standalone.c +10 -0
@@ -577,6 +577,7 @@ enum nf_ct_sysctl_index {NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_UNACK ,NF_SYSCTL_CT_PROTO_TCP_LOOSE ,NF_SYSCTL_CT_PROTO_TCP_LIBERAL , +NF_SYSCTL_CT_PROTO_TCP_IGNORE_INVALID_RST ,NF_SYSCTL_CT_PROTO_TCP_MAX_RETRANS ,NF_SYSCTL_CT_PROTO_TIMEOUT_UDP , NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_STREAM,
@@ -778,6 +779,14 @@ static struct ctl_table nf_ct_sysctl_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, }, + [NF_SYSCTL_CT_PROTO_TCP_IGNORE_INVALID_RST] = { + .procname = "nf_conntrack_tcp_ignore_invalid_rst", + .maxlen = sizeof(u8), + .mode = 0644, + .proc_handler = proc_dou8vec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, [NF_SYSCTL_CT_PROTO_TCP_MAX_RETRANS] = { .procname = "nf_conntrack_tcp_max_retrans", .maxlen = sizeof(u8),
@@ -970,6 +979,7 @@ static void nf_conntrack_standalone_init_tcp_sysctl(struct net *net,XASSIGN (LOOSE , &tn->tcp_loose);XASSIGN (LIBERAL , &tn->tcp_be_liberal);XASSIGN (MAX_RETRANS , &tn->tcp_max_retrans); +XASSIGN (IGNORE_INVALID_RST , &tn->tcp_ignore_invalid_rst);#undef XASSIGN }
Signature · 1 line
2.26.2
Le 26/05/2021 à 11:24, Ali Abdallah a écrit :
Quoted 16 lines
This patch adds a new sysctl
tcp_ignore_invalid_rstto disable marking out of segments RSTs as INVALID.Signed-off-by Ali Abdallah <[email protected]>--- Documentation/networking/nf_conntrack-sysctl.rst | 6 ++++++ include/net/netns/conntrack.h | 1 + net/netfilter/nf_conntrack_proto_tcp.c | 6 +++++- net/netfilter/nf_conntrack_standalone.c | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-)Documentation/networking/nf_conntrack-sysctl.rst +0
-0
Documentation/networking/nf_conntrack-sysctl.rst nf_conntrack_tcp_be_liberal - BOOLEAN · line 115
Quoted 6 lines
Documentation/networking/nf_conntrack-sysctl.rst +3
-0@@ -110,6 +110,12 @@ nf_conntrack_tcp_be_liberal - BOOLEAN Be conservative in what you do, be liberal in what you accept from others. If it's non-zero, we mark only out of window RST segments as INVALID. +nf_conntrack_tcp_ignore_invalid_rst - BOOLEAN + - 0 - disabled (default) + - not 0 - enabled
If I correctly read the patch, the only "not 0" possible value is 1. Why not using explicitly "1"?
[snip]
Documentation/networking/nf_conntrack-sysctl.rst static struct ctl_table nf_ct_sysctl_table[] = { · line 788
Quoted 11 lines
Documentation/networking/nf_conntrack-sysctl.rst +7
-0@@ -778,6 +779,14 @@ static struct ctl_table nf_ct_sysctl_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, }, + [NF_SYSCTL_CT_PROTO_TCP_IGNORE_INVALID_RST] = { + .procname = "nf_conntrack_tcp_ignore_invalid_rst", + .maxlen = sizeof(u8), + .mode = 0644, + .proc_handler = proc_dou8vec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE,
Max == 1.
Regards,
Nicolas
Quoted 5 lines · Nicolas Dichtel
Documentation/networking/nf_conntrack-sysctl.rst nf_conntrack_tcp_be_liberal - BOOLEAN · line 115
Quoted 3 lines
Documentation/networking/nf_conntrack-sysctl.rst +3
-0+nf_conntrack_tcp_ignore_invalid_rst - BOOLEAN + - 0 - disabled (default) + - not 0 - enabledIf I correctly read the patch, the only "not 0" possible value is 1. Why not using explicitly "1"?
That what the doc on nf_conntrack_tcp_be_liberal says as well, logically not 0 is 1, so IMHO I don't think that can lead to confusion.
Kind regards,
Ali
Le 26/05/2021 à 16:34, Ali Abdallah a écrit :
Quoted 9 lines · Nicolas Dichtel
Quoted 5 lines
Documentation/networking/nf_conntrack-sysctl.rst nf_conntrack_tcp_be_liberal - BOOLEAN · line 115
Quoted 3 lines
Documentation/networking/nf_conntrack-sysctl.rst +3
-0+nf_conntrack_tcp_ignore_invalid_rst - BOOLEAN + - 0 - disabled (default) + - not 0 - enabledIf I correctly read the patch, the only "not 0" possible value is 1. Why not using explicitly "1"?
That what the doc on
nf_conntrack_tcp_be_liberalsays as well, logically not 0 is 1, so IMHO I don't think that can lead to confusion.
There is a lot of sysctl that have several magic values, see
https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt
And some act like boolean but accept all values,/proc/sys/net/ipv4/conf/*/forwarding for example.
There is nothing obvious with sysctl values (and a lot of inconsistencies), it's why I suggest to be explicit.
Regards,
Nicolas
Quoted 4 lines · Nicolas Dichtel
Le 26/05/2021 à 16:34, Ali Abdallah a écrit :
Quoted 2 lines
That what the doc on
nf_conntrack_tcp_be_liberalsays as well, logically not 0 is 1, so IMHO I don't think that can lead to confusion.
Quoted 8 lines
There is a lot of sysctl that have several magic values, see
https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txtAnd some act like boolean but accept all values,
/proc/sys/net/ipv4/conf/*/forwardingfor example.There is nothing obvious with sysctl values (and a lot of inconsistencies), it's why I suggest to be explicit.
Yes, I absolutely see your point, and I have no problem in making that explicit, I will sent a v2 patch saying explicitly that only "1" would disable RST seq number checks, hopefully it gets merged soon.
Quoted 2 lines
Regards,
Nicolas
Kind Regards,
Ali
Quoted 2 lines · Ali Abdallah
This patch adds a new sysctl
tcp_ignore_invalid_rstto disable marking out of segments RSTs as INVALID.
Just for archives:
I am not sure this is still needed after the recent change, but I can see why its desirable to keep NAT working even when RST is invalid.
I think that the more fundamental problem is the inability to permit setting a conntrack as INVALID while allowing NAT to work, i.e. move drop decision to ruleset.
However, I see that this isn't easy to change. Therefore,