From nobody Wed May 08 11:20:01 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 4VZCNf3Kt3z5KsmD; Wed, 08 May 2024 11:20:02 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VZCNf11g6z49Zq; Wed, 8 May 2024 11:20:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715167202; 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=JAj0U1siOFzHL2z991jFmn2R48X/PnRixq7cyBOgGnc=; b=ZwSs1ckEsJBJmO9rmajl1C0LzImwb9cgMHGvT9aJTX0TIMpDiVscCiknFM5hNSig4MDLvA aNqso/tyClDBGCMPRax0ek/euMDk1aPXExNJOMKHRwVx5OoonYWyddWfKkm/JUvVjKOsyy 7tjbd6twJXQDtQ8m7Ohgmrhyzt7FGZIo2NM7OMFjL2NMlxOqJdhevJfyBVe2lWBy+sR/T5 0QhUlTqvV+UntgjXtSn5Xj3r11QiMM12O5AXxXz6V/FW+G69rPecs6JcBifyvb9bg8j1Vb o8c0zGqPhIquaWIPgGhJXZZUoP7HKS7b2zxJRbFkh9sOfnzf6lC0ryL6wS/LyQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715167202; a=rsa-sha256; cv=none; b=JBkiHYrqBzIbTa6QErJy/vsQ8XF4Bwa+7vW+OUGdjbWZomqTVq6zc3a8FeeRHyVcquuTYz 9UkdhNNSrduy/KKzybbHGZJwlGPGaVyB4xGLDZFoG+haNtMEI8pCn1HzeCHturgUsa4WGG r3jcLG89L5nqKVMxA+ypDhzjwrYbW51CTfPdj2wa0Yfj39XsEXmABKXPmlCurqlgLjONMN aqOFjJbZuzramN2S94zcDzzJ47XD69hcymsji5mSQmrhw88lJCJVcMS0s++9XwY2KiqD81 6v/TB0UvgnMeNASXgyxWWnpMbFWSb0ULFYAZXK20H1spsNJchTgioq14TAb9Dg== 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=1715167202; 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=JAj0U1siOFzHL2z991jFmn2R48X/PnRixq7cyBOgGnc=; b=AswD/zGo/4p1bvRHdCxDXNEh8jee7+Av/IR8L/9+M6jAg3BgSLRFvmC+lxvZDuDOhBQiRP DThZgsnzrKHGEApjep925RZwpg2LxL8liszcL7+a9EQI3C7cPVx/NxjUIinld6SJAZPbwl GUm07eCtD4xVBj8Ey/dO5s9XyNfuGMXs6+bVAhkabKmUIBjXseNEafJlLlWICu0H7Ul0vN BL/qywisONFB0W6Jj9hnmpQJ+pvFJympLOQqLFOLba5RuYkhEyPrAFv2ZHdALQnwDKvDZH MBvG+Vwu0BuO3eeCA3P9mWSWnG6sccEZZx73v1VLamfivOnWQhQn5Avxh0yggQ== 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 4VZCNf0dxdzN01; Wed, 8 May 2024 11:20:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 448BK1Yr096839; Wed, 8 May 2024 11:20:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 448BK1Ru096835; Wed, 8 May 2024 11:20:01 GMT (envelope-from git) Date: Wed, 8 May 2024 11:20:01 GMT Message-Id: <202405081120.448BK1Ru096835@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 301ec2cebb6a - main - pf: always mark states as unlinked before detaching them 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/main X-Git-Reftype: branch X-Git-Commit: 301ec2cebb6a3e472af39eb7b98c3b7ff88e04b0 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=301ec2cebb6a3e472af39eb7b98c3b7ff88e04b0 commit 301ec2cebb6a3e472af39eb7b98c3b7ff88e04b0 Author: Kristof Provost AuthorDate: 2024-05-06 07:43:49 +0000 Commit: Kristof Provost CommitDate: 2024-05-08 11:19:05 +0000 pf: always mark states as unlinked before detaching them Users have reported crashes in pf_test_state_udp() where at least one state key is NULL. That suggests that pf_detach_state() ran concurrently with pf_test_state_udp(). pf_test_state_udp() holds the state lock (aka the id lock), but pf_detach_state() does not. The intent is that detached states are not returned by STATE_LOOKUP/ pf_find_state(), as the state's timeout is set to PFTM_UNLINKED and thus pf_find_state() does not find the state. There are other paths to pf_detach_state() (outside of pf_unlink_state()) though, where we did not set the timeout to PFTM_UNLINKED. Fix those, and assert that the timeout is set correctly when we enter pf_detach_state(). MFC after: 1 week See also: https://redmine.pfsense.org/issues/15413 Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D45101 --- sys/netpfil/pf/pf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 0dd4da5f271a..195b5d49db7a 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1353,6 +1353,7 @@ keyattach: sk : NULL); printf("\n"); } + s->timeout = PFTM_UNLINKED; PF_HASHROW_UNLOCK(ih); KEYS_UNLOCK(); uma_zfree(V_pf_state_key_z, sk); @@ -1421,6 +1422,7 @@ pf_detach_state(struct pf_kstate *s) struct pf_keyhash *kh; NET_EPOCH_ASSERT(); + MPASS(s->timeout >= PFTM_MAX); pf_sctp_multihome_detach_addr(s); @@ -1552,6 +1554,7 @@ pf_state_insert(struct pfi_kkif *kif, struct pfi_kkif *orig_kif, break; if (cur != NULL) { + s->timeout = PFTM_UNLINKED; PF_HASHROW_UNLOCK(ih); if (V_pf_status.debug >= PF_DEBUG_MISC) { printf("pf: state ID collision: "