git: cc638b24d56a - stable/15 - pf: relax sctp v_tag verification
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 11 Dec 2025 09:25:53 UTC
The branch stable/15 has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=cc638b24d56a1472eb366e4320529d6bf77fd4e8
commit cc638b24d56a1472eb366e4320529d6bf77fd4e8
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2025-11-25 09:59:02 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2025-12-11 09:22:22 +0000
pf: relax sctp v_tag verification
pf was too strict when validating SCTP tags. When a server receives a
retransmitted INIT it will reply with a random initiate tag every time.
However, pf saves the first initiate tag and expects every subsequent INIT_ACK
retransmission to have the same tag. This is not the case, leading to endless
INIT/INIT_ACK cycles.
Allow the tag to be updated as long as we've not gone past COOKIE_WAIT.
Add a test case to verify this.
MFC after: 2 weeks
See also: https://redmine.pfsense.org/issues/16516
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit bc3b72ff48953551e0e8bd6e5a2c718ecd973285)
---
sys/netpfil/pf/pf.c | 6 +++-
tests/sys/netpfil/pf/sctp.py | 67 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index fa6dd41cecee..fb67c37b1556 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -7362,7 +7362,11 @@ pf_sctp_track(struct pf_kstate *state, struct pf_pdesc *pd,
}
if (src->scrub != NULL) {
- if (src->scrub->pfss_v_tag == 0)
+ /*
+ * Allow tags to be updated, in case of retransmission of
+ * INIT/INIT_ACK chunks.
+ **/
+ if (src->state <= SCTP_COOKIE_WAIT)
src->scrub->pfss_v_tag = pd->hdr.sctp.v_tag;
else if (src->scrub->pfss_v_tag != pd->hdr.sctp.v_tag)
return (PF_DROP);
diff --git a/tests/sys/netpfil/pf/sctp.py b/tests/sys/netpfil/pf/sctp.py
index f492f26b63a1..9f1d7dea4ef6 100644
--- a/tests/sys/netpfil/pf/sctp.py
+++ b/tests/sys/netpfil/pf/sctp.py
@@ -551,6 +551,73 @@ class TestSCTP(VnetTestTemplate):
assert re.search(r"epair.*sctp 192.0.2.1:.*192.0.2.3:1234", states)
assert re.search(r"epair.*sctp 192.0.2.1:.*192.0.2.2:1234", states)
+class TestSCTP_SRV(VnetTestTemplate):
+ REQUIRED_MODULES = ["sctp", "pf"]
+ TOPOLOGY = {
+ "vnet1": {"ifaces": ["if1"]},
+ "vnet2": {"ifaces": ["if1"]},
+ "if1": {"prefixes4": [("192.0.2.1/24", "192.0.2.2/24")]},
+ }
+
+ def vnet2_handler(self, vnet):
+ ToolsHelper.print_output("/sbin/pfctl -e")
+ ToolsHelper.pf_rules([
+ "set state-policy if-bound",
+ "pass inet proto sctp",
+ "pass on lo"])
+
+ # Start an SCTP server process, pipe the ppid + data back to the other vnet?
+ srv = SCTPServer(socket.AF_INET, port=1234)
+ while True:
+ srv.accept(vnet)
+
+ @pytest.mark.require_user("root")
+ @pytest.mark.require_progs(["scapy"])
+ def test_initiate_tag_check(self):
+ # Ensure we don't send ABORTs in response to the other end's INIT_ACK
+ # That'd interfere with our test.
+ ToolsHelper.print_output("/sbin/sysctl net.inet.sctp.blackhole=2")
+
+ import scapy.all as sp
+
+ packet = sp.IP(src="192.0.2.1", dst="192.0.2.2") \
+ / sp.SCTP(sport=1234, dport=1234) \
+ / sp.SCTPChunkInit(init_tag=1, n_in_streams=1, n_out_streams=1, a_rwnd=1500)
+ packet.show()
+
+ r = sp.sr1(packet, timeout=3)
+ assert r
+ r.show()
+ assert r.getlayer(sp.SCTP)
+ assert r.getlayer(sp.SCTPChunkInitAck)
+ assert r.getlayer(sp.SCTP).tag == 1
+
+ # Send another INIT with the same initiate tag, expect another init ack
+ packet = sp.IP(src="192.0.2.1", dst="192.0.2.2") \
+ / sp.SCTP(sport=1234, dport=1234) \
+ / sp.SCTPChunkInit(init_tag=1, n_in_streams=1, n_out_streams=1, a_rwnd=1500)
+ packet.show()
+
+ r = sp.sr1(packet, timeout=3)
+ assert r
+ r.show()
+ assert r.getlayer(sp.SCTP)
+ assert r.getlayer(sp.SCTPChunkInitAck)
+ assert r.getlayer(sp.SCTP).tag == 1
+
+ # Send an INIT with a different initiate tag, expect another init ack
+ packet = sp.IP(src="192.0.2.1", dst="192.0.2.2") \
+ / sp.SCTP(sport=1234, dport=1234) \
+ / sp.SCTPChunkInit(init_tag=42, n_in_streams=1, n_out_streams=1, a_rwnd=1500)
+ packet.show()
+
+ r = sp.sr1(packet, timeout=3)
+ assert r
+ r.show()
+ assert r.getlayer(sp.SCTP)
+ assert r.getlayer(sp.SCTPChunkInitAck)
+ assert r.getlayer(sp.SCTP).tag == 42
+
class TestSCTPv6(VnetTestTemplate):
REQUIRED_MODULES = ["sctp", "pf"]
TOPOLOGY = {