netfilter: conntrack: improve RST handling when tuple is re-used
authorAli Abdallah <aabdallah@suse.de>
Thu, 20 May 2021 10:53:11 +0000 (12:53 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 6 Jul 2021 12:15:12 +0000 (14:15 +0200)
commitc4edc3ccbc63947e697bd2e30afca8bfaa144998
treee95f8131643d42b4e6af4a07477e239e6266e8fe
parentc23a9fd209bc6f8c1fa6ee303fdf037d784a1627
netfilter: conntrack: improve RST handling when tuple is re-used

If we receive a SYN packet in original direction on an existing
connection tracking entry, we let this SYN through because conntrack
might be out-of-sync.

Conntrack gets back in sync when server responds with SYN/ACK and state
gets updated accordingly.

However, if server replies with RST, this packet might be marked as
INVALID because td_maxack value reflects the *old* conntrack state
and not the state of the originator of the RST.

Avoid td_maxack-based checks if previous packet was a SYN.

Unfortunately that is not be enough: an out of order ACK in original
direction updates last_index, so we still end up marking valid RST.

Thus disable the sequence check when we are not in established state and
the received RST has a sequence of 0.

Because marking RSTs as invalid usually leads to unwanted timeouts,
also skip RST sequence checks if a conntrack entry is already closing.

Such entries can already be evicted via GC in case the table is full.

Co-developed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Ali Abdallah <aabdallah@suse.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_conntrack_proto_tcp.c