sst-linux/net/core
Gavrilov Ilia fcfc00bfec drop_monitor: fix incorrect initialization order
commit 07b598c0e6f06a0f254c88dafb4ad50f8a8c6eea upstream.

Syzkaller reports the following bug:

BUG: spinlock bad magic on CPU#1, syz-executor.0/7995
 lock: 0xffff88805303f3e0, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0
CPU: 1 PID: 7995 Comm: syz-executor.0 Tainted: G            E     5.10.209+ #1
Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x119/0x179 lib/dump_stack.c:118
 debug_spin_lock_before kernel/locking/spinlock_debug.c:83 [inline]
 do_raw_spin_lock+0x1f6/0x270 kernel/locking/spinlock_debug.c:112
 __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:117 [inline]
 _raw_spin_lock_irqsave+0x50/0x70 kernel/locking/spinlock.c:159
 reset_per_cpu_data+0xe6/0x240 [drop_monitor]
 net_dm_cmd_trace+0x43d/0x17a0 [drop_monitor]
 genl_family_rcv_msg_doit+0x22f/0x330 net/netlink/genetlink.c:739
 genl_family_rcv_msg net/netlink/genetlink.c:783 [inline]
 genl_rcv_msg+0x341/0x5a0 net/netlink/genetlink.c:800
 netlink_rcv_skb+0x14d/0x440 net/netlink/af_netlink.c:2497
 genl_rcv+0x29/0x40 net/netlink/genetlink.c:811
 netlink_unicast_kernel net/netlink/af_netlink.c:1322 [inline]
 netlink_unicast+0x54b/0x800 net/netlink/af_netlink.c:1348
 netlink_sendmsg+0x914/0xe00 net/netlink/af_netlink.c:1916
 sock_sendmsg_nosec net/socket.c:651 [inline]
 __sock_sendmsg+0x157/0x190 net/socket.c:663
 ____sys_sendmsg+0x712/0x870 net/socket.c:2378
 ___sys_sendmsg+0xf8/0x170 net/socket.c:2432
 __sys_sendmsg+0xea/0x1b0 net/socket.c:2461
 do_syscall_64+0x30/0x40 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x62/0xc7
RIP: 0033:0x7f3f9815aee9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f3f972bf0c8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007f3f9826d050 RCX: 00007f3f9815aee9
RDX: 0000000020000000 RSI: 0000000020001300 RDI: 0000000000000007
RBP: 00007f3f981b63bd R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000006e R14: 00007f3f9826d050 R15: 00007ffe01ee6768

If drop_monitor is built as a kernel module, syzkaller may have time
to send a netlink NET_DM_CMD_START message during the module loading.
This will call the net_dm_monitor_start() function that uses
a spinlock that has not yet been initialized.

To fix this, let's place resource initialization above the registration
of a generic netlink family.

Found by InfoTeCS on behalf of Linux Verification Center
(linuxtesting.org) with Syzkaller.

Fixes: 9a8afc8d39 ("Network Drop Monitor: Adding drop monitor implementation & Netlink protocol")
Cc: stable@vger.kernel.org
Signed-off-by: Ilia Gavrilov <Ilia.Gavrilov@infotecs.ru>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Link: https://patch.msgid.link/20250213152054.2785669-1-Ilia.Gavrilov@infotecs.ru
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-03-07 16:56:38 +01:00
..
bpf_sk_storage.c bpf: Refactor some inode/task/sk storage functions for reuse 2024-07-18 13:18:34 +02:00
datagram.c net: fix rc7's __skb_datagram_iter() 2024-07-18 13:18:33 +02:00
dev_addr_lists_test.c
dev_addr_lists.c
dev_ioctl.c
dev.c net: Add non-RCU dev_getbyhwaddr() helper 2025-03-07 16:56:36 +01:00
dev.h
drop_monitor.c drop_monitor: fix incorrect initialization order 2025-03-07 16:56:38 +01:00
dst_cache.c
dst.c net: do not delay dst_entries_add() in dst_release() 2024-11-14 13:15:17 +01:00
failover.c
fib_notifier.c
fib_rules.c
filter.c bpf: tcp: Mark bpf_load_hdr_opt() arg2 as read-write 2025-02-21 13:49:09 +01:00
flow_dissector.c flow_dissector: Fix port range key handling in BPF conversion 2025-03-07 16:56:35 +01:00
flow_offload.c
gen_estimator.c net: use unrcu_pointer() helper 2024-12-14 19:53:33 +01:00
gen_stats.c
gro_cells.c
gro.c
hwbm.c
link_watch.c net: linkwatch: use system_unbound_wq 2024-08-14 13:52:44 +02:00
lwt_bpf.c
lwtunnel.c
Makefile
neighbour.c neighbour: use RCU protection in __neigh_notify() 2025-02-21 13:50:08 +01:00
net_namespace.c net: add exit_batch_rtnl() method 2025-01-23 17:17:09 +01:00
net-procfs.c
net-sysfs.c ethtool: check device is present when getting link settings 2024-09-04 13:25:01 +02:00
net-sysfs.h
net-traces.c
netclassid_cgroup.c
netevent.c
netpoll.c netpoll: Use rcu_access_pointer() in __netpoll_setup 2024-12-14 19:54:45 +01:00
netprio_cgroup.c
of_net.c
page_pool.c
pktgen.c pktgen: Avoid out-of-bounds access in get_imix_entries 2025-01-23 17:17:09 +01:00
ptp_classifier.c
request_sock.c
rtnetlink.c net: fix crash when config small gso_max_size/gso_ipv4_max_size 2024-12-14 19:53:11 +01:00
scm.c
secure_seq.c
selftests.c
skbuff.c net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX 2024-08-29 17:30:43 +02:00
skmsg.c bpf: Fix wrong copied_seq calculation 2025-03-07 16:56:37 +01:00
sock_destructor.h
sock_diag.c net: use unrcu_pointer() helper 2024-12-14 19:53:33 +01:00
sock_map.c bpf, sockmap: Fix race between element replace and close() 2025-01-17 13:34:36 +01:00
sock_reuseport.c
sock.c net: restrict SO_REUSEPORT to inet sockets 2025-01-09 13:30:02 +01:00
stream.c
sysctl_net_core.c net: let net.core.dev_weight always be non-zero 2025-02-21 13:49:05 +01:00
timestamping.c
tso.c
utils.c
xdp.c xdp: fix invalid wait context of page_pool_destroy() 2024-08-03 08:49:09 +02:00