From nobody Mon Mar 27 08:16:37 2023 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 4PlQdK2zw5z41x3V; Mon, 27 Mar 2023 08:16:37 +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 4PlQdK2YJ1z4BP6; Mon, 27 Mar 2023 08:16:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679904997; 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=xJVCkcJjLOmf4ouqTdrtl8sksNUPK0jxUuoyz8tCvYk=; b=NC04yzTTm0KRhpbhTZfE5GR05XjNU9FIhfLU+sLhAXSsoc5KCpP/Achp+WvL3cIpcsoby7 KKMxPpzu3tizDHPKydhIHlJaMKk1HYa09HAPU7D1Y+r0HAbCRhZ7mUaUXYj9y7iztBJWl2 jZb8yxCl04GVJ17QM0eTRlFQ9QVwGgHZRIE//AJ4re0yaT5RdIFXe0nQ91GHZlROiJ48hk V5lzF8O/1b0Vy4k/g8NAQ7Y7udn/xbUyg7oIruxQpkfyYjWPAzi24c3ThrCYGsOo4VaBfP 8+3liGumGn0pAZvViKe+O6A4MgRRkAIAULvE9XBI60QHzF/uQRu0vGmtKKykLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679904997; 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=xJVCkcJjLOmf4ouqTdrtl8sksNUPK0jxUuoyz8tCvYk=; b=WNiIPqdaXQ1yHepx6uQ3t00d7MulA7XFb0C+KILNtsNHuIUif0FHP5U41ZChc6LxbCffAB IAqjEQ+95hjTnifm+H7yIy9zGtdXtDUq/4jM6g1FAm+p7hcXF49uEcY51piTiLp0bYI42p s6H5c0W5l0jWQ/eW28P/A4dHKql/Y09FtjOnkghzK8jc0Vua5PxCSdxFExkdwkxw5A9eCy MlhaMFdnTbJ3bdzFFpfn2KAF3wK/2kUlMmd8xl6YKdE+9REn9WLyP2++4WGrmmcrW6NEdS RFLysOUTv6qRhTi7ZXdKaiMEl5uqhAdHQ+AXN3X5ZqQp0mjt5kh7Ikt5LBhobg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679904997; a=rsa-sha256; cv=none; b=B3Np5RQFgAX4G9eAy+g8XPVJcrGHHf+GPyMQMT4DYYSZS0R9e4gmFtV9zUw7je4TVUOpnV oXMlEQiCvcMgYfbwEmUEUo6Ss+1nJEwsslpgXPLJPtrtq0sJh6kn832opVO2amT1Rwaxj5 cTh8I8zhnOA2IbBvRFHtfffNi1VsrMy1daL08gwJXiWtNH9dkJM2RxXWx5Ap/7ddr/326Z V9uh3ikrJyKoaK5+WPN8YiDQhJQz/FObj6zzFLqXArt5Uu6YX4aJ2a9l/9jDxshdr+Pmlj gHchqy25YU+ZF8UYqlJ1Ys8SJ6BLXZQcZxtSv+R6RfM9MtPsf6Zqw9qROd8usA== 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 4PlQdK1d2lzF3Q; Mon, 27 Mar 2023 08:16:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32R8GbZC045619; Mon, 27 Mar 2023 08:16:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32R8GbFZ045618; Mon, 27 Mar 2023 08:16:37 GMT (envelope-from git) Date: Mon, 27 Mar 2023 08:16:37 GMT Message-Id: <202303270816.32R8GbFZ045618@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: 09b7cab88f65 - stable/12 - pfsync: fix pfsync_undefer_state() locking 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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/12 X-Git-Reftype: branch X-Git-Commit: 09b7cab88f652e3a3682749e38c043d25dd7d0ed Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=09b7cab88f652e3a3682749e38c043d25dd7d0ed commit 09b7cab88f652e3a3682749e38c043d25dd7d0ed Author: Kristof Provost AuthorDate: 2023-03-20 13:29:55 +0000 Commit: Kristof Provost CommitDate: 2023-03-27 00:28:32 +0000 pfsync: fix pfsync_undefer_state() locking pfsync_undefer_state() takes the bucket lock, but could get called from places (e.g. from pfsync_update_state() or pfsync_delete_state()) where we already held the lock. As it can also be called from places where we don't yet hold the lock create new locked variant for use when the lock is already held. Keep using pfsync_undefer_state() where the lock must still be taken. PR: 268246 MFC after: 1 week Sponsored by: Rubicon Communications, LLC (Netgate) (cherry picked from commit 53247cdf12449e90f6736ae563e4cce8315c923f) --- sys/netpfil/pf/if_pfsync.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c index 8d90f76a3faa..6a67b8fe3d80 100644 --- a/sys/netpfil/pf/if_pfsync.c +++ b/sys/netpfil/pf/if_pfsync.c @@ -295,6 +295,7 @@ static int pfsyncioctl(struct ifnet *, u_long, caddr_t); static int pfsync_defer(struct pf_kstate *, struct mbuf *); static void pfsync_undefer(struct pfsync_deferral *, int); +static void pfsync_undefer_state_locked(struct pf_kstate *, int); static void pfsync_undefer_state(struct pf_kstate *, int); static void pfsync_defer_tmo(void *); @@ -1850,28 +1851,37 @@ pfsync_defer_tmo(void *arg) } static void -pfsync_undefer_state(struct pf_kstate *st, int drop) +pfsync_undefer_state_locked(struct pf_kstate *st, int drop) { struct pfsync_softc *sc = V_pfsyncif; struct pfsync_deferral *pd; struct pfsync_bucket *b = pfsync_get_bucket(sc, st); - PFSYNC_BUCKET_LOCK(b); + PFSYNC_BUCKET_LOCK_ASSERT(b); TAILQ_FOREACH(pd, &b->b_deferrals, pd_entry) { if (pd->pd_st == st) { if (callout_stop(&pd->pd_tmo) > 0) pfsync_undefer(pd, drop); - PFSYNC_BUCKET_UNLOCK(b); return; } } - PFSYNC_BUCKET_UNLOCK(b); panic("%s: unable to find deferred state", __func__); } +static void +pfsync_undefer_state(struct pf_kstate *st, int drop) +{ + struct pfsync_softc *sc = V_pfsyncif; + struct pfsync_bucket *b = pfsync_get_bucket(sc, st); + + PFSYNC_BUCKET_LOCK(b); + pfsync_undefer_state_locked(st, drop); + PFSYNC_BUCKET_UNLOCK(b); +} + static struct pfsync_bucket* pfsync_get_bucket(struct pfsync_softc *sc, struct pf_kstate *st) { @@ -1890,7 +1900,7 @@ pfsync_update_state(struct pf_kstate *st) PFSYNC_BUCKET_LOCK(b); if (st->state_flags & PFSTATE_ACK) - pfsync_undefer_state(st, 0); + pfsync_undefer_state_locked(st, 0); if (st->state_flags & PFSTATE_NOSYNC) { if (st->sync_state != PFSYNC_S_NONE) pfsync_q_del(st, true, b); @@ -2033,7 +2043,7 @@ pfsync_delete_state(struct pf_kstate *st) PFSYNC_BUCKET_LOCK(b); if (st->state_flags & PFSTATE_ACK) - pfsync_undefer_state(st, 1); + pfsync_undefer_state_locked(st, 1); if (st->state_flags & PFSTATE_NOSYNC) { if (st->sync_state != PFSYNC_S_NONE) pfsync_q_del(st, true, b);