From nobody Wed Aug 21 07:44:53 2024 X-Original-To: dev-commits-src-all@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 4Wpddx55djz5TP3c; Wed, 21 Aug 2024 07:44:53 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Wpddx4Qsqz4T5L; Wed, 21 Aug 2024 07:44:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724226293; 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=i0huQh2lg+R2wSOI0g/BozCNu5C6uBXKicz0SQgB4UM=; b=DNq2vv21Jt6Wx1RlNLXlMPIbbjaTbTdHI0Nr7bCb/7Weq9q0+h5tfq8XSmRVRqh6ki7jL/ VMWnZOuTOdQUWBYwN0SCfZuJeqotMPCzYG7D8SWnv0dnTsxaAdL+8lI68FFl/ouIZ9N4tp kkVM6qaBAjyaHKj/rfj0dq5FIBqq0DxSMd6HWzRhxEhiRt5HyeVPGvCpUEFfrkpM2aBSRF IwG1qAxqhD8+o+QFQM9JPDeVM8vNbSNLHAhgKMn+ogcXXvr3xrATB/CoUmjyuI8K4jb12U XZc2Hn/u468UZJQW/lQRwXxot/zUk7Z6gTeE4Dj7k9IyXwo7KzUYSAbgmibSiw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724226293; a=rsa-sha256; cv=none; b=FVyG5YCJaegv2BkcgkOh3G50i3yR186jcgTdG3PatXwSG9Xx5EtD8ahmt7HRbX353iHf7f uEJcG4Q8UXBtL1Vfr5H9YMLW17vF3C11gQKGJ0tFFBmPXQR2DLefNvBrE0JJcD2qCpZx0y cp/S3P6EKuMv9HS94maYr1w9R+CEn7GL7xMHKGJHUA/gQce8bBzAeCMQ5mhyZe1y92Wu+d RL91W+Vt7rDuhG1+QC6CMIBHKVp4OU1mOqdjmsRmI634Jw4sqZYN6vv1ypxJyJuqtvKY9M 3l1YCa7iQHOPB4FliCZ6ti1HpOXJsmKoL9QWv9UKDa5IB7/4uRXGyJOZNp/3LQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724226293; 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=i0huQh2lg+R2wSOI0g/BozCNu5C6uBXKicz0SQgB4UM=; b=dVmONjduahZUER087Q1AobDd/XMVP1ImcHd5MKqEbfR3ICRs4Jcn1dQCOVeSLC4l0TLAP7 mc1FOFrjZLMifqy9RwE/q7gdXUhd1GM669V07lX2q8jYvyT9QjSsxcW6ZHYNkhlFVNBPhD TiE0QCVOzbAJC0/PWXeVujuCg2AOtBd9l0Ny7i0m5rlIILhwIqT3ycXJmRneB35DhV6RYy N+cGLtCTWEe3mKqvVjDLSAPaev7HfwJw0+zeH0VIAMd7BtGT5aTtoyJnIiYrKziHK4P+5E m3RxpAF190nceUFVodD7Lpx/nJo7CbTd7jSMh+Vvzw/vILJpAA1InpOUV5njbg== 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 4Wpddx41m9zbD2; Wed, 21 Aug 2024 07:44:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47L7ir1T088595; Wed, 21 Aug 2024 07:44:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47L7irXf088592; Wed, 21 Aug 2024 07:44:53 GMT (envelope-from git) Date: Wed, 21 Aug 2024 07:44:53 GMT Message-Id: <202408210744.47L7irXf088592@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 7d3a0370c8a3 - releng/13.4 - pf: fix icmp-in-icmp state lookup List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/releng/13.4 X-Git-Reftype: branch X-Git-Commit: 7d3a0370c8a3dadad0739ed88fc26536649119c5 Auto-Submitted: auto-generated The branch releng/13.4 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=7d3a0370c8a3dadad0739ed88fc26536649119c5 commit 7d3a0370c8a3dadad0739ed88fc26536649119c5 Author: Kristof Provost AuthorDate: 2024-08-12 14:07:35 +0000 Commit: Kristof Provost CommitDate: 2024-08-21 07:44:01 +0000 pf: fix icmp-in-icmp state lookup In 534ee17e6 pf state checking for ICMP(v6) was made stricter. This change failed to correctly set the pf_pdesc for ICMP-in-ICMP lookups, resulting in ICMP error packets potentially being dropped incorrectly. Specially, it copied the ICMP header into a separate variable, not into the pf_pdesc. Populate the required pf_pdesc fields for the embedded ICMP packet's state lookup. PR: 280701 Approved by: re (cperciva) MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 2da98eef1f352c496ffd458b4c68ddee972bb903) (cherry picked from commit 0d8d4cc3ea47f1ee61d749b22b135eb73c7d33cd) --- sys/netpfil/pf/pf.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 07d0604e924c..7d04bf07f760 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -6499,9 +6499,9 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif } #ifdef INET case IPPROTO_ICMP: { - struct icmp iih; + struct icmp *iih = &pd2.hdr.icmp; - if (!pf_pull_hdr(m, off2, &iih, ICMP_MINLEN, + if (!pf_pull_hdr(m, off2, iih, ICMP_MINLEN, NULL, reason, pd2.af)) { DPFPRINTF(PF_DEBUG_MISC, ("pf: ICMP error message too short i" @@ -6509,12 +6509,13 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif return (PF_DROP); } - icmpid = iih.icmp_id; - pf_icmp_mapping(&pd2, iih.icmp_type, + icmpid = iih->icmp_id; + pf_icmp_mapping(&pd2, iih->icmp_type, &icmp_dir, &multi, &virtual_id, &virtual_type); + pd2.dir = icmp_dir; ret = pf_icmp_state_lookup(&key, &pd2, state, m, - pd->dir, kif, virtual_id, virtual_type, + pd2.dir, kif, virtual_id, virtual_type, icmp_dir, &iidx, PF_ICMP_MULTI_NONE); if (ret >= 0) return (ret); @@ -6528,10 +6529,10 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif if (PF_ANEQ(pd2.src, &nk->addr[pd2.sidx], pd2.af) || (virtual_type == htons(ICMP_ECHO) && - nk->port[iidx] != iih.icmp_id)) + nk->port[iidx] != iih->icmp_id)) pf_change_icmp(pd2.src, (virtual_type == htons(ICMP_ECHO)) ? - &iih.icmp_id : NULL, + &iih->icmp_id : NULL, daddr, &nk->addr[pd2.sidx], (virtual_type == htons(ICMP_ECHO)) ? nk->port[iidx] : 0, NULL, @@ -6547,7 +6548,7 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif m_copyback(m, off, ICMP_MINLEN, (caddr_t)&pd->hdr.icmp); m_copyback(m, ipoff2, sizeof(h2), (caddr_t)&h2); - m_copyback(m, off2, ICMP_MINLEN, (caddr_t)&iih); + m_copyback(m, off2, ICMP_MINLEN, (caddr_t)iih); } return (PF_PASS); break; @@ -6555,9 +6556,9 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif #endif /* INET */ #ifdef INET6 case IPPROTO_ICMPV6: { - struct icmp6_hdr iih; + struct icmp6_hdr *iih = &pd2.hdr.icmp6; - if (!pf_pull_hdr(m, off2, &iih, + if (!pf_pull_hdr(m, off2, iih, sizeof(struct icmp6_hdr), NULL, reason, pd2.af)) { DPFPRINTF(PF_DEBUG_MISC, ("pf: ICMP error message too short " @@ -6565,8 +6566,10 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif return (PF_DROP); } - pf_icmp_mapping(&pd2, iih.icmp6_type, + pf_icmp_mapping(&pd2, iih->icmp6_type, &icmp_dir, &multi, &virtual_id, &virtual_type); + + pd2.dir = icmp_dir; ret = pf_icmp_state_lookup(&key, &pd2, state, m, pd->dir, kif, virtual_id, virtual_type, icmp_dir, &iidx, PF_ICMP_MULTI_NONE); @@ -6594,10 +6597,10 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif if (PF_ANEQ(pd2.src, &nk->addr[pd2.sidx], pd2.af) || ((virtual_type == htons(ICMP6_ECHO_REQUEST)) && - nk->port[pd2.sidx] != iih.icmp6_id)) + nk->port[pd2.sidx] != iih->icmp6_id)) pf_change_icmp(pd2.src, (virtual_type == htons(ICMP6_ECHO_REQUEST)) - ? &iih.icmp6_id : NULL, + ? &iih->icmp6_id : NULL, daddr, &nk->addr[pd2.sidx], (virtual_type == htons(ICMP6_ECHO_REQUEST)) ? nk->port[iidx] : 0, NULL, @@ -6615,7 +6618,7 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif (caddr_t)&pd->hdr.icmp6); m_copyback(m, ipoff2, sizeof(h2_6), (caddr_t)&h2_6); m_copyback(m, off2, sizeof(struct icmp6_hdr), - (caddr_t)&iih); + (caddr_t)iih); } return (PF_PASS); break;