netfilter: conntrack: correct sequence on reinitialized TCP connection
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: conntrack: correct sequence on reinitialized TCP connection
Although RFC 793 states that sender "... must only be sure to use sequence numbers larger than those recently used" when TCP connection is reinitialized, it is not possible for a middlebox to guarantee that a (malicious) sender complies with the RFC.
One possible solution is to remove the after(end, sender->td_end), however, that would make it easier for an attacker to overwrite the victim's conntrack state with arbitrary ones.
Instead, let this syn packet go through as ignored and annotate its state to wait for server to deliver a syn-ack that proves that client is really trying to reach the server. This is similar to the existing code under TCP_CONNTRACK_IGNORE section where firewall is out-of-sync.
(malicious) sender can still possibly override the victim's state via syn flood, let just this syn-ack packet continue its travel and enter liberal mode in that case, we cannot make the scenario work universally.
Note that we can only tolerate one 'unknown last ignored' state and we can check if syn-ack carries the right sequence number saved in the state. All other scenarios require synproxy configuration where conntrack keeps no state.
Extend last_flags field to 16-bit to store IP_CT_TCP_REINIT, this flag is not exposed to userspace through uapi.
--- include/linux/netfilter/nf_conntrack_tcp.h | 5 +- net/netfilter/nf_conntrack_proto_tcp.c | 140 +++++++++++++++------ 2 files changed, 106 insertions(+), 39 deletions(-)
include/linux/netfilter/nf_conntrack_tcp.h +4 -1
@@ -14,6 +14,9 @@ struct ip_ct_tcp_state {u_int8_t flags;/* per direction options */ }; +/* unexpected SYN packet with smaller sequence number while in SYN_SENT. */ +#define IP_CT_TCP_REINIT 0x100 +struct ip_ct_tcp {struct ip_ct_tcp_state seen[2 ];/* connection parameters per direction */ u_int8_t state;/* state of the connection (enum tcp_conntrack) */
@@ -26,8 +29,8 @@ struct ip_ct_tcp {u_int32_t last_end;/* Last seq + len */ u_int16_t last_win;/* Last window advertisement seen in dir */ /* For SYN packets while we may be out-of-sync */ +u_int16_t last_flags;/* Last flags set */ u_int8_t last_wscale; /* Last window scaling factor seen */ - u_int8_t last_flags; /* Last flags set */ };#endif /* _NF_CONNTRACK_TCP_H */
net/netfilter/nf_conntrack_proto_tcp.c +102 -38
187 lines not on this page · raw message
Signature · 1 line
2.30.2