There validation of SEG.SEQ (first step in SEGMENT ARRIVES) should be done before the validation of SEG.ACK (fifth step in SEGMENT ARRIVES). Furthermore, when the SEG.SEQ validation fails, a challenge ACK should be sent instead of sending a RST-segment and moving the endpoint to CLOSED.
Thanks to Tilnel for reporting the issue on freebsd-net@.