From nobody Thu Sep 19 13:04:01 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 4X8bLn5lfqz5WYZs; Thu, 19 Sep 2024 13:04: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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X8bLn3r8Jz4sn1; Thu, 19 Sep 2024 13:04:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726751041; 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=X/MWeINaGXS/H0h1WFBqTGIhfBqCyucp7O5HqGIMK3k=; b=Rw8lkbh7RveDV/hC7eZH1zEoNoDHN0c+wlVCo6dxqzK48xfYhyqCjg8Yf2BmnQqTqTds35 Kom5/yyhKevjR55mJQGM7o1OpYsIozPR+NNXsRI0jUCRwUOt1lWcwxkL4cWcd2a/OoSmjZ naGMk86SolvvD76pvW01SPC1y87SMGs5OGUH12m/AUmEcVhd2BksrIiTUUEiMsdLB+JYjE 4xwiHwCpEQPdQzyQrsX5eJ1zhkNA64cmKUpwHvPpdaAKIYf9Qwjg2i1dUqzYex/O+LQvWa LmmzrSAFKw4D0B+v/jnUy0aa28R7fh/irLHJimi0t1Naiunbv8VksN8ut1Z3cA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726751041; a=rsa-sha256; cv=none; b=v49W2kOgF8fzOgl5DpZRI7bfKSUBRKB7tdTMiaOR0PVLeATbVMXJDSh4jICxC+vqv2yMYE Ay9DF11sxNny/cfIb9XoJ46hsSMbUsmgG5zXMiA8i25iahhZ6iIGaX08Ivi3CRUtpxihWE j5cZFPcGvDJmtD3SippLyNelSjMPYUyUqZcbYh4RYF60dboSac9YhxY0XgMBFvUsSfExrE BExWFh05ZE3oQJ3K2uilJLiFw3Aptj7P3OSfOFNWvVDCvWWw9r9t+MnIvYMYQm1HDZAKH8 y33Wa3MbDEmJdQjWIQme8V2ewe9nqW/LYCnNnLQVCY6qaxTHmIVg/1Hl1YugXQ== 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=1726751041; 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=X/MWeINaGXS/H0h1WFBqTGIhfBqCyucp7O5HqGIMK3k=; b=V6tQdfDbfeD0y/ebKvV1J2uMRQCUipFO5LmGdaBvthQSObQwcnA1HbTJ/MssN2Uhv+vuvj qTgbODJxSngbEOq86rc3T8dBh37cCt0JGAgOQpeDi3D4K80B/XQkbLb613enTcMhAgcrSE pFNcKToOlgK0P8Doqql4eCkCWxOlkYb7dn1/nzBi1X1oQq+Dbo2N9jzqEoaD+iDAjBDTLs 5xg4Kw4u494sl8gTtyUdchtMBCpxkSsnpD50Rew5QHmk5L4zT4KWP/WeF9xb3MivZ4DWvW L68XYrMe5J/3xEJ0qdj1xx+Y2usVQCjSHtJFzAaxUJVPiQQ3w8O6UjyF6I5PCQ== 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 4X8bLn39lCz168T; Thu, 19 Sep 2024 13:04:01 +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 48JD418x000897; Thu, 19 Sep 2024 13:04:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JD41jP000894; Thu, 19 Sep 2024 13:04:01 GMT (envelope-from git) Date: Thu, 19 Sep 2024 13:04:01 GMT Message-Id: <202409191304.48JD41jP000894@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 36265a707dc5 - releng/13.3 - pf: invert direction for inner icmp state lookups 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.3 X-Git-Reftype: branch X-Git-Commit: 36265a707dc51189843498e059361010ea3c9718 Auto-Submitted: auto-generated The branch releng/13.3 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=36265a707dc51189843498e059361010ea3c9718 commit 36265a707dc51189843498e059361010ea3c9718 Author: Kristof Provost AuthorDate: 2024-08-14 09:29:30 +0000 Commit: Mark Johnston CommitDate: 2024-09-19 13:00:48 +0000 pf: invert direction for inner icmp state lookups (e.g. traceroute with icmp) ok henning, jsing Also extend the test case to cover this scenario. Approved by: so Security: FreeBSD-EN-24:16.pf PR: 280701 Obtained from: OpenBSD MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 89f6723288b0d27d3f14f93e6e83f672fa2b8aca) (cherry picked from commit 5f3f07397a7909e8f9449d1aa0b465159cbf0d60) --- sys/netpfil/pf/pf.c | 21 +++++++++++---------- tests/sys/netpfil/pf/icmp.sh | 4 +++- tests/sys/netpfil/pf/icmp6.sh | 4 +++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 48db6512eee1..247a20bf953b 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -321,7 +321,7 @@ static int pf_test_state_udp(struct pf_kstate **, int, int pf_icmp_state_lookup(struct pf_state_key_cmp *, struct pf_pdesc *, struct pf_kstate **, struct mbuf *, int, struct pfi_kkif *, u_int16_t, u_int16_t, - int, int *, int); + int, int *, int, int); static int pf_test_state_icmp(struct pf_kstate **, int, struct pfi_kkif *, struct mbuf *, int, void *, struct pf_pdesc *, u_short *); @@ -5991,7 +5991,8 @@ pf_multihome_scan_asconf(struct mbuf *m, int start, int len, int pf_icmp_state_lookup(struct pf_state_key_cmp *key, struct pf_pdesc *pd, struct pf_kstate **state, struct mbuf *m, int direction, struct pfi_kkif *kif, - u_int16_t icmpid, u_int16_t type, int icmp_dir, int *iidx, int multi) + u_int16_t icmpid, u_int16_t type, int icmp_dir, int *iidx, int multi, + int inner) { key->af = pd->af; key->proto = pd->proto; @@ -6028,7 +6029,8 @@ pf_icmp_state_lookup(struct pf_state_key_cmp *key, struct pf_pdesc *pd, /* Is this ICMP message flowing in right direction? */ if ((*state)->rule.ptr->type && - (((*state)->direction == direction) ? + (((!inner && (*state)->direction == direction) || + (inner && (*state)->direction != direction)) ? PF_IN : PF_OUT) != icmp_dir) { if (V_pf_status.debug >= PF_DEBUG_MISC) { printf("pf: icmp type %d in wrong direction (%d): ", @@ -6086,7 +6088,7 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif */ ret = pf_icmp_state_lookup(&key, pd, state, m, pd->dir, kif, virtual_id, virtual_type, icmp_dir, &iidx, - PF_ICMP_MULTI_NONE); + PF_ICMP_MULTI_NONE, 0); if (ret >= 0) { if (ret == PF_DROP && pd->af == AF_INET6 && icmp_dir == PF_OUT) { @@ -6094,7 +6096,7 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif PF_STATE_UNLOCK((*state)); ret = pf_icmp_state_lookup(&key, pd, state, m, pd->dir, kif, virtual_id, virtual_type, - icmp_dir, &iidx, multi); + icmp_dir, &iidx, multi, 0); if (ret >= 0) return (ret); } else @@ -6178,6 +6180,7 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif int off2 = 0; pd2.af = pd->af; + pd2.dir = pd->dir; /* Payload packet is from the opposite direction. */ pd2.sidx = (direction == PF_IN) ? 1 : 0; pd2.didx = (direction == PF_IN) ? 0 : 1; @@ -6499,10 +6502,9 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif 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, pd2.dir, kif, virtual_id, virtual_type, - icmp_dir, &iidx, PF_ICMP_MULTI_NONE); + icmp_dir, &iidx, PF_ICMP_MULTI_NONE, 1); if (ret >= 0) return (ret); @@ -6555,10 +6557,9 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif 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); + icmp_dir, &iidx, PF_ICMP_MULTI_NONE, 1); if (ret >= 0) { if (ret == PF_DROP && pd->af == AF_INET6 && icmp_dir == PF_OUT) { @@ -6567,7 +6568,7 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, struct pfi_kkif *kif ret = pf_icmp_state_lookup(&key, pd, state, m, pd->dir, kif, virtual_id, virtual_type, - icmp_dir, &iidx, multi); + icmp_dir, &iidx, multi, 1); if (ret >= 0) return (ret); } else diff --git a/tests/sys/netpfil/pf/icmp.sh b/tests/sys/netpfil/pf/icmp.sh index 16c4123b8dfe..f4c8ec5e5836 100644 --- a/tests/sys/netpfil/pf/icmp.sh +++ b/tests/sys/netpfil/pf/icmp.sh @@ -108,7 +108,9 @@ ttl_exceeded_body() jexec nat pfctl -e pft_set_rules nat \ "nat on ${epair_int}b from 198.51.100.0/24 -> (${epair_int}b)" \ - "pass" + "block" \ + "pass inet proto udp" \ + "pass inet proto icmp icmp-type { echoreq }" # Sanity checks atf_check -s exit:0 -o ignore \ diff --git a/tests/sys/netpfil/pf/icmp6.sh b/tests/sys/netpfil/pf/icmp6.sh index c54b54c20a87..b9b60a484afc 100644 --- a/tests/sys/netpfil/pf/icmp6.sh +++ b/tests/sys/netpfil/pf/icmp6.sh @@ -120,7 +120,9 @@ ttl_exceeded_body() jexec nat pfctl -e pft_set_rules nat \ "nat on ${epair_int}b from 2001:db8:3::/64 -> (${epair_int}b:0)" \ - "pass" + "block" \ + "pass inet6 proto udp" \ + "pass inet6 proto icmp6 icmp6-type { neighbrsol, neighbradv, echoreq }" # Sanity checks atf_check -s exit:0 -o ignore \