From nobody Thu Sep 19 13:04:05 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 4X8bLt1rmzz5WYGW; Thu, 19 Sep 2024 13:04:06 +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 4X8bLt0g7Yz4t2t; Thu, 19 Sep 2024 13:04:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726751046; 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=wNE4k91HyvhHZ+uIeWliDpNw/eeHqzRB1EC+7yp+Grs=; b=N4diy85nQY/9/pj3uYGw/fqFmD7862mScVmHh9lzCllDJW8K8bUSYDxhw3U+maoaXbP/Nt +c3FAXRE00q03909EgUESMBngz5XX8vMT0qqoYVGYkw/6l3WMLrizWx3NdIFbwGDtQ3BKi ivUEBjXxlbDQR18r/C6s8Xc8mu2AhQQsjW0+GNvhDJcSa84Z01viy5VlRbeAkHYNP8AAl3 7xjuws2sXzGVes7SSCb5WbJd6vesLTvzj1xp4Dg0C+7csGu+zVwxaMdqLqZvcJ8czK0MhZ Pw1ogxyUkBLRfAB7z9j7ZWkJ/aKO1omCoft7plZ1QwkckVCweNnZVnd6PkKrlA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726751046; a=rsa-sha256; cv=none; b=FYyA+MykZhhmeRyiumWOaO9Qhaz61u3+sIcrb+a/QwYO7P7sh4q456+e7EqPKF9PRUGkIR f9TrtidydJStdrSIt+qvDBG+/NJU5WX2ge/lf2KRK267heEPzEa3/Amm957enmX8DMCYEw KTGTSI/Psvw5OGLVH2WdBPmf/kmb5ZWaUKJrLq1Dljd6zn66QxcfeFK/lKjO93HAiLQ/95 GEn93pD1F6pt64M58+96hE0o2hgK/zVLaMvz38Wop246jEFgp7xMdM+d8BOtwY2MfqpOqu yXts/GF19rNr09plwlK+98188KaIkf75ywkjt/CST8ibhVMQm66g12jb6zZs8A== 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=1726751046; 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=wNE4k91HyvhHZ+uIeWliDpNw/eeHqzRB1EC+7yp+Grs=; b=czodg9kOOaD685udVa1qKhixWa15Hbqw11PGeZNMGWz4GUt2m7H3WIGY5u11f5Lz1j0tpQ 8HR3a8r5iAavwU3ar7xeJhgL1L68XwUfJFmH6PZE4xnpyrdgQ+uSfnYU9VtdUiluh97nU+ ZmbK2btjZ8BvJo/M9huENPMusgN1+oy/c/BaZRph6Lcw80iRphFgOu4uqhKaWzkBV/0sCi 1mLu9eMOP4mutucSFJ9Nj0TWK0XQHKoEtQFzS0Ty4p76/KLbDeMVNYx/+DxjkQhqXQOv3P Pqu6wCxR169D599Ct2yoYBMDVCzqyKvlODfW9WukAHtpk3gpJv045O4QKQ7iXw== 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 4X8bLt0HDTz16Jb; Thu, 19 Sep 2024 13:04:06 +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 48JD45P7001129; Thu, 19 Sep 2024 13:04:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JD45Cj001126; Thu, 19 Sep 2024 13:04:05 GMT (envelope-from git) Date: Thu, 19 Sep 2024 13:04:05 GMT Message-Id: <202409191304.48JD45Cj001126@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: ea9257bcd0e1 - releng/13.3 - 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/13.3 X-Git-Reftype: branch X-Git-Commit: ea9257bcd0e1ae178fa4266017bd1db7dae4e780 Auto-Submitted: auto-generated The branch releng/13.3 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ea9257bcd0e1ae178fa4266017bd1db7dae4e780 commit ea9257bcd0e1ae178fa4266017bd1db7dae4e780 Author: Kristof Provost AuthorDate: 2024-08-30 11:36:39 +0000 Commit: Mark Johnston CommitDate: 2024-09-19 13:01:45 +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 d6e5f8643d37e925aa51fc8224cfc05aba0813f7) --- 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 b3b8074cbe17..0f2ad39fec94 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -330,8 +330,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 100302ab2ca5..27918a6fd909 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -6089,6 +6089,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); @@ -6141,15 +6143,16 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, 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); } @@ -6556,8 +6559,10 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, 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] != @@ -6612,16 +6617,17 @@ pf_test_state_icmp(struct pf_kstate **state, int direction, 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); }