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>
Subject: [PATCH net-next 2/4] netconsole: read np.dev under the RTNL in local_mac_show()
Date: Mon, 28 Sep 2026 19:00:04 +0100 [thread overview]
Message-ID: <20260928-netcons-fixes-v1-2-bb5ffe5e698a@gmail.com> (raw)
In-Reply-To: <20260928-netcons-fixes-v1-0-bb5ffe5e698a@gmail.com>
local_mac_show() loads nt->np.dev and dereferences it with no lock. It
can race with the interface going away and netconsole_netdev_event()
eventually calling netdev_put() and freeing the device before we
dereference it, leading to a UAF.
The window is only a few instructions wide, so I could only reproduce it
with an artificially widened window between the load and the
dereference:
BUG: KASAN: slab-use-after-free in local_mac_show+0x4e/0x80
Read of size 8 at addr ffff88800e990458 by task uaf/130
local_mac_show+0x4e/0x80
configfs_read_iter+0x187/0x260
vfs_read+0x453/0x5a0
Allocated by task 116:
alloc_netdev_mqs+0x78/0x830
rtnl_create_link+0x53b/0x5c0
Freed by task 121:
kfree+0x159/0x420
device_release+0x77/0x120
kobject_put+0xb5/0x160
netdev_run_todo+0x420/0x850
rtnl_dellink+0x259/0x5b0
Fixes: 0953864160bd ("[NETPOLL]: no need to store local_mac")
Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
---
drivers/net/netconsole.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 7dde00eb8e98..5f4311726d11 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -900,10 +900,17 @@ static ssize_t remote_ip_show(struct config_item *item, char *buf)
static ssize_t local_mac_show(struct config_item *item, char *buf)
{
- struct net_device *dev = to_target(item)->np.dev;
static const u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+ struct netconsole_target *nt = to_target(item);
+ int ret;
- return sysfs_emit(buf, "%pM\n", dev ? dev->dev_addr : bcast);
+ /* Hold RTNL here so netconsole_netdev_event() doesn't tear down np.dev
+ * from under us.
+ */
+ rtnl_lock();
+ ret = sysfs_emit(buf, "%pM\n", nt->np.dev ? nt->np.dev->dev_addr : bcast);
+ rtnl_unlock();
+ return ret;
}
static ssize_t remote_mac_show(struct config_item *item, char *buf)
--
2.55.0
next prev parent reply other threads:[~2026-09-28 18:01 UTC|newest]
Thread overview: 5+ 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-09-28 18:00 ` Gustavo Luiz Duarte [this message]
2026-09-28 18:00 ` [PATCH net-next 3/4] netconsole: avoid printing partially updated target attributes 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-2-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@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®