From nobody Wed Sep 04 08:53:34 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 4WzGVk3qNCz5TSK5; Wed, 04 Sep 2024 08:53:34 +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 4WzGVk1LYWz4Xry; Wed, 4 Sep 2024 08:53:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725440014; 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=CAWSaO1YShihW36trFHB3EyMyVpOSpsfeVeqT99axxE=; b=pvEAr0nSB128Ao3xoTkWl8ve6mqBijfnAd3zLLe3imJ48CbwzierVnzOdqpL/gIV9HaFW6 WKPFYtUi0R+5Pqy27vR9mIUATs+m/UNNjxiMXDcE9eg2eNC+KVOxEBDcZc0Dpug4HagXgT YR875LgfK1UVAAqFIVNVgGolhFLZsAE/ES6W6tXrODIYC4RCgYJ+6bGxRUroHrO3SJ7AGo QcA+s49T9/n14U5Y37324TL61A+laWlfuEs7yjaH1g3+ghx6lw1i0XKd2tfUZdwdFF6sFO AZ6TUOldWYxHMaa6Agts/F7wYI3+EvImLwXPDCV7j8w9uHtUOlZ3e8CTqMLjeQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725440014; a=rsa-sha256; cv=none; b=wA0gSuza0zTy9VcxbT/uDnCqmfAn7jxygo3xbH2EMU9aXfBuuCNUeLe9GQnl8zTj2BtB8Y EE+aJspYACWLGpxlO2/pv54ltRi6++521aMA3C7FZb/PliH28bTszz0wGZKb0xqJsvZyZw hCqr8X5NdA3p1fQSTJAPtEeDzRY9L7fh+QideX8V52PyVKJq47grxH5UZxreZGHW9hsTYm 5gF/I7FRCbca2Wg29RlrQ319+YNsMVau0IJCLs4StoZfEgWbs8/otiWUyjxVIOINHtK8aU 094/fNtGLJaN5zMaG2fAqKugcRMBxMLPZmeOYcL4tOneDDoFkZnAgWVQ23tgCQ== 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=1725440014; 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=CAWSaO1YShihW36trFHB3EyMyVpOSpsfeVeqT99axxE=; b=YSrfIfFRpEPUr2cVcq2CmtGEIYglag5pqH2JFeFrPker1UeNEXVC20fdqVwhjY3MHFfrPk 3k339lKYFjVZwaYjsVIIV5mB17jP11xgGd+ZsupiQE6M50ldNWJ3gF2pBZN7fw9MSDQ+K+ WPoXeDmn9nEmsnbPbBfJdYqEmvNkLNQ+JYTMP+ZNVldaVK/E6ghaNXcG9Nup4vPOBJHPQP ZP6m6ZAzFWzNTzf+SarA2V/FhgFlln/US9dlY4no/oWjEopcJR46D4lIoIrbi758lockx0 rU2Hd7tNIiWsd1hS9nCI9xUCndO7dBmUjmQnISslV1CBUUkP69RzAsCfgViQfg== 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 4WzGVk0ys4zHnk; Wed, 4 Sep 2024 08:53:34 +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 4848rYOp005871; Wed, 4 Sep 2024 08:53:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4848rYpA005868; Wed, 4 Sep 2024 08:53:34 GMT (envelope-from git) Date: Wed, 4 Sep 2024 08:53:34 GMT Message-Id: <202409040853.4848rYpA005868@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: 38f74de7184a - stable/14 - 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 38f74de7184ac3ad7acc48055551aaa9ec9cded9 Auto-Submitted: auto-generated The branch stable/14 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=38f74de7184ac3ad7acc48055551aaa9ec9cded9 commit 38f74de7184ac3ad7acc48055551aaa9ec9cded9 Author: Kristof Provost AuthorDate: 2024-08-30 11:36:39 +0000 Commit: Kristof Provost CommitDate: 2024-09-04 08:38:15 +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. MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 0578fe492284ded4745167060be794032e6e22f0) --- 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 d33c747efa7e..290f339e7d00 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 e94856b011bf..e39abc7e7ad2 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -6704,6 +6704,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); @@ -6756,15 +6758,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); } @@ -7171,8 +7174,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] != @@ -7227,16 +7232,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); }