From nobody Tue Jul 05 17:55:47 2022 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 4FDE91D1C9C1; Tue, 5 Jul 2022 17:55:47 +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 4Lcr1v1jnHz4t66; Tue, 5 Jul 2022 17:55:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657043747; 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=HuF7AsAGJRsnY7vPEdItp1CnkqC9PuwxISJIkonbXkc=; b=G4fwfaNMgJRjmJTcsMxFqXOkvQNItkJn0Swejy+tXl0SHtG7Xzl7K22XQAcT9/bCIMBLks fqPflIxDQw4Il2RUesH8L2qj90ZJJ9ghhRUI1ny+R3L5cTSjiFlOKP7NnMipLo9BsrFnFl KZ8YXmehwnUiysQ6Ej4me5UbGirVjsIkbDCrCW/1c9jAcr6bIGvXn5T8SJE76m53jGLm1l zbaRtVKo6zYgpgBimGooFBSOPjRpXJoE66wLPF9jV3qbo7THbKAt7ICfkdqTFWg1UIbZD5 IxJq6RWrtacuGWLTXt5pt2SKxEjLsOAjvtmPsjH3KH/mTM/ky6fJlNvaE9IyHQ== 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 1B3012417; Tue, 5 Jul 2022 17:55:47 +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 265HtlrD000894; Tue, 5 Jul 2022 17:55:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 265HtlHV000893; Tue, 5 Jul 2022 17:55:47 GMT (envelope-from git) Date: Tue, 5 Jul 2022 17:55:47 GMT Message-Id: <202207051755.265HtlHV000893@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: cbb019b831ad - main - dummynet: fix ip_dn_vnet_init() / dummynet_task() race 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/main X-Git-Reftype: branch X-Git-Commit: cbb019b831ad59ead34b825bf053169ebbe81bbf Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657043747; 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=HuF7AsAGJRsnY7vPEdItp1CnkqC9PuwxISJIkonbXkc=; b=YrFlzbNgsPyKIm4hIkVac51d0ppcGGq9BqujCsgDyOvodqNzbiTC+0j6zTlvnjeNRgGzK+ 0InnTbFVx0LRO+4LFaQDcLzNtn4en09UNvU0udguCDoPLkvqy9DtoIDtcmq6097L6fB7AY I2xLXvsYTUt33qb4BfmhBxDgGV3MwSebWDsT8vUs1DalLKHuoKvxLvQVVfHuHOPLs0+Nvq BykMeNlxdHVo1ACOZf9habq7B/ElydFfyyjXvDhsg62ubqR+KbROwq8qpqgdLkszrHbbCQ TKV8u8KgHLBB7+qfUOt7ZNXcIhzM/Tpma0svQvw/ymg7ATK2NmoYNL2XS4UtgQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657043747; a=rsa-sha256; cv=none; b=T21RXdx1azf+0hh2F/iqCzgs+CTKVkp6lCXD5QJI6+uTqtHIffwZ6H4w6/Lm8bF0hP4G8X 3o7xvFrIwUEMdiX4A7rMgr+VhzhKiYYfZXRDwHY243OadOsoV1Lxs9V5WaXH+/3Xx247An mOEFJ3XN5fEtcFiF+3tZYxevorxfG9DQWGgw5wolqgIjh1XsphNx3kv7HFezOwsMijxBNm 7SBFUkhYygiLrX6/DNpqgc8KSBIer07x53FIjePni1IwARXJOYCaA95eEejzDwSPBLv8QP EzHuZ6eQesKniLQRFvcD2gwLwiotGBKK/rfO56AigkPQ2IihVM53SNtnaRAxBw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=cbb019b831ad59ead34b825bf053169ebbe81bbf commit cbb019b831ad59ead34b825bf053169ebbe81bbf Author: Kristof Provost AuthorDate: 2022-07-04 20:36:43 +0000 Commit: Kristof Provost CommitDate: 2022-07-05 16:59:00 +0000 dummynet: fix ip_dn_vnet_init() / dummynet_task() race If dummynet_task() is run on a vnet where dummynet is still initialising (i.e. still running ip_dn_vnet_init()) we can attempt to use an uninitialised mutex. We can use the existing init_done field to check if the per-vnet V_dn_cfg is fully set up, if we ensure that it's only set to 1 when we've done all of the init work. Reported by: Alfredo Dal'Ava JĂșnior Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D35716 --- sys/netpfil/ipfw/ip_dn_io.c | 5 +++++ sys/netpfil/ipfw/ip_dummynet.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/netpfil/ipfw/ip_dn_io.c b/sys/netpfil/ipfw/ip_dn_io.c index deeb3d9325de..7a85714fa0c6 100644 --- a/sys/netpfil/ipfw/ip_dn_io.c +++ b/sys/netpfil/ipfw/ip_dn_io.c @@ -669,6 +669,11 @@ dummynet_task(void *context, int pending) memset(&q, 0, sizeof(struct mq)); CURVNET_SET(vnet_iter); + if (! V_dn_cfg.init_done) { + CURVNET_RESTORE(); + continue; + } + DN_BH_WLOCK(); /* Update number of lost(coalesced) ticks. */ diff --git a/sys/netpfil/ipfw/ip_dummynet.c b/sys/netpfil/ipfw/ip_dummynet.c index 46300b90007e..503fbef6f530 100644 --- a/sys/netpfil/ipfw/ip_dummynet.c +++ b/sys/netpfil/ipfw/ip_dummynet.c @@ -2562,7 +2562,7 @@ ip_dn_vnet_init(void) { if (V_dn_cfg.init_done) return; - V_dn_cfg.init_done = 1; + /* Set defaults here. MSVC does not accept initializers, * and this is also useful for vimages */ @@ -2601,6 +2601,8 @@ ip_dn_vnet_init(void) /* Initialize curr_time adjustment mechanics. */ getmicrouptime(&V_dn_cfg.prev_t); + + V_dn_cfg.init_done = 1; } static void