🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #3406

[PATCH net-next 09/37] can: raw: take rtnl_lock() before leaving the notifier list

#3406
From: Marc Kleine-Budde
Date: Thu, 15 Oct 2026 01:40
59 lines
10269 bytes
From: Oliver Hartkopp <socketcan@hartkopp.net>

raw_release() removes the socket from raw_notifier_list before it takes
rtnl_lock(). As the netdev notifier chain runs under RTNL, a socket that
leaves the list in this window is skipped by raw_notify() and has to
remove its CAN filters itself.

For raw this is not harmful: raw_release() removes the filters with
dev_net(ro->dev) under RTNL, so they are found even when the bound
device has been moved to another network namespace in this window. The
receivers only remain on the moved device until raw_release() gets
RTNL.

Take rtnl_lock() before removing the socket from the notifier list, so
that raw, isotp and bcm use the same locking scheme in their release
functions. As the notifier chain is always invoked under RTNL,
raw_busy_notifier can not point to the released socket anymore. Replace
the now dead busy-wait loop with a WARN_ON_ONCE().

Link: https://lore.kernel.org/linux-can/CEA6A38A-2646-4ADA-95B4-CBAE2F301A8E@doyensec.com/
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20261014142114.280279-4-socketcan@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/raw.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/net/can/raw.c b/net/can/raw.c
index dfea48768b23..d95ce54a4c45 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -422,16 +422,17 @@ static int raw_release(struct socket *sock)
 	ro = raw_sk(sk);
 	net = sock_net(sk);
 
+	rtnl_lock();
+
+	/* The netdev notifier chain runs under RTNL, so raw_notifier() can't
+	 * be walking raw_notifier_list and point to this socket. The spinlock
+	 * is still needed as raw_init() adds sockets without holding RTNL.
+	 */
 	spin_lock(&raw_notifier_lock);
-	while (raw_busy_notifier == ro) {
-		spin_unlock(&raw_notifier_lock);
-		schedule_timeout_uninterruptible(1);
-		spin_lock(&raw_notifier_lock);
-	}
+	WARN_ON_ONCE(raw_busy_notifier == ro);
 	list_del(&ro->notifier);
 	spin_unlock(&raw_notifier_lock);
 
-	rtnl_lock();
 	lock_sock(sk);
 
 	/* remove current filters & unregister */
-- 
2.53.0
Technical Details
Message-ID: <20261015015336.816543-10-mkl@pengutronix.de>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346487-linux-kernel-netdev=dewy.ru
References: <20261015015336.816543-1-mkl@pengutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346487-linux-kernel-netdev=dewy.ru
From: mkl@pengutronix.de (Marc Kleine-Budde)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next 09/37] can: raw: take rtnl_lock() before leaving the notifier list
Date: Thu, 15 Oct 2026 03:40:07 +0200
Organization: Usenet Network
Message-ID: <20261015015336.816543-10-mkl@pengutronix.de>
References: <20261015015336.816543-1-mkl@pengutronix.de>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2428277"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:SSKl7DX9rAniJqU1oAFc/KxxMgI= sha256:d+hpVMUI5hJxrTwkBJJL7wlmTJ6JGNbFti5pmVWS6gg=
	sha1:p6m953Vd19CXjpaZ4wYtuHS6JEQ= sha256:cFn6gv9D+60CegqdOnKHaNgxY2bUuw0n+k7NCY0q9Ng=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 2FE1C10FF78; Thu, 15 Oct 2026 04:55:06 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.749
X-Spam-Status: No, score=-0.749 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=pengutronix.de
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ZfYFYeJQydWL;
	Thu, 15 Oct 2026 04:55:03 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-346487-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=pengutronix.de
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 24DE6110211; Thu, 15 Oct 2026 04:54:54 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by tor.lore.kernel.org (Postfix) with ESMTP id D22E93B56F; Thu, 15 Oct 2026 01:54:01 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F87337B3F2;
	Thu, 15 Oct 2026 01:53:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=pengutronix.de header.i=@pengutronix.de header.b="WPb6XnSq"
X-Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7C263542CF;
	Thu, 15 Oct 2026 01:53:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=185.203.200.13
X-ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1792029227; cv=pass; b=kr/vi7f4tlkzR+G9LI8OyeiCRJFYJFfGBfaLaGE7AemCjCNpKUoglTv5CZPJoMicXyfchqF/etMcZIymb7AhgGnokfF8FH7K4WGO7TFvDNHsF0rG6sISD7DebzH2ThvTmESe32XDysTcWpN+f356zNmnm7QCVsn6/e10GOmFgcQ=
X-ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1792029227; c=relaxed/simple;
	bh=2GxWI++i9V6SkKHtjZPkEjGMZYiN5sklT0VO7UWaNvc=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=qgAJLpqHPOAFzxBOuxZllVvgJtRHUxtAB98AOCxp7V5FTCp9++24f1VSo3FA0l0ykmx8M1skxTgWo4AYlU1+CUhF0Y0Ae1zo2yI6kLNPHEJvJk0UJPBtK2S2qRXh9za+071KNRxK01ReZ82FrBjUYal6aKVzmbVU9QjLhnuwgMo=
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; dkim=pass (2048-bit key) header.d=pengutronix.de header.i=@pengutronix.de header.b=WPb6XnSq; arc=pass smtp.client-ip=185.203.200.13
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de
X-Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2])
	(Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de)
	by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 3AC8E202657;
	Thu, 15 Oct 2026 03:53:40 +0200 (CEST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de;
	s=20260414; t=1792029220;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=dvwH74dSTn6N243qYn35jRVqaP+2TQSCr8QQnKYNBjE=;
	b=WPb6XnSqpV0JLqiv3kWldxHLvKGKw5IJgaDc+q6OrjkaJhBaQfCnWjmjIgvnXXdR3eO6f6
	SNNSC8kRz/L2sD58/jTM+2IAr1rIE0m6nScS9d0bkqBmLGjbZZN1Wiq0+R4sopLyR7DFxW
	3oowszz24rLCeOsNdE0ZTFseTv2eV+b97C/8t/HOQF3Rx+1aFHX+KeOTVJM7PmulT/EuA5
	ulLtupm4b5qqta6hlANiBm+bSf/O0jBdJ8y+Fw7IQACj1qMVJL7XyRrd7F967ybot0BxRH
	YYfCNrFSSLEfDx01UOweoX3qX6PS3VOstKFapCByU8WtvcAK3o69I+HsE9MtHw==
X-ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1792029220; a=rsa-sha256;
	cv=none;
	b=XNhiv42/NF/gcmdu2c4NNsb/6KQo7hRNuAiIY09OvHMLsLbGoa4RGLxRFoMC881T2sFwzv
	JvxL8WRggz83g3uNxQpi21GhdblikZ9UXtV8vt5i11w5WqpD/qKYmF+ucpYSEgWazPMdUY
	Jpq8YJ0pm7yHB5VXFO0YkHWdOtSabmBl3dRdZNrU4bKR+lzhPrzW3zB9n/XJZpml+UMMtT
	Z6EMAAVr/4HNCtJSyMLaU867tiwZklKHSKpijgqny7Vmn/ySb1EwY+rlni5qH4UWP8SJ5T
	Aw6WHoGKlEeRfTepX/ePhHSgoPWx65awZjc7tu+aVyOnIOvOYLnqgh1oGdwJag==
X-ARC-Authentication-Results: i=1;
	ORIGINATING;
	auth=pass smtp.auth=relay-from-drehscheibe.grey.stw.pengutronix.de smtp.mailfrom=mkl@pengutronix.de
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de;
	s=20260414; t=1792029220;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=dvwH74dSTn6N243qYn35jRVqaP+2TQSCr8QQnKYNBjE=;
	b=TdJCBcOwdHAjLYomFdV0L37gowE1ea1GTYgvIJ8X9V4LTFhzLdmh42JPqc53jNMrhl4BOX
	nqE7cV+6tRZLT76L89tHoyWWKlJnGovQwzYWJSGler7ztwF9FAidhcWZLUMqCtn30NfvSp
	n2WHzOAOpxnJ7Ad5CeMecrpyI+yyhrChr1EyKEGuE77ZFCMbr/m49lhwd283sS3TQ4JNqp
	4MvKcLi56lEKaM562rVhMXejY2EC5crwv26OqXKu5hobIUeIN38R6M3qpU2Ra0BTvDbGrH
	uWyzueI+W3n2Sni6Jo/+k+6Cel6rtm5Th4YbDDEhpPYKYMSJ4IQ3y7/nBREOew==
X-Received: from moin.white.stw.pengutronix.de ([2a0a:edc0:0:b01:1d::7b] helo=bjornoya.blackshift.org)
	by drehscheibe.grey.stw.pengutronix.de with esmtps  (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
	(Exim 4.96)
	(envelope-from <mkl@pengutronix.de>)
	id 1xHAf6-005wq9-0S;
	Thu, 15 Oct 2026 03:53:40 +0200
X-Received: from blackshift.org (p4ffb23c7.dip0.t-ipconnect.de [79.251.35.199])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(Client did not present a certificate)
	(Authenticated sender: mkl-all@blackshift.org)
	by smtp.blackshift.org (Postfix) with ESMTPSA id D6D505C477C;
	Thu, 15 Oct 2026 01:53:39 +0000 (UTC)
X-Cc: davem@davemloft.net,
	kuba@kernel.org,
	linux-can@vger.kernel.org,
	kernel@pengutronix.de,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	Marc Kleine-Budde <mkl@pengutronix.de>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261015015336.816543-1-mkl@pengutronix.de>
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>