From nobody Thu Sep 19 13:02:58 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 4X8bKb2QXhz5WYWK; Thu, 19 Sep 2024 13:02:59 +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 4X8bKb0jNCz4pmP; Thu, 19 Sep 2024 13:02:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726750979; 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=Fsq/bKquo9um0StxRFXs5NRn5Jes6upjBfZfCaFzx+A=; b=ps9P1zK6/UCFRAf23iUJlREuUkcg710f1foBcsl6QqxWu/EZryHOAWcaLIX2GrrQoztPBH CSaiKGzJq72/yMF5oI0dF1AvQaAKuDEeuF/VlCSRfisvNJK3raLZKNdRaS8HQm9PZ+SPNo opi4E0VsPwcVc7IWkBYSYWm2kWHc5gG492Uu1A2QjdT48ztz/moGdXaX2GnwkXKamnTygN sOp47U9UPj3p3NlzqBNUl2TpkoL3Wt71mcgF+dvMAMsTR/EoLZeovjiezYOqPhCrwYhb71 QyOFbq+ZYO8uZYIuY5gDovpFHEMJJaGMzKdQgnBVAkVrc89VhPlBStfzry0U4g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726750979; a=rsa-sha256; cv=none; b=j1yRVMt+YDZVh5C9M9XQgEl/QTvkpgKRg+l9GESzASRCQfuGDqbeOV4eO+H+bvN5Q6h6dQ DiOifXglJ+wrbdEHyP097fmmWEj1QhsT/xHJO4NoZ9Le6b1EWrB1GeHa9VYXo9Hubj4rut AvxkWOTnLD3KaIUKG8ocnlZZkzN7Gz9ddASbcFgzlmSBL0oquD/nyxpDDFHxwZuRM6F9Od 7Gpt/sUnTICp3bgjVoWjydkYsql0VTP9W5RjSWBARbOAxpKJLPrdLA8vlZgMay6DnF6Jw/ pmnMpwEBrvcvIdTmSCYE/wveXyT7VnJOwgjL6tm1M9ClNWYiZvXLfX3dfle8Tw== 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=1726750979; 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=Fsq/bKquo9um0StxRFXs5NRn5Jes6upjBfZfCaFzx+A=; b=ALgNamvZH9NRIeOXG0VVcXwxeUEcat0kGDTWaJ+fwsKlXtIzjBZneUQBCFeO+rwJKgOCgX r+1rSslPyeZS1Zm7AKzs53t/JpnRqmyB6LmfpVX4qWDI+UA8gFqdMfoZ6jYokqGqmulpzM cm+UE9YhHRye285IfyoVN3+q+CXXFioXApAo1uOA4VkUe7gAjWt/Q0kAbP6hzaCsFnibXd R6FfcP9/eVlX25bufxN8NHJM5PaguxC++O5i2YcWXvOgrlDbGSKQ/fmakVGjNzzb+k0RaH KZzHy2588XkKJ89uEbzWAWlgYC/J9qPqWwu0z6aHZrCmuYstL7RVtNicDlyjrQ== 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 4X8bKb0JGbz16Bg; Thu, 19 Sep 2024 13:02:59 +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 48JD2wiD099829; Thu, 19 Sep 2024 13:02:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JD2wOG099826; Thu, 19 Sep 2024 13:02:58 GMT (envelope-from git) Date: Thu, 19 Sep 2024 13:02:58 GMT Message-Id: <202409191302.48JD2wOG099826@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: 1e965d5399e1 - releng/14.1 - 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.1 X-Git-Reftype: branch X-Git-Commit: 1e965d5399e18c42441c90778333a1a5f24a105c Auto-Submitted: auto-generated The branch releng/14.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1e965d5399e18c42441c90778333a1a5f24a105c commit 1e965d5399e18c42441c90778333a1a5f24a105c Author: Kristof Provost AuthorDate: 2024-08-30 11:36:39 +0000 Commit: Mark Johnston CommitDate: 2024-09-19 12:55: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 6a01f3eb6988..676cf05cab8d 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 ed278a5526be..7c31f1fc0fd0 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -6680,6 +6680,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); @@ -6732,15 +6734,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); } @@ -7147,8 +7150,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] != @@ -7203,16 +7208,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); }