From: John Sperbeck <jsperbeck@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org
Cc: Simon Horman <horms@kernel.org>, Breno Leitao <leitao@debian.org>,
John Sperbeck <jsperbeck@google.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] net: netpoll: ensure skb_pool list is always initialized
Date: Sat, 21 Dec 2024 17:23:34 -0800 [thread overview]
Message-ID: <20241222012334.249021-1-jsperbeck@google.com> (raw)
When __netpoll_setup() is called directly, instead of through
netpoll_setup(), the np->skb_pool list head isn't initialized.
If skb_pool_flush() is later called, then we hit a NULL pointer
in skb_queue_purge_reason(). This can be seen with this repro,
when CONFIG_NETCONSOLE is enabled as a module:
ip tuntap add mode tap tap0
ip link add name br0 type bridge
ip link set dev tap0 master br0
modprobe netconsole netconsole=4444@10.0.0.1/br0,9353@10.0.0.2/
rmmod netconsole
The backtrace is:
BUG: kernel NULL pointer dereference, address: 0000000000000008
#PF: supervisor write access in kernel mode
#PF: error_code(0x0002) - not-present page
... ... ...
Call Trace:
<TASK>
__netpoll_free+0xa5/0xf0
br_netpoll_cleanup+0x43/0x50 [bridge]
do_netpoll_cleanup+0x43/0xc0
netconsole_netdev_event+0x1e3/0x300 [netconsole]
unregister_netdevice_notifier+0xd9/0x150
cleanup_module+0x45/0x920 [netconsole]
__se_sys_delete_module+0x205/0x290
do_syscall_64+0x70/0x150
entry_SYSCALL_64_after_hwframe+0x76/0x7e
Move the skb_pool list initialization into __netpoll_setup(). Also,
have netpoll_setup() call this before allocating its initial pool of
packets.
Fixes: 6c59f16f1770 ("net: netpoll: flush skb pool during cleanup")
Signed-off-by: John Sperbeck <jsperbeck@google.com>
---
net/core/netpoll.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 2e459b9d88eb..61662390414e 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -627,6 +627,8 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
const struct net_device_ops *ops;
int err;
+ skb_queue_head_init(&np->skb_pool);
+
if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
np_err(np, "%s doesn't support polling, aborting\n",
ndev->name);
@@ -681,8 +683,6 @@ int netpoll_setup(struct netpoll *np)
struct in_device *in_dev;
int err;
- skb_queue_head_init(&np->skb_pool);
-
rtnl_lock();
if (np->dev_name[0]) {
struct net *net = current->nsproxy->net_ns;
@@ -782,17 +782,16 @@ int netpoll_setup(struct netpoll *np)
}
}
+ err = __netpoll_setup(np, ndev);
+ if (err)
+ goto put;
+
/* fill up the skb queue */
refill_skbs(np);
- err = __netpoll_setup(np, ndev);
- if (err)
- goto flush;
rtnl_unlock();
return 0;
-flush:
- skb_pool_flush(np);
put:
DEBUG_NET_WARN_ON_ONCE(np->dev);
if (ip_overwritten)
--
2.47.1.613.gc27f4b7a9f-goog
next reply other threads:[~2024-12-22 1:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-22 1:23 John Sperbeck [this message]
2024-12-31 1:57 ` [PATCH] net: netpoll: ensure skb_pool list is always initialized Jakub Kicinski
2025-01-03 13:24 ` Breno Leitao
2025-01-10 13:07 ` Breno Leitao
2025-01-11 0:32 ` [PATCH v2] " John Sperbeck
2025-01-13 10:09 ` Breno Leitao
2025-01-14 1:13 ` [PATCH net v3] " John Sperbeck
2025-01-14 10:16 ` Breno Leitao
2025-01-15 1:50 ` patchwork-bot+netdevbpf
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=20241222012334.249021-1-jsperbeck@google.com \
--to=jsperbeck@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).