From: Gustavo Luiz Duarte <gustavold@gmail.com>
To: "Breno Leitao" <leitao@debian.org>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Matt Mackall" <mpm@selenic.com>,
"Bruno Prémont" <bonbons@linux-vserver.org>,
"Stephen Hemminger" <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Gustavo Luiz Duarte <gustavold@gmail.com>,
Sashiko <netdev-bot+sashiko@kernel.org>
Subject: [PATCH net-next 3/4] netconsole: avoid printing partially updated target attributes
Date: Mon, 28 Sep 2026 19:00:05 +0100 [thread overview]
Message-ID: <20260928-netcons-fixes-v1-3-bb5ffe5e698a@gmail.com> (raw)
In-Reply-To: <20260928-netcons-fixes-v1-0-bb5ffe5e698a@gmail.com>
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.
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
Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
---
drivers/net/netconsole.c | 57 ++++++++++++++++++++++++++++++++++++++----------
1 file changed, 46 insertions(+), 11 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 5f4311726d11..627475f16383 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -861,7 +861,14 @@ 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);
+ int ret;
+
+ dynamic_netconsole_mutex_lock();
+ ret = sysfs_emit(buf, "%s\n", nt->np.dev_name);
+ dynamic_netconsole_mutex_unlock();
+
+ return ret;
}
static ssize_t local_port_show(struct config_item *item, char *buf)
@@ -877,25 +884,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)
@@ -915,7 +936,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)
@@ -1350,7 +1378,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.55.0
next prev parent reply other threads:[~2026-09-28 18:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 18:00 [PATCH net-next 0/4] netconsole: fix target enable race and configfs read locking Gustavo Luiz Duarte
2026-09-28 18:00 ` [PATCH net-next 1/4] netconsole: finish enabling the target before releasing RTNL Gustavo Luiz Duarte
2026-10-01 15:03 ` Breno Leitao
2026-10-05 11:36 ` Gustavo Luiz Duarte
2026-09-28 18:00 ` [PATCH net-next 2/4] netconsole: read np.dev under the RTNL in local_mac_show() Gustavo Luiz Duarte
2026-09-28 18:00 ` Gustavo Luiz Duarte [this message]
2026-10-01 9:00 ` [PATCH net-next 3/4] netconsole: avoid printing partially updated target attributes netdev-bot+sashiko
2026-10-05 11:46 ` Gustavo Luiz Duarte
2026-09-28 18:00 ` [PATCH net-next 4/4] netconsole: remove unnecessary target refcounting from the netdev notifier Gustavo Luiz Duarte
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260928-netcons-fixes-v1-3-bb5ffe5e698a@gmail.com \
--to=gustavold@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=bonbons@linux-vserver.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpm@selenic.com \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.