From nobody Thu Sep 05 07:35:39 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 4WzrkN1p8Sz5VWxg; Thu, 05 Sep 2024 07:35:40 +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 4WzrkM5K9jz4XsX; Thu, 5 Sep 2024 07:35:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725521739; 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=amof0GNTiKxqVD0W6TdA1UcSO1aoE35VCu6MBD+rS/I=; b=Fa9yuq1hNUX75JIKWjVeNMD4XGnkYkAkNHLcdZdbSXgVrcoZ+VibevMTYxCr4XGyQuyBZb hqF6U+pUX4upRHKZzhpEGGYNpm/Zag3YcAg6comtE5nIpjDoUO2rCCpVMAoMPbk/5d4dny GK+gGSwI1s8b+xWLwnz5IVfYw+Y2sBNDCnuOofV2GBteoWjhH5glgSH4NK5T8Btq9fCBhP +MQab1HbRrogwpwZK9te5dGnkXQpGILyw5l3q5CO8qzQ6ynDr2Df2+fc7HNAROU/de+4zb Rf7NLK5dZzjQGGV/y9kelwRA30SEJ2p2R8iCw+HvRjSUYxAx8NopgyVdkYJOjQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725521739; a=rsa-sha256; cv=none; b=Nw5xZG8F79Hbmhz90Us+TFms+Pi0oQP2zIEownBQLxAQZE5Oq43w5Iw672X8RZ/tKIZ1Rb QcjihJZ2Tktlvw9Iqt0D7oYwVZu2FKmaScdU+X804J0H3BFhgz/dgI7slGcBkQOnvrQ/Vy 4ntjzDvVFcnG76FW0O47IwxP0Lh0c3OxkZ6nK+2TKx0pRqqbR/L63gwwGQShxQ10txB9QU VHYbdHhJbs9BfG31/5IFsvpSQNWHUCFZHek7OBtgyRGaO8Vl89KyYidHiBuyxFA4xXdZpq z9SlBt6STJsr0FvgboeEOY6AhM1gkwrrwoNU6IcPnTFoEwACxkaey0SIPPFrsA== 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=1725521739; 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=amof0GNTiKxqVD0W6TdA1UcSO1aoE35VCu6MBD+rS/I=; b=N9lK4SUWpBZxPUALp6pQDyy1mhBklMDidlkNeYN/rz5H7POC92th1djldDIfaFJ1B/NyzQ 5KR1LUZEY25Zqx53+gquKEok09atora5KPZ33Y7Zxdc+wuWXn4VXtT1KBPBN/+FKnDRPqR Nck99DMmwABO/SjOBloLrkTe2d+GHb0rRf4odq3M1HJ8zZaqS4rmgfXoxkslfM60sLRRz+ mtC//V+KVRWXAwSD6CNZPKhRukuafxirQ261ikLqVI1ABJ7nLukTqORJdY6g6aT2GeDVo/ eqTqHk89+jTnX51nCEQpbE3ykf2HVVfEbLALJn8mefMlUytCwKzwnyTxnXWdkw== 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 4WzrkM4wyjzyvc; Thu, 5 Sep 2024 07:35:39 +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 4857ZdOW037224; Thu, 5 Sep 2024 07:35:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4857ZdUv037221; Thu, 5 Sep 2024 07:35:39 GMT (envelope-from git) Date: Thu, 5 Sep 2024 07:35:39 GMT Message-Id: <202409050735.4857ZdUv037221@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: e893ec49afb2 - releng/13.4 - 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/releng/13.4 X-Git-Reftype: branch X-Git-Commit: e893ec49afb2caf05a2c28df4434905fa4213537 Auto-Submitted: auto-generated The branch releng/13.4 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=e893ec49afb2caf05a2c28df4434905fa4213537 commit e893ec49afb2caf05a2c28df4434905fa4213537 Author: Kristof Provost AuthorDate: 2024-08-30 11:36:39 +0000 Commit: Kristof Provost CommitDate: 2024-09-05 07:35:12 +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) (cherry picked from commit d6e5f8643d37e925aa51fc8224cfc05aba0813f7) Approved-by: re (cperciva) --- 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 e6c2d1f290cf..66bdbf43e212 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 9c1aa4d0a77a..ccd6b54f7b37 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -6103,6 +6103,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); @@ -6155,15 +6157,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); } @@ -6570,8 +6573,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] != @@ -6626,16 +6631,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); }