From nobody Mon Aug 21 13:25:00 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RTtWK1ZB8z4qmWt; Mon, 21 Aug 2023 13:25:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RTtWK0h20z3MVV; Mon, 21 Aug 2023 13:25:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692624301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YqgiaSbDLbP1lbdcO6WgB/1ZOPbkWYDtPg1/Hz8eT/Q=; b=CMMbgiO/YzIjb74X+2uDZTJfpQYLU3tqbp23igrArMir1+2MhCsFwC8gVzkSXEjrHX56zM 0H20FmKuMFZ4gph5wM5I29ZRevLHhXUiFp/OfpbXh9QhWZo6+X8NT1lpB/l8EuNiEHFPUg hRubpcqFwiUOKCSVBElwBgB+ppqptutnF1aCKy9Er8vrLdDcL6URqHM/G0x+kc/uVaMVft 5ghZBk6GVhivd7KCzfPl61x5YxDXm12k252kLu5lU7Jkc2WKAI9FkKLGXVsSR9qUuPbRYn b+cRTs9NdlTiLgfAhBL/xJpmxLxmvGNf8nRg07eR4hIir5AWJ060KTcgNnyqEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692624301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YqgiaSbDLbP1lbdcO6WgB/1ZOPbkWYDtPg1/Hz8eT/Q=; b=lr3UjAY2DLD8uv0Cil+spscogWmT2Y7M9qcfF5Lyn9v+i84SJ0oNJUzQnSEpNnJ1raHWlF 2EvxL6MpIHMWEktGU9o7WwFED/VJGzz/EoXxZLpXduSCl68t/Q2fIJZZ5ddC1DN2MR0JcN euFamBf0yhwQovaeF2rGpLpXougTemInC7yL8LqGwlwS6tI4HVNINvq86/5hxakqZneCbA rzQUfz/VTQz+bKLsApnRFDGeNjcVlesO/nsmkedbTD52/vQQnXbVGo1unU9UkJeCnI0irT PFK9BwfwZQMZWzTUontwEhxtMGQKWPna4Bxiatg2ZqiXr9HPJKuDZQ0ZZJZgAQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692624301; a=rsa-sha256; cv=none; b=AEg21bMrc7oLaOFWqP/DqHHE1p29rL3TLJ9KlflMrWsHbBt+/tGHOz/BM3bx6giLoug7eB tbsw5cGrRdlN9fZqaeOYesGTLnBYzbocGtHSH8bQh2klQelPV3zSVfoKwmD9TZ39hFBud/ gDYfs8yE/t5CYfdN9QCUkqBj9zoyx3AqRLC58gSM3jg6POh5OO5oujVn9MF75+1uvBaBWs AcQxt0ChR/fComBfUVqfjd+IiiSlWjsO9fMtN2IkdhlZ1YMF1pex3FaqOhpskAt5HyfxZH JaUeANDqNjQ7x8+iMUGMX7ZRTX6zSOPI1U9Zvl7lhCM2EQZN97e8BK64UYsaYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RTtWJ6d0Qz6xP; Mon, 21 Aug 2023 13:25:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37LDP0cu014285; Mon, 21 Aug 2023 13:25:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37LDP0Dv014282; Mon, 21 Aug 2023 13:25:00 GMT (envelope-from git) Date: Mon, 21 Aug 2023 13:25:00 GMT Message-Id: <202308211325.37LDP0Dv014282@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 92d4152295bc - main - pf: enable the syncookie feature for IPv6 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 92d4152295bc670b80352b5fbe102565de99a4eb Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=92d4152295bc670b80352b5fbe102565de99a4eb commit 92d4152295bc670b80352b5fbe102565de99a4eb Author: Kajetan Staszkiewicz AuthorDate: 2023-08-21 06:01:29 +0000 Commit: Kristof Provost CommitDate: 2023-08-21 11:19:06 +0000 pf: enable the syncookie feature for IPv6 When syncookie support was added to pf the relevant work was only done in pf_test(), not pf_test6(). Do this now. MFC after: 1 week Reviewed by: kp Sponsored by: InnoGames GmbH Differential Revision: https://reviews.freebsd.org/D41502 --- sys/netpfil/pf/pf.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index c2b9ee21d04c..c80553ba017d 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -8108,6 +8108,15 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb pd.p_len = pd.tot_len - off - (pd.hdr.tcp.th_off << 2); pd.sport = &pd.hdr.tcp.th_sport; pd.dport = &pd.hdr.tcp.th_dport; + + /* Respond to SYN with a syncookie. */ + if ((pd.hdr.tcp.th_flags & (TH_SYN|TH_ACK|TH_RST)) == TH_SYN && + pd.dir == PF_IN && pf_synflood_check(&pd)) { + pf_syncookie_send(m, off, &pd); + action = PF_DROP; + break; + } + action = pf_normalize_tcp(kif, m, 0, off, h, &pd); if (action == PF_DROP) goto done; @@ -8117,9 +8126,45 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb V_pfsync_update_state_ptr(s); r = s->rule.ptr; a = s->anchor.ptr; - } else if (s == NULL) - action = pf_test_rule(&r, &s, kif, m, off, &pd, - &a, &ruleset, inp); + } else if (s == NULL) { + /* Validate remote SYN|ACK, re-create original SYN if + * valid. */ + if ((pd.hdr.tcp.th_flags & (TH_SYN|TH_ACK|TH_RST)) == + TH_ACK && pf_syncookie_validate(&pd) && + pd.dir == PF_IN) { + struct mbuf *msyn; + + msyn = pf_syncookie_recreate_syn(h->ip6_hlim, + off, &pd); + if (msyn == NULL) { + action = PF_DROP; + break; + } + + action = pf_test6(dir, pflags, ifp, &msyn, inp, + &pd.act); + m_freem(msyn); + if (action != PF_PASS) + break; + + action = pf_test_state_tcp(&s, kif, m, off, h, + &pd, &reason); + if (action != PF_PASS || s == NULL) { + action = PF_DROP; + break; + } + + s->src.seqhi = ntohl(pd.hdr.tcp.th_ack) - 1; + s->src.seqlo = ntohl(pd.hdr.tcp.th_seq) - 1; + pf_set_protostate(s, PF_PEER_SRC, PF_TCPS_PROXY_DST); + + action = pf_synproxy(&pd, &s, &reason); + break; + } else { + action = pf_test_rule(&r, &s, kif, m, off, &pd, + &a, &ruleset, inp); + } + } break; }