From nobody Thu Sep 19 13:03:30 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 4X8bLB5Q8sz5WYX7; Thu, 19 Sep 2024 13:03:30 +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 4X8bLB33Mbz4rVX; Thu, 19 Sep 2024 13:03:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726751010; 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=pJfsHvc5qJnSv2v/iuBCtccqnOYCttnQ4XfInHChPI0=; b=iGQiw6VMBw9EKHRJANhD/ozfMaa7/QqGNJhmpz9tKbjhwXQAdZXSaUMs/K1L6CTtiVRj7m gJ6wdPkh/pkMo8yjpT100FgqWtZNW1QjrM7QQIS7IJ1PP+vZxigPVGbeabywc6E/KcfxIO z3BncyoDvJHsq11JVLi1ALlsssFNQb90ynUCwIDHItF7eccZYdpNduAJTke0dtCE9LkOia 7tFU39oL5eI5sdrW6I0O5hAMmuKnfRLdq2hAdAGwmJ8Tz8hlxZfBXkJqRVSwWTipt6e+zw 5S1dyjSmBOwRIK6peBBRGTgIyoTlV3YN0TUAOc/raVlcklvd0KpKDBJfCisqpA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726751010; a=rsa-sha256; cv=none; b=QyZiWrk54i9dsidNTREFTTWwysEa/w+E8sGwLmCpMqb5sJFN0WecQte7fmhcR1lfahP9ny tWyYe92Ou4rbfzx3dZkZg7qV0tB/uZdpK63BY/nTVVMNCNrmTSuUjbOX8HWAVa8vc/1aJT 6XJiAR0T7x17Q/QhZ040G1wbHsQByQoOys/rFfSigw1Qwb3H284DOOF7c042QFYQGgvpyc VNWOs0PUAWIFc7kzriD7zmLPOp/RW/KyHaoGI3X7qJPUVghlx8d1EjLrdSyRfD2Wq9fAdr ffzAKHgMfs4UnRVzWv9jbKwxkWxlXTe0CCfoKwyC/xsOJ2YQqazdoLHGSiZjRA== 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=1726751010; 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=pJfsHvc5qJnSv2v/iuBCtccqnOYCttnQ4XfInHChPI0=; b=CE7Nfy3EOcm0P++iMNqTcRKWaGFErRSiZPe6DQwzH9ayDHTl4ZHgmtMyw+CkOw8Eze5ra8 FfEUXiJjOWLI4ODSOV9CkJ+YVu3kU4MEUJYtq0WttYEuNbhc8DW84cXD2btBsRib/aqGyT mHHcsjz+zvUn/gNPYPq/zTb0LWalfKPDVzGd7Ch88TeqjHuO+477NElix0Pu2EwfsltUYU yb0I0cZmOAyow5nLns7wZRvRgKnvDtMfDcWlO2csscTASS+8BI0/LPrJKT11ZmDYpecCyG XTeyuBfax/+1/bk7NFP8BLlf1rMqGGEfeE3Jv2LkvljfM6L8gTtBoW8xW+4R3Q== 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 4X8bLB2d5Xz15tr; Thu, 19 Sep 2024 13:03:30 +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 48JD3Ugr000458; Thu, 19 Sep 2024 13:03:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JD3UEE000455; Thu, 19 Sep 2024 13:03:30 GMT (envelope-from git) Date: Thu, 19 Sep 2024 13:03:30 GMT Message-Id: <202409191303.48JD3UEE000455@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: 413ae023b056 - releng/14.0 - pf: rework pf_icmp_state_lookup() failure mode 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.0 X-Git-Reftype: branch X-Git-Commit: 413ae023b0563b7d51ab7aa1d69900886db66497 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=413ae023b0563b7d51ab7aa1d69900886db66497 commit 413ae023b0563b7d51ab7aa1d69900886db66497 Author: Kristof Provost AuthorDate: 2024-08-30 11:36:39 +0000 Commit: Mark Johnston CommitDate: 2024-09-19 12:58:55 +0000 pf: rework pf_icmp_state_lookup() failure mode If pf_icmp_state_lookup() finds a state but rejects it for not matching the expected direction we should unlock the state (and NULL out *state). This simplifies life for callers, and also ensures there's no confusion about what a non-NULL returned state means. Previously it could have been left in there by the caller, resulting in callers unlocking the same state twice. Approved by: so Security: FreeBSD-EN-24:16.pf MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 0578fe492284ded4745167060be794032e6e22f0) (cherry picked from commit 38f74de7184ac3ad7acc48055551aaa9ec9cded9) --- sys/net/pfvar.h | 4 ++-- sys/netpfil/pf/pf.c | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 4edbf0c51ff8..f24103c25960 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -359,8 +359,8 @@ struct pfi_dynaddr { mtx_unlock(_s->lock); \ } while (0) #else -#define PF_STATE_LOCK(s) mtx_lock(s->lock) -#define PF_STATE_UNLOCK(s) mtx_unlock(s->lock) +#define PF_STATE_LOCK(s) mtx_lock((s)->lock) +#define PF_STATE_UNLOCK(s) mtx_unlock((s)->lock) #endif #ifdef INVARIANTS diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 5a7a6563d355..8ff0fbb3c4ae 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -6189,6 +6189,8 @@ pf_icmp_state_lookup(struct pf_state_key_cmp *key, struct pf_pdesc *pd, pf_print_state(*state); printf("\n"); } + PF_STATE_UNLOCK(*state); + *state = NULL; return (PF_DROP); } return (-1); @@ -6241,15 +6243,16 @@ pf_test_state_icmp(struct pf_kstate **state, struct pfi_kkif *kif, kif, virtual_id, virtual_type, icmp_dir, &iidx, PF_ICMP_MULTI_NONE, 0); if (ret >= 0) { + MPASS(*state == NULL); if (ret == PF_DROP && pd->af == AF_INET6 && icmp_dir == PF_OUT) { - if (*state != NULL) - PF_STATE_UNLOCK((*state)); ret = pf_icmp_state_lookup(&key, pd, state, m, off, pd->dir, kif, virtual_id, virtual_type, icmp_dir, &iidx, multi, 0); - if (ret >= 0) + if (ret >= 0) { + MPASS(*state == NULL); return (ret); + } } else return (ret); } @@ -6656,8 +6659,10 @@ pf_test_state_icmp(struct pf_kstate **state, struct pfi_kkif *kif, ret = pf_icmp_state_lookup(&key, &pd2, state, m, off, pd2.dir, kif, virtual_id, virtual_type, icmp_dir, &iidx, PF_ICMP_MULTI_NONE, 1); - if (ret >= 0) + if (ret >= 0) { + MPASS(*state == NULL); return (ret); + } /* translate source/destination address, if necessary */ if ((*state)->key[PF_SK_WIRE] != @@ -6712,16 +6717,17 @@ pf_test_state_icmp(struct pf_kstate **state, struct pfi_kkif *kif, pd->dir, kif, virtual_id, virtual_type, icmp_dir, &iidx, PF_ICMP_MULTI_NONE, 1); if (ret >= 0) { + MPASS(*state == NULL); if (ret == PF_DROP && pd2.af == AF_INET6 && icmp_dir == PF_OUT) { - if (*state != NULL) - PF_STATE_UNLOCK((*state)); ret = pf_icmp_state_lookup(&key, &pd2, state, m, off, pd->dir, kif, virtual_id, virtual_type, icmp_dir, &iidx, multi, 1); - if (ret >= 0) + if (ret >= 0) { + MPASS(*state == NULL); return (ret); + } } else return (ret); }