From nobody Mon Apr 11 19:52:13 2022 X-Original-To: dev-commits-src-main@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 0F47F11CC890; Mon, 11 Apr 2022 19:52:14 +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 4KcfdT74mJz3J40; Mon, 11 Apr 2022 19:52:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649706734; 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=NAPlaGqZFF6kDx04DvRTo0WpDwLGvwp9VPY5r98A16o=; b=NYIiyUH9IuFdYXj8oYUpNoD8EeQyl1s0qDVPc+X8h7rhyuq02tm0kimAdS0xtFXfjB5uu8 N5VFmEIIn2NjGotPjk8Y9TIXKt9zj0PwCU/TkaxoEkDrVpT1ym/d/LKU8q3TbfTV4l+UXy 1njwzgDQN820OWLLYJNVe3XdRDzd0Y3meEelWiYa7Shu/jrEjziIZ9P6zdfjDWyX55/zdG anoqcIyVlJCgQ/+w4KWsmDRXPxf5oTN+XeFITVxfKrKoSG9W7+QfK4BLWJMNLKjXUn2LII 7E/aqtbxebj4QZPW4WLGjpDaFMGRktMu8CMrmsV5AkNlU3TBoJTNavvmP/7ViQ== 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 C8CE8160D; Mon, 11 Apr 2022 19:52:13 +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 23BJqDNU028665; Mon, 11 Apr 2022 19:52:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23BJqD1A028664; Mon, 11 Apr 2022 19:52:13 GMT (envelope-from git) Date: Mon, 11 Apr 2022 19:52:13 GMT Message-Id: <202204111952.23BJqD1A028664@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mike Karels Subject: git: 6ca0ca7b4cb5 - main - IPv4 multicast: fix LOR in shutdown path List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: karels X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6ca0ca7b4cb527dc17c289f1ae177ec267fd1add Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649706734; 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=NAPlaGqZFF6kDx04DvRTo0WpDwLGvwp9VPY5r98A16o=; b=nSSqvCzgZVQSGWWQHaqoiSvh+bvqSPFhklFf8o2QuJrvxiA06gRkT+uGL+GuCRgkPT/+9T JYYhf7sqXFSBbCMmh2LBYtUVTvUd4AK+i0wDSLTyli5nrPaAwDayu2V8wl6gOLXtTMZG+9 sF5bKsmocxakPPIF71tNlzJGKV9BNFRMI+f3k9H+DZIVxYr8OmoZWmrTjSZpMhBKiWhKnT Ml7IfZu8/s+qX18skdOrYlnVw2h4iio0J3ope2PRjSf2WOqvW2rmnFnMIEJInRbhRz8gPv yMvijIjov8lAGbRHVm9SYazyRKUCFza9JbiOcvw1zGgCQ52S5orve245uaSk0g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649706734; a=rsa-sha256; cv=none; b=thXQ9UaDeGdO1op2zxl2QIwL19y36g5VxwYULPt5VzIU2UoNahwGo718M3XMjBJX1+kNd9 5TrJMWglGkkReno1RISsvQPPgN5CarO0VhKgZFLUB1QiB+u2dny98fD8fxj+wHtiJI9WcB bTXwjt++L9c4YpUL1OGTHSZ3ZoLmGn1UMY465maB7Zwfu/hJl7lnVhyUUukY0Wb17t/KD9 gjev/5vqbNupC6Ykz8x+Bow6LsG3F5N/yND0hU7be/0gjKw6Ko9I2Quhx2u4dTcDaLZ5ws JRexwvBcyjv771/MAachGMao4n9d0xr7VnhWnTOzCc045UEZyjTEch8TlB1a7A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by karels: URL: https://cgit.FreeBSD.org/src/commit/?id=6ca0ca7b4cb527dc17c289f1ae177ec267fd1add commit 6ca0ca7b4cb527dc17c289f1ae177ec267fd1add Author: Mike Karels AuthorDate: 2022-04-08 12:37:15 +0000 Commit: Mike Karels CommitDate: 2022-04-11 19:51:16 +0000 IPv4 multicast: fix LOR in shutdown path X_ip_mrouter_done() was calling the interface ioctl routines via if_allmulti() while holding a write lock. However, some interface ioctl routines, including em/iflib and tap, use sxlocks, which are not permitted while holding a non-sleepable lock, and this elicits a warning from WITNESS. Fix the locking issue by recording the affected interface pointers in a malloc'ed array, and call if_allmulti() on each after dropping the rwlock. Reviewed by: bz Differential Revision: https://reviews.freebsd.org/D34845 --- sys/netinet/ip_mroute.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index cc356e3678f3..f77898fb3aa4 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -747,7 +747,8 @@ ip_mrouter_init(struct socket *so, int version) static int X_ip_mrouter_done(void) { - struct ifnet *ifp; + struct ifnet **ifps; + int nifp; u_long i; vifi_t vifi; struct bw_upcall *bu; @@ -774,6 +775,8 @@ X_ip_mrouter_done(void) taskqueue_drain(V_task_queue, &V_task); } + ifps = malloc(MAXVIFS * sizeof(*ifps), M_TEMP, M_WAITOK); + MRW_WLOCK(); taskqueue_cancel(V_task_queue, &V_task, NULL); @@ -785,14 +788,17 @@ X_ip_mrouter_done(void) mtx_destroy(&V_bw_upcalls_ring_mtx); /* - * For each phyint in use, disable promiscuous reception of all IP - * multicasts. + * For each phyint in use, prepare to disable promiscuous reception + * of all IP multicasts. Defer the actual call until the lock is released; + * just record the list of interfaces while locked. Some interfaces use + * sx locks in their ioctl routines, which is not allowed while holding + * a non-sleepable lock. */ - for (vifi = 0; vifi < V_numvifs; vifi++) { + KASSERT(V_numvifs <= MAXVIFS, ("More vifs than possible")); + for (vifi = 0, nifp = 0; vifi < V_numvifs; vifi++) { if (!in_nullhost(V_viftable[vifi].v_lcl_addr) && !(V_viftable[vifi].v_flags & (VIFF_TUNNEL | VIFF_REGISTER))) { - ifp = V_viftable[vifi].v_ifp; - if_allmulti(ifp, 0); + ifps[nifp++] = V_viftable[vifi].v_ifp; } } bzero((caddr_t)V_viftable, sizeof(*V_viftable) * MAXVIFS); @@ -824,6 +830,14 @@ X_ip_mrouter_done(void) MRW_WUNLOCK(); + /* + * Now drop our claim on promiscuous multicast on the interfaces recorded + * above. This is safe to do now because ALLMULTI is reference counted. + */ + for (vifi = 0; vifi < nifp; vifi++) + if_allmulti(ifps[vifi], 0); + free(ifps, M_TEMP); + CTR1(KTR_IPMF, "%s: done", __func__); return 0;