pf: fix syncookies in conjunction with tcp fast port reuse
authorKristof Provost <kp@FreeBSD.org>
Sat, 31 Dec 2022 14:59:10 +0000 (15:59 +0100)
committerKristof Provost <kp@FreeBSD.org>
Fri, 13 Jan 2023 22:14:12 +0000 (23:14 +0100)
commit9c041b450d5e604c3e35b5799b60a2c53795feef
tree8f05faef15418010c52919447448e67622ea79f3
parentae3301084da1a0e643a7589930186d67f0910b65
pf: fix syncookies in conjunction with tcp fast port reuse

Basic scenario: we have a closed connection (In TCPS_FIN_WAIT_2), and
get a new connection (i.e. SYN) re-using the tuple.

Without syncookies we look at the SYN, and completely unlink the old,
closed state on the SYN.
With syncookies we send a generated SYN|ACK back, and drop the SYN,
never looking at the state table.

So when the ACK (i.e. the third step in the three way handshake for
connection setup) turns up, we’ve not actually removed the old state, so
we find it, and don’t do the syncookie dance, or allow the new
connection to get set up.

Explicitly check for this in pf_test_state_tcp(). If we find a state in
TCPS_FIN_WAIT_2 and the syncookie is valid we delete the existing state
so we can set up the new state.
Note that when we verify the syncookie in pf_test_state_tcp() we don't
decrement the number of half-open connections to avoid an incorrect
double decrement.

MFC after:      2 weeks
Differential Revision:  https://reviews.freebsd.org/D37919
sys/net/pfvar.h
sys/netpfil/pf/pf.c
sys/netpfil/pf/pf_syncookies.c