🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #2434

[PATCH net v3 1/2] netconsole: finish enabling the target before releasing RTNL

#2434
From: Gustavo Luiz Duarte
Date: Mon, 12 Oct 2026 16:41
77 lines
10490 bytes
netcons_netpoll_setup() publishes nt->np.dev inside __netpoll_setup(),
then releases the RTNL and waits for an RCU grace period before
returning. Only after that does its caller store STATE_ENABLED.

A NETDEV_UNREGISTER event landing in that window tears the target down
and we end up storing STATE_ENABLED with a NULL np->dev, leading to a
null-ptr-deref in netconsole_write():

  BUG: KASAN: null-ptr-deref in netconsole_write+0xb9/0x7f0
  Read of size 8 at addr 00000000000000a8 by task pr/netcon_ext0/135
   netconsole_write+0xb9/0x7f0
   nbcon_emit_next_record+0x501/0x550
   nbcon_emit_one+0x10e/0x170
   nbcon_kthread_func+0x2ff/0x3b0
   kthread+0x199/0x1e0

Store STATE_ENABLED before dropping the RTNL lock to avoid racing with
netconsole_netdev_event().

Fixes: 2382b15bcc39 ("netconsole: take care of NETDEV_UNREGISTER event")
Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
---
 drivers/net/netconsole.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index b358e5c36735..1fb846ad07d1 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -552,13 +552,16 @@ static int netcons_netpoll_setup(struct netconsole_target *nt)
 	err = __netpoll_setup(np, ndev);
 	if (err)
 		goto put;
-	rtnl_unlock();
 
 	/* Make sure all NAPI polls which started before dev->npinfo
 	 * was visible have exited before we start calling NAPI poll.
 	 * NAPI skips locking if dev->npinfo is NULL.
+	 * Hold RTNL until enable is finished so we don't race with
+	 * netconsole_netdev_event()
 	 */
-	synchronize_rcu();
+	synchronize_net();
+	nt->state = STATE_ENABLED;
+	rtnl_unlock();
 
 	return 0;
 
@@ -589,7 +592,6 @@ static void resume_target(struct netconsole_target *nt)
 		return;
 	}
 
-	nt->state = STATE_ENABLED;
 	pr_info("network logging resumed on interface %s\n", nt->np.dev_name);
 }
 
@@ -1067,7 +1069,6 @@ static ssize_t enabled_store(struct config_item *item,
 			goto out_unlock;
 		}
 
-		nt->state = STATE_ENABLED;
 		pr_info("network logging started\n");
 	} else {	/* false */
 		/* We need to disable the netconsole before cleaning it up
@@ -2669,8 +2670,6 @@ static struct netconsole_target *alloc_param_target(char *target_config,
 			 * otherwise, keep the target in the list, but disabled.
 			 */
 			goto fail;
-	} else {
-		nt->state = STATE_ENABLED;
 	}
 	populate_configfs_item(nt, cmdline_count);
 

-- 
2.56.0
Technical Details
Message-ID: <20261012-netcons-fixes-v3-1-1aac85ed7665@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-345114-linux-kernel-netdev=dewy.ru
References: <20261012-netcons-fixes-v3-0-1aac85ed7665@gmail.com>

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-345114-linux-kernel-netdev=dewy.ru
From: gustavold@gmail.com (Gustavo Luiz Duarte)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v3 1/2] netconsole: finish enabling the target before
 releasing RTNL
Date: Mon, 12 Oct 2026 17:41:57 +0100
Organization: Usenet Network
Message-ID: <20261012-netcons-fixes-v3-1-1aac85ed7665@gmail.com>
References: <20261012-netcons-fixes-v3-0-1aac85ed7665@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="1829708"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:YAH2G8UfJpMaeL5Js1kwAJR/Img= sha256:jRB2bxaxOJIzBmgU4Gdv9liMnpynlQSQUfFovktSknA=
	sha1:TPk1GjDY3vi0o9l8pA2hKwuPaf4= sha256:vTI4euSIA8ZpNrY+8etdp0JnRiDtnP29mMH/UOIOmu4=
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 337E910FC6B; Mon, 12 Oct 2026 19:56:43 +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, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
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 5D6KKRQj9z5Q;
	Mon, 12 Oct 2026 19:56:32 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-345114-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 872FA10FC56; Mon, 12 Oct 2026 19:56:22 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sea.lore.kernel.org (Postfix) with ESMTP id C1E46126F26; Mon, 12 Oct 2026 16:42:30 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 533F44B1297;
	Mon, 12 Oct 2026 16:42:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bj8ZEyF7"
X-Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id C46BE48F85C
	for <netdev@vger.kernel.org>; Mon, 12 Oct 2026 16:42:21 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791823343; cv=none; b=VtGcIZYtVYn/vxzJ0afgtvUEmLq6PBa3DzC2LKS9IXAnFDv2Tpv+SYnPxaXkSZqD7WXaCVYo/cYnxmd8xHIfMkY91AaVpmX3+3C4ymXZ3jyeOe675VJPUOgDepkGQh8S11o52NONfbfAwzVw3I1aVAnLmEMrJFMKu3ERWFBFcjM=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791823343; c=relaxed/simple;
	bh=EXC48ns2jWgAZUb2XLn2yHi+H3UJwk46qcn+bKkeKxM=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=BMOLkQw11vH3aN+dvsInF7KojBMcS1XCauXaPBsvd8MDcqMdznqPMLsLBqHJc9j+npWR8ES7GrVwAOx5xo+KMsWCZ29Xrl4UOBy9pj91w5lGGmBmSSb7CWM18pfCWkTieuGhI6VtulWWB1e04FSZ2hUM3MpYmj17SoGO3zgIbAU=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Bj8ZEyF7; arc=none smtp.client-ip=209.85.221.47
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-48c5b7d5865so167712f8f.2
        for <netdev@vger.kernel.org>; Mon, 12 Oct 2026 09:42:21 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1791823340; x=1792428140; darn=vger.kernel.org;
        h=cc:to:in-reply-to:references:message-id:content-transfer-encoding
         :content-type:mime-version:subject:date:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=DbH0x+1VGrxmmG/67GKpm0AlwDDsWm6hJsBQAAEfQEQ=;
        b=Bj8ZEyF7mlJrBzYLeQpdXMfcbdhO/zeAYnHsrwj3wFPp46ekmGdCF3CxZXonS1GgM5
         NXZN54NTi/8KZupzxcialHuP7zDXpMafHwGI6q1qHjRu7XMyUeWRPtCqQYSKZzCEaEi2
         tjJoTDe/EI3VqB0dG8mQdIfm9f4eqy9LI/kY7iz+jWp19vQUEG7saVQzbA0cw82ICW8Q
         dJvwAinHrLB6YB9TV5bxDXe59vn3fZtZai+GzDUM+xpdUPifwAv7LcOUfVwpbCP3fuvf
         fThxrplRJtHcO40A1O19PiaSeVN+c6aYh3T2PXswW5qAB/5U+NFpu0YjPsUW1zggeffT
         vxuA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1791823340; x=1792428140;
        h=cc:to:in-reply-to:references:message-id:content-transfer-encoding
         :content-type:mime-version:subject:date:from:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=DbH0x+1VGrxmmG/67GKpm0AlwDDsWm6hJsBQAAEfQEQ=;
        b=HiyijmjMWwW/2QI0TNTVB4vrdjcbWFyoUHhfN7TJTa+j0cDm+KhfsPYt7hPxZj32bS
         cveqi1P43QrBHz2NhS7nZwaJndMiFo8GVFMtkSBiKAgCzCflObI9GUOgDiHdc8gKmGo0
         47mgN1A1Ad53H8NFUA/wwwhH5q6EWf9J0bmlL+hciQziTfJP/P/ZtlolvsjF12Ii10b2
         58msxkQuDJFSHeZwdPicw4KpYIzbPyGCx/ui321CCMZFjQ9klt8xGS4pASWqmX424CuE
         6FoDwnqwC0BrWJ3hey2Z5I1lHr7ZcexYVp8/Yq/d17lUlnw1Bk95yXHnc+IxA+SX90eT
         nKbQ==
X-Forwarded-Encrypted: i=1; AKwUvBwr6IzayMOJzb3o5+01dpJV+XDEes85qnOkoGpso8B5dCiUngPZglwGuRv4Y/1PUTerD4mJPsY=@vger.kernel.org
X-Gm-Message-State: AFq9FYLeMuk235Ihn/4p6up2LXh9gFntat8PoGLy4KlvzPGDmY5QtM0q
	jgP4k7zblzeaEpr0u5h5nYctZeGJn/4AaMqaBnYQoZ+BS7KG/OxdErwh
X-Gm-Gg: AYBFou2xcn0OxKWKSlI42LAM0tDQw9dTIQCbWwOalcc8wbhY/JbS3P9uwElyGkB0vpO
	PqcmzF23sOVXsGXp5e8Sz037XmiQB0aPoe+xJgBUR5IfOuJ0RrejayTECJAPlDY7jaSE1hIqS80
	fddEHQ7N4UzfaNOdkveIRYhWDEn+lQL7RRGC7ufXQxmVxWw7kRWrHdttO+4Xg5xVVHe4C8sVvc4
	wynl3aSUBnacKiGvb6DflY+pbl+qUpFMIuO5JSZDxtDjp/l6YN48r3wuRCBp2uakuWFBeM9/pAv
	ieY0AA60EEvQ+TCkUAxTOi4kFXZpGIURMOdteCxprv8BG41qC8WjhZWJezZ8WZS22g4JgV26vxR
	3lKwt0iDkM954T9q8E7/JIVQGfMLgzLyrCYSHaAJOYQaBtsA+4pLDyhvCP8h0b3hky5xdYcFmO4
	AahIuX046hz+86rZNn1KDqVSZgKNqkSCCqGfNqYGjwZehu7aQKOgYB0usSVI59kaU=
X-Received: by 2002:a05:6000:4694:b0:48a:f4c1:4301 with SMTP id ffacd0b85a97d-48ddfb1b623mr910781f8f.6.1791823339056;
        Mon, 12 Oct 2026 09:42:19 -0700 (PDT)
X-Received: from localhost ([2620:10d:c092:500::4:c555])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48de0967c03sm394228f8f.6.2026.10.12.09.42.18
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 12 Oct 2026 09:42:18 -0700 (PDT)
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>
X-In-Reply-To: <20261012-netcons-fixes-v3-0-1aac85ed7665@gmail.com>
X-Cc: Gustavo Luiz Duarte <gustavold@gmail.com>, netdev@vger.kernel.org, 
 linux-kernel@vger.kernel.org
X-Mailer: b4 0.15.2