linux/drivers/net/wireguard
Yury Norov (NVIDIA) 5bd8de2077 wireguard: queueing: always return valid online CPU in wg_cpumask_choose_online()
The function gets number of online CPUS, and uses it to search for
Nth cpu in cpu_online_mask.

If id == num_online_cpus() - 1, and one CPU gets offlined between
calling num_online_cpus() -> cpumask_nth(), there's a chance for
cpumask_nth() to find nothing and return >= nr_cpu_ids.

The caller code in __queue_work() tries to avoid that by checking the
returned CPU against WORK_CPU_UNBOUND, which is NR_CPUS. It's not the
same as '>= nr_cpu_ids'. On a typical Ubuntu desktop, NR_CPUS is 8192,
while nr_cpu_ids is the actual number of possible CPUs, say 8.

The non-existing cpu may later be passed to rcu_dereference() and
corrupt the logic. Fix it by switching from 'if' to 'while'.

Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Link: https://patch.msgid.link/20250910013644.4153708-3-Jason@zx2c4.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-09-11 18:52:21 -07:00
..
selftest wireguard: allowedips: add WGALLOWEDIP_F_REMOVE_ME flag 2025-05-27 09:06:19 +02:00
allowedips.c wireguard: allowedips: add WGALLOWEDIP_F_REMOVE_ME flag 2025-05-27 09:06:19 +02:00
allowedips.h wireguard: allowedips: add WGALLOWEDIP_F_REMOVE_ME flag 2025-05-27 09:06:19 +02:00
cookie.c wireguard: global: add __nonstring annotations for unterminated strings 2025-05-27 09:06:19 +02:00
cookie.h
device.c net: Use netif_threaded_enable instead of netif_set_threaded in drivers 2025-07-24 18:34:55 -07:00
device.h
main.c genetlink: remove linux/genetlink.h 2024-04-01 21:44:34 -07:00
Makefile
messages.h
netlink.c wireguard: allowedips: add WGALLOWEDIP_F_REMOVE_ME flag 2025-05-27 09:06:19 +02:00
netlink.h
noise.c wireguard: global: add __nonstring annotations for unterminated strings 2025-05-27 09:06:19 +02:00
noise.h
peer.c
peer.h wireguard: peer: Replace sockaddr with sockaddr_inet 2025-07-25 15:29:58 -07:00
peerlookup.c
peerlookup.h
queueing.c
queueing.h wireguard: queueing: always return valid online CPU in wg_cpumask_choose_online() 2025-09-11 18:52:21 -07:00
ratelimiter.c
ratelimiter.h
receive.c wireguard: receive: annotate data-race around receiving_counter.counter 2024-03-19 11:22:49 +01:00
send.c wireguard: send: annotate intentional data race in checking empty queue 2024-07-05 17:21:10 -07:00
socket.c net: ipv6: Add a flags argument to ip6tunnel_xmit(), udp_tunnel6_xmit_skb() 2025-06-17 18:18:45 -07:00
socket.h
timers.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
timers.h
version.h