Article View: linux.kernel.netdev
Article #2439[PATCH net-next v2 1/2] netconsole: avoid printing partially updated target attributes
From: Gustavo Luiz Duarte
Date: Mon, 12 Oct 2026 17:03
Date: Mon, 12 Oct 2026 17:03
130 lines
12351 bytes
12351 bytes
The configfs store callbacks all serialize on dynamic_netconsole_mutex
but not on the read side, so reading an attribute while it is being
written returns a partially updated value.
Hold dynamic_netconsole_mutex on *_show() callbacks to avoid racing with
writers.
The dev_name_show() callback can also race with
netconsole_netdev_event() writing to np.dev_name due to
NETDEV_CHANGENAME. So it needs to hold target_list_lock in addition to
dynamic_netconsole_mutex.
Reported-by: Sashiko <netdev-bot+sashiko@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260814-netcons_ipv6-v3-7-bc0915e8c75f@gmail.com
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928-netcons-fixes-v1-0-bb5ffe5e698a%40gmail.com
Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
---
drivers/net/netconsole.c | 63 +++++++++++++++++++++++++++++++++++++++---------
1 file changed, 52 insertions(+), 11 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 267254f046de..953a1da07186 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -859,7 +859,20 @@ static ssize_t release_show(struct config_item *item, char *buf)
static ssize_t dev_name_show(struct config_item *item, char *buf)
{
- return sysfs_emit(buf, "%s\n", to_target(item)->np.dev_name);
+ struct netconsole_target *nt = to_target(item);
+ unsigned long flags;
+ int ret;
+
+ dynamic_netconsole_mutex_lock();
+ /* Hold target_list_lock to prevent racing against
+ * netconsole_netdev_event() changing np.dev_name.
+ */
+ spin_lock_irqsave(&target_list_lock, flags);
+ ret = sysfs_emit(buf, "%s\n", nt->np.dev_name);
+ spin_unlock_irqrestore(&target_list_lock, flags);
+ dynamic_netconsole_mutex_unlock();
+
+ return ret;
}
static ssize_t local_port_show(struct config_item *item, char *buf)
@@ -875,25 +888,39 @@ static ssize_t remote_port_show(struct config_item *item, char *buf)
static ssize_t local_ip_show(struct config_item *item, char *buf)
{
struct netconsole_target *nt = to_target(item);
+ int ret;
+
+ dynamic_netconsole_mutex_lock();
if (nt->local_ip.family == AF_UNSPEC)
- return sysfs_emit(buf, "\n");
- if (nt->local_ip.family == AF_INET6)
- return sysfs_emit(buf, "%pI6c\n", &nt->local_ip.in6);
+ ret = sysfs_emit(buf, "\n");
+ else if (nt->local_ip.family == AF_INET6)
+ ret = sysfs_emit(buf, "%pI6c\n", &nt->local_ip.in6);
else
- return sysfs_emit(buf, "%pI4\n", &nt->local_ip.ip);
+ ret = sysfs_emit(buf, "%pI4\n", &nt->local_ip.ip);
+
+ dynamic_netconsole_mutex_unlock();
+
+ return ret;
}
static ssize_t remote_ip_show(struct config_item *item, char *buf)
{
struct netconsole_target *nt = to_target(item);
+ int ret;
+
+ dynamic_netconsole_mutex_lock();
if (nt->remote_ip.family == AF_UNSPEC)
- return sysfs_emit(buf, "\n");
- if (nt->remote_ip.family == AF_INET6)
- return sysfs_emit(buf, "%pI6c\n", &nt->remote_ip.in6);
+ ret = sysfs_emit(buf, "\n");
+ else if (nt->remote_ip.family == AF_INET6)
+ ret = sysfs_emit(buf, "%pI6c\n", &nt->remote_ip.in6);
else
- return sysfs_emit(buf, "%pI4\n", &nt->remote_ip.ip);
+ ret = sysfs_emit(buf, "%pI4\n", &nt->remote_ip.ip);
+
+ dynamic_netconsole_mutex_unlock();
+
+ return ret;
}
static ssize_t local_mac_show(struct config_item *item, char *buf)
@@ -906,7 +933,14 @@ static ssize_t local_mac_show(struct config_item *item, char *buf)
static ssize_t remote_mac_show(struct config_item *item, char *buf)
{
- return sysfs_emit(buf, "%pM\n", to_target(item)->remote_mac);
+ struct netconsole_target *nt = to_target(item);
+ int ret;
+
+ dynamic_netconsole_mutex_lock();
+ ret = sysfs_emit(buf, "%pM\n", nt->remote_mac);
+ dynamic_netconsole_mutex_unlock();
+
+ return ret;
}
static ssize_t transmit_errors_show(struct config_item *item, char *buf)
@@ -1342,7 +1376,14 @@ static struct netconsole_target *userdata_to_target(struct userdata *ud)
static ssize_t userdatum_value_show(struct config_item *item, char *buf)
{
- return sysfs_emit(buf, "%s\n", &(to_userdatum(item)->value[0]));
+ struct userdatum *udm = to_userdatum(item);
+ int ret;
+
+ dynamic_netconsole_mutex_lock();
+ ret = sysfs_emit(buf, "%s\n", udm->value);
+ dynamic_netconsole_mutex_unlock();
+
+ return ret;
}
/* Navigate configfs and calculate the lentgh of the formatted string
--
2.56.0
Technical Details
Message-ID:
<20261012-netcons-fixes-next-v2-1-ac8ec4c62edb@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-345136-linux-kernel-netdev=dewy.ruReferences:
<20261012-netcons-fixes-next-v2-0-ac8ec4c62edb@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-345136-linux-kernel-netdev=dewy.ru
From: gustavold@gmail.com (Gustavo Luiz Duarte)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v2 1/2] netconsole: avoid printing partially
updated target attributes
Date: Mon, 12 Oct 2026 18:03:43 +0100
Organization: Usenet Network
Message-ID: <20261012-netcons-fixes-next-v2-1-ac8ec4c62edb@gmail.com>
References: <20261012-netcons-fixes-next-v2-0-ac8ec4c62edb@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="1831853"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:SPDfWstxRrZS1dCOvhaV6J1BlTA= sha256:p6iXlksWtWXpgvFeLR3tABdk16oggY/a+2ip9NJZnBQ=
sha1:IVz9zfNYoDHUkhgQY0i9Vpa7TqE= sha256:spyjj3cZYTmswaKvSNtlSeOVXXz19MwHv4QfLIOZREU=
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 82B9710FC6F; Mon, 12 Oct 2026 20:04:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.849
X-Spam-Status: No, score=-0.849 tagged_above=-9999 required=6.31
tests=[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 qB00tJxxILRp;
Mon, 12 Oct 2026 20:04:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-345136-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 9619D10FC56; Mon, 12 Oct 2026 20:04:15 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sto.lore.kernel.org (Postfix) with ESMTP id DC5B0606766; Mon, 12 Oct 2026 17:04:13 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 4677A4B95CA;
Mon, 12 Oct 2026 17:04:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XY5TuFUf"
X-Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53])
(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 6A37B39CD1F
for <netdev@vger.kernel.org>; Mon, 12 Oct 2026 17:04:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1791824643; cv=none; b=Atx6RGZ3IvBVe6TUA/NhI82ma/fBqVwVnJEQK9Q6ij8PfK/jSlmKBOPzpsvQFxGBiuH5FyXsQMzJhjMCxgkWBYQk/kHZ/zS3j6/BMew1oDeSAw9Ou3VAAvMBu8aBBgO/owRRKBO8repJQJF+djdCZhZjuiBXz6UpKjttBM+Fe2g=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1791824643; c=relaxed/simple;
bh=7MuVjuhF+Ser5K3+IN7XG2FsuC3X8ZSQxqeDy6PE6bs=;
h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
In-Reply-To:To:Cc; b=Kd+t1b048G9wVZ86r7BVWuN7XKOSiTeve3k7S5zr3k+NgbHDe7zCH6z5l3PaqYbCgENwLSpARoq4bjwJS5ddi9WOvhI/MEw4chDXbRCSHmzV/WN2xOofPv2ha3tHk1aaZFd60Uh3WKiYApm3u62tBw9e7bt3z9rtjnB2MFTdFvU=
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=XY5TuFUf; arc=none smtp.client-ip=209.85.221.53
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-f53.google.com with SMTP id ffacd0b85a97d-48bbb06f29bso169153f8f.3
for <netdev@vger.kernel.org>; Mon, 12 Oct 2026 10:04:01 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1791824639; x=1792429439; 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=3FVaPfHKAF1nMEvp9RjbHuFY5UhBJPIfS1hxOZsF6QI=;
b=XY5TuFUf5qD364itS2gxwuukny79Gg1sFHP+th6xbpi7TlXd0p/l+g81sVUmnkKAAv
p3k7AUeSSJOt99Wm5is6YBSuvbzqYkjgbzD84UZIZPEN7xtb1f35xVfNGObEqbqd7mfF
dhGiwWErh1M4HgUytFWUZc/cPxizMfwEK/c7NiP1Cn2nGQunYFb58zCGWzRm9b/XMJzq
F7/BEaGhbgrPVzmnbfrep9u9CsoUAK0uMaNbDQTbEvA/vovTaLNZ8dSPdBq3ZQWiGcJt
gAf674WK3nnrntHJogQcBWmUnjXzDICd10nE1UWJEOLipVtxAUUl0wLp6sPLsBy8sOP+
0Nsg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1791824639; x=1792429439;
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=3FVaPfHKAF1nMEvp9RjbHuFY5UhBJPIfS1hxOZsF6QI=;
b=wemxZ+Oromtc2i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e9.1.1791824639352;
Mon, 12 Oct 2026 10:03:59 -0700 (PDT)
X-Received: from localhost ([2620:10d:c092:500::4:c555])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48de0ab4f34sm447253f8f.28.2026.10.12.10.03.58
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 12 Oct 2026 10:03:58 -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-next-v2-0-ac8ec4c62edb@gmail.com>
X-Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Gustavo Luiz Duarte <gustavold@gmail.com>,
Sashiko <netdev-bot+sashiko@kernel.org>
X-Mailer: b4 0.15.2