From nobody Thu Sep 19 13:02:54 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 4X8bKV4Qkzz5WY92; Thu, 19 Sep 2024 13:02:54 +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 4X8bKV3qDPz4plR; Thu, 19 Sep 2024 13:02:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726750974; 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=QM1JuxaNON0LbyUAlvUpaLVrl6NQDtl0MhSwkNe5HxI=; b=EP+WebIy4axBouhGHZ07BVb3HVIx+QTd00G+gn7oJGKLcy/ugWIwnGIKqLmx3QOX9GsUwh h5R5klUICtSPYgFpt98QCorIAs6eKo0/zwMF/9teFWZXcWfU2t9zv49hKxP1mr3NjmkHQW JfOr4qf3Vq0t2oD24a2A0bTDHLbQZGYXWXU5p2Oy/xjOar+unzmnBlVdSDpM2ZjSX0+Cky bRYAQ7K1qzhTCxTAaYvmInaRazctbj43fVrKZF7UwxjUJaSfWyuX9o7mnrGm5vQl3BoJoH 6I5Kd5A1fB3h9zlm9avet1BCqyljXsImSymFq1+5yXf4VEeOwxlAjtFXI1g8mw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726750974; a=rsa-sha256; cv=none; b=n6iZIF7Z63FiIkFtaqseWidoJFUvRDrj4JkxI4LAPJq11ALtRa2xtKuidlvcMRn3dCtL3q 7WRSNd42WYusxsWev3OFTF/0aaWBjpRyOfESo5ueUB5Yih2yrqzdi1JLfVL/tBNgDBew6E hv6M089fhWn08bro4IHrbLCY6IlE0tCUswxKui2hIyM5jMxlMRF1c7qPtc5boYf2MPPaJQ muNyz6qrgArzQ9DwxDSomWHVLSM+jVWkz2rsnpSQkWbSvnyVNdu41lDGnkfuMNysVMRk9V FcxO/IKM1NvtIu+LrAGn58gznTZKJsNBVGh+05AifsQpym+/Ye/LO+BFI5ElDw== 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=1726750974; 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=QM1JuxaNON0LbyUAlvUpaLVrl6NQDtl0MhSwkNe5HxI=; b=pLxZO8+WFiZa4QSWqfZBGv/DTzhKjNsxQVLm2aHHXhC8GfejU2tMjyYURqQuD43Al9GXAV DT/4qx8p1PXszd8yDFzggpgbMzU+A8DctiLjBxq3jmBHA10jFDSN3IB97uGo/O5VM8XmMp gcA9Gsy4rBQIcjl3z/upVz04br8qkY6Cys+T3LktpIK6UYiI3/nPIkoIq9HN58ytVhXSio S7N9qUs36ZLwltKlcxHEhaVcScx/87sSbTafW5BF/NVMyxyHd2sPVVXA0SOUOsIqcCRkoJ O+mX3vXR5MLftanzii1p7NJfO58ZAy65v2Udu/h498CpZjtS+9PW+k0f9IUPGQ== 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 4X8bKV3R0Sz16W8; Thu, 19 Sep 2024 13:02:54 +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 48JD2sim099609; Thu, 19 Sep 2024 13:02:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JD2sut099606; Thu, 19 Sep 2024 13:02:54 GMT (envelope-from git) Date: Thu, 19 Sep 2024 13:02:54 GMT Message-Id: <202409191302.48JD2sut099606@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: 84b57a4c5b84 - releng/14.1 - 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/14.1 X-Git-Reftype: branch X-Git-Commit: 84b57a4c5b848d44ec0918c28d8c27bec948a151 Auto-Submitted: auto-generated The branch releng/14.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=84b57a4c5b848d44ec0918c28d8c27bec948a151 commit 84b57a4c5b848d44ec0918c28d8c27bec948a151 Author: Kristof Provost AuthorDate: 2024-08-14 09:29:30 +0000 Commit: Mark Johnston CommitDate: 2024-09-19 12:55:09 +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 46c4fc50d3012ca3c8756df243589add36b70830) --- sys/netpfil/pf/pf.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index edfa7a450054..43f32f673842 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -342,7 +342,7 @@ static int pf_test_state_udp(struct pf_kstate **, 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 **, struct pfi_kkif *, struct mbuf *, int, void *, struct pf_pdesc *, u_short *); @@ -6582,7 +6582,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; @@ -6619,7 +6620,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): ", @@ -6677,7 +6679,7 @@ pf_test_state_icmp(struct pf_kstate **state, 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) { @@ -6685,7 +6687,7 @@ pf_test_state_icmp(struct pf_kstate **state, 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 @@ -6769,6 +6771,7 @@ pf_test_state_icmp(struct pf_kstate **state, struct pfi_kkif *kif, int off2 = 0; pd2.af = pd->af; + pd2.dir = pd->dir; /* Payload packet is from the opposite direction. */ pd2.sidx = (pd->dir == PF_IN) ? 1 : 0; pd2.didx = (pd->dir == PF_IN) ? 0 : 1; @@ -7090,10 +7093,9 @@ pf_test_state_icmp(struct pf_kstate **state, 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); @@ -7146,10 +7148,9 @@ pf_test_state_icmp(struct pf_kstate **state, 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) { @@ -7158,7 +7159,7 @@ pf_test_state_icmp(struct pf_kstate **state, 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