Skip to content

Commit f0d0277

Browse files
John Sperbeckkuba-moo
authored andcommitted
net: netpoll: ensure skb_pool list is always initialized
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 [email protected]/br0,[email protected]/ 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 setup and initial skb fill into __netpoll_setup(). Fixes: 221a9c1 ("net: netpoll: Individualize the skb pool") Signed-off-by: John Sperbeck <[email protected]> Reviewed-by: Breno Leitao <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c17ff47 commit f0d0277

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

net/core/netpoll.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
627627
const struct net_device_ops *ops;
628628
int err;
629629

630+
skb_queue_head_init(&np->skb_pool);
631+
630632
if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
631633
np_err(np, "%s doesn't support polling, aborting\n",
632634
ndev->name);
@@ -662,6 +664,9 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
662664
strscpy(np->dev_name, ndev->name, IFNAMSIZ);
663665
npinfo->netpoll = np;
664666

667+
/* fill up the skb queue */
668+
refill_skbs(np);
669+
665670
/* last thing to do is link it to the net device structure */
666671
rcu_assign_pointer(ndev->npinfo, npinfo);
667672

@@ -681,8 +686,6 @@ int netpoll_setup(struct netpoll *np)
681686
struct in_device *in_dev;
682687
int err;
683688

684-
skb_queue_head_init(&np->skb_pool);
685-
686689
rtnl_lock();
687690
if (np->dev_name[0]) {
688691
struct net *net = current->nsproxy->net_ns;
@@ -782,9 +785,6 @@ int netpoll_setup(struct netpoll *np)
782785
}
783786
}
784787

785-
/* fill up the skb queue */
786-
refill_skbs(np);
787-
788788
err = __netpoll_setup(np, ndev);
789789
if (err)
790790
goto flush;

0 commit comments

Comments
 (0)