Skip to content

Commit 8c0726e

Browse files
committed
Merge branch 'net-netpoll-fix-memory-leak-and-add-comprehensive-selftests'
Breno Leitao says: ==================== net: netpoll: fix memory leak and add comprehensive selftests Fix a memory leak in netpoll and introduce netconsole selftests that expose the issue when running with kmemleak detection enabled. This patchset includes a selftest for netpoll with multiple concurrent users (netconsole + bonding), which simulates the scenario from test[1] that originally demonstrated the issue allegedly fixed by commit efa95b0 ("netpoll: fix use after free") - a commit that is now being reverted. Sending this to "net" branch because this is a fix, and the selftest might help with the backports validation. Link: https://lore.kernel.org/lkml/96b940137a50e5c387687bb4f57de8b0435a653f.1404857349.git.decot@googlers.com/ [1] ==================== Link: https://patch.msgid.link/20251107-netconsole_torture-v10-0-749227b55f63@debian.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents e6ca8f5 + 236682d commit 8c0726e

7 files changed

Lines changed: 566 additions & 17 deletions

File tree

net/core/netpoll.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,10 @@ static void __netpoll_cleanup(struct netpoll *np)
811811
if (!npinfo)
812812
return;
813813

814+
/* At this point, there is a single npinfo instance per netdevice, and
815+
* its refcnt tracks how many netpoll structures are linked to it. We
816+
* only perform npinfo cleanup when the refcnt decrements to zero.
817+
*/
814818
if (refcount_dec_and_test(&npinfo->refcnt)) {
815819
const struct net_device_ops *ops;
816820

@@ -820,8 +824,7 @@ static void __netpoll_cleanup(struct netpoll *np)
820824

821825
RCU_INIT_POINTER(np->dev->npinfo, NULL);
822826
call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);
823-
} else
824-
RCU_INIT_POINTER(np->dev->npinfo, NULL);
827+
}
825828

826829
skb_pool_flush(np);
827830
}

tools/testing/selftests/drivers/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TEST_PROGS := \
1818
netcons_fragmented_msg.sh \
1919
netcons_overflow.sh \
2020
netcons_sysdata.sh \
21+
netcons_torture.sh \
2122
netpoll_basic.py \
2223
ping.py \
2324
psp.py \

tools/testing/selftests/drivers/net/bonding/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ TEST_PROGS := \
1414
dev_addr_lists.sh \
1515
mode-1-recovery-updelay.sh \
1616
mode-2-recovery-updelay.sh \
17+
netcons_over_bonding.sh \
1718
# end of TEST_PROGS
1819

1920
TEST_FILES := \
@@ -24,6 +25,7 @@ TEST_FILES := \
2425

2526
TEST_INCLUDES := \
2627
../../../net/lib.sh \
28+
../lib/sh/lib_netcons.sh \
2729
../../../net/forwarding/lib.sh \
2830
# end of TEST_INCLUDES
2931

tools/testing/selftests/drivers/net/bonding/config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CONFIG_BONDING=y
22
CONFIG_BRIDGE=y
3+
CONFIG_CONFIGFS_FS=y
34
CONFIG_DUMMY=y
45
CONFIG_INET_ESP=y
56
CONFIG_INET_ESP_OFFLOAD=y
@@ -9,6 +10,9 @@ CONFIG_MACVLAN=y
910
CONFIG_NET_ACT_GACT=y
1011
CONFIG_NET_CLS_FLOWER=y
1112
CONFIG_NET_CLS_MATCHALL=m
13+
CONFIG_NETCONSOLE=m
14+
CONFIG_NETCONSOLE_DYNAMIC=y
15+
CONFIG_NETCONSOLE_EXTENDED_LOG=y
1216
CONFIG_NETDEVSIM=m
1317
CONFIG_NET_SCH_INGRESS=y
1418
CONFIG_NLMON=y

0 commit comments

Comments
 (0)