: tcp_conntrack: accept RST|PSH as valid
Subsystems (2)
This combination has been encountered on an IBM AS/400 in response to packets sent to a closed session. There is no particular reason to mark it invalid.
--- net/ipv4/netfilter/ip_conntrack_proto_tcp.c | 1 + net/netfilter/nf_conntrack_proto_tcp.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
net/ipv4/netfilter/ip_conntrack_proto_tcp.c +1 -0
@@ -818,6 +818,7 @@ static const u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG) + 1 [TH_SYN|TH_ACK] = 1, [TH_SYN|TH_ACK|TH_PUSH] = 1, [TH_RST] = 1, + [TH_RST|TH_PUSH] = 1, [TH_RST|TH_ACK] = 1, [TH_RST|TH_ACK|TH_PUSH] = 1, [TH_FIN|TH_ACK] = 1,
net/netfilter/nf_conntrack_proto_tcp.c +1 -0
@@ -775,6 +775,7 @@ static u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG) + 1] = [TH_SYN|TH_ACK] = 1, [TH_SYN|TH_ACK|TH_PUSH] = 1, [TH_RST] = 1, + [TH_RST|TH_PUSH] = 1, [TH_RST|TH_ACK] = 1, [TH_RST|TH_ACK|TH_PUSH] = 1, [TH_FIN|TH_ACK] = 1,
Signature · 1 line
1.5.0.3
[NETFILTER]: tcp_conntrack: factorize out the PUSH flag
The PUSH flag is accepted with every other valid combination. Let's get it out of the tcp_valid_flags table and reduce the number of combinations we have to handle. This does not significantly reduce the table size however (8 bytes).
--- net/ipv4/netfilter/ip_conntrack_proto_tcp.c | 17 ++++------------- net/netfilter/nf_conntrack_proto_tcp.c | 17 ++++------------- 2 files changed, 8 insertions(+), 26 deletions(-)
net/ipv4/netfilter/ip_conntrack_proto_tcp.c +4 -13
@@ -808,27 +808,18 @@ void ip_conntrack_tcp_update(struct sk_buff *skb,#define TH_ECE 0x40#define TH_CWR 0x80 -/* table of valid flag combinations - ECE and CWR are always valid */ -static const u8 tcp_valid_flags[(TH_FIN |TH_SYN |TH_RST |TH_PUSH |TH_ACK |TH_URG ) +1 ] = +/* table of valid flag combinations - PUSH, ECE and CWR are always valid */ +static const u8 tcp_valid_flags[(TH_FIN |TH_SYN |TH_RST |TH_ACK |TH_URG ) +1 ] = { [TH_SYN ] =1 , - [TH_SYN |TH_PUSH ] =1 , [TH_SYN |TH_URG ] =1 , - [TH_SYN |TH_PUSH |TH_URG ] =1 , [TH_SYN |TH_ACK ] =1 , - [TH_SYN |TH_ACK |TH_PUSH ] =1 , [TH_RST ] =1 , - [TH_RST |TH_PUSH ] =1 , [TH_RST |TH_ACK ] =1 , - [TH_RST |TH_ACK |TH_PUSH ] =1 , [TH_FIN |TH_ACK ] =1 , + [TH_FIN |TH_ACK |TH_URG ] =1 , [TH_ACK ] =1 , - [TH_ACK |TH_PUSH ] =1 , [TH_ACK |TH_URG ] =1 , - [TH_ACK |TH_URG |TH_PUSH ] =1 , - [TH_FIN |TH_ACK |TH_PUSH ] =1 , - [TH_FIN |TH_ACK |TH_URG ] =1 , - [TH_FIN |TH_ACK |TH_URG |TH_PUSH ] =1 , };/* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
@@ -873,7 +864,7 @@ static int tcp_error(struct sk_buff *skb, }/* Check TCP flags. */ - tcpflags = (((u_int8_t *)th)[13 ] & ~(TH_ECE |TH_CWR )); + tcpflags = (((u_int8_t *)th)[13 ] & ~(TH_ECE |TH_CWR |TH_PUSH ));if (!tcp_valid_flags[tcpflags]) {if (LOG_INVALID (IPPROTO_TCP )) nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
net/netfilter/nf_conntrack_proto_tcp.c +4 -13
@@ -765,27 +765,18 @@ EXPORT_SYMBOL_GPL(nf_conntrack_tcp_update);#define TH_ECE 0x40#define TH_CWR 0x80 -/* table of valid flag combinations - ECE and CWR are always valid */ -static u8 tcp_valid_flags[(TH_FIN |TH_SYN |TH_RST |TH_PUSH |TH_ACK |TH_URG ) +1 ] = +/* table of valid flag combinations - PUSH, ECE and CWR are always valid */ +static u8 tcp_valid_flags[(TH_FIN |TH_SYN |TH_RST |TH_ACK |TH_URG ) +1 ] = { [TH_SYN ] =1 , - [TH_SYN |TH_PUSH ] =1 , [TH_SYN |TH_URG ] =1 , - [TH_SYN |TH_PUSH |TH_URG ] =1 , [TH_SYN |TH_ACK ] =1 , - [TH_SYN |TH_ACK |TH_PUSH ] =1 , [TH_RST ] =1 , - [TH_RST |TH_PUSH ] =1 , [TH_RST |TH_ACK ] =1 , - [TH_RST |TH_ACK |TH_PUSH ] =1 , [TH_FIN |TH_ACK ] =1 , + [TH_FIN |TH_ACK |TH_URG ] =1 , [TH_ACK ] =1 , - [TH_ACK |TH_PUSH ] =1 , [TH_ACK |TH_URG ] =1 , - [TH_ACK |TH_URG |TH_PUSH ] =1 , - [TH_FIN |TH_ACK |TH_PUSH ] =1 , - [TH_FIN |TH_ACK |TH_URG ] =1 , - [TH_FIN |TH_ACK |TH_URG |TH_PUSH ] =1 , };/* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */
@@ -832,7 +823,7 @@ static int tcp_error(struct sk_buff *skb, }/* Check TCP flags. */ - tcpflags = (((u_int8_t *)th)[13 ] & ~(TH_ECE |TH_CWR )); + tcpflags = (((u_int8_t *)th)[13 ] & ~(TH_ECE |TH_CWR |TH_PUSH ));if (!tcp_valid_flags[tcpflags]) {if (LOG_INVALID (IPPROTO_TCP )) nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
Signature · 1 line
1.5.0.3
Re: [NETFILTER]: tcp_conntrack: factorize out the PUSH flag
Quoted 4 lines · Willy Tarreau
The PUSH flag is accepted with every other valid combination. Let's get it out of the
tcp_valid_flagstable and reduce the number of combinations we have to handle. This does not significantly reduce the table size however (8 bytes).
Thanks Willy, both applied. I edited out the ip_conntrack parts since that is already removed in my 2.6.22 tree.
Pablo Neira Ayuso
maintainerBonjour Willy,
Quoted 3 lines · Willy Tarreau
This combination has been encountered on an IBM AS/400 in response to packets sent to a closed session. There is no particular reason to mark it invalid.
I wonder if it is time to document this stuff. Would an interface to configurate valid TCP flags settings from userspace be too much? Of course, we would have a default configuration setup for them.
Signature · 2 lines
The dawn of the fourth age of Linux firewalling is coming; a time of great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris
Quoted 3 lines · Pablo Neira Ayuso
I wonder if it is time to document this stuff. Would an interface to configurate valid TCP flags settings from userspace be too much? Of course, we would have a default configuration setup for them.
I don't think we need this. Flags are either valid for everyone or for nobody.
Quoted 7 lines · Patrick McHardy
Quoted 3 lines · Pablo Neira Ayuso
I wonder if it is time to document this stuff. Would an interface to configurate valid TCP flags settings from userspace be too much? Of course, we would have a default configuration setup for them.
I don't think we need this. Flags are either valid for everyone or for nobody.
I agree. If you do not want certain TCP flag combinations, use iptables -j DROP, no?
Jan