wg_cpumask_choose_online() reads and writes the per-peer serial_work_cpu without annotation, while wg_cpumask_next_online() already uses READ_ONCE() and WRITE_ONCE() for last_cpu. Since both are called from the crypto workers, KCSAN reports a data race on the field: BUG: KCSAN: data-race in wg_packet_encrypt_worker / wg_packet_encrypt_worker read to 0xffff88811ac90080 of 4 bytes by task 3410 on cpu 0: wg_cpumask_choose_online drivers/net/wireguard/queueing.h:107 wg_queue_enqueue_per_peer_tx drivers/net/wireguard/queueing.h:183 write to 0xffff88811ac90080 of 4 bytes by task 15243 on cpu 1: wg_cpumask_choose_online drivers/net/wireguard/queueing.h:110 The race is harmless, as the value is only a hint for queue_work_on(), but it should not be left as a plain access. Use READ_ONCE() and WRITE_ONCE() like the sibling function does. Reported-by: syzbot+75273239c9ffd7dc304f@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/6a859c89.f7a79266.2f965f.003e.GAE@google.com/ Fixes: e7096c131e51 ("net: WireGuard secure network tunnel") Signed-off-by: Aibing Chen --- drivers/net/wireguard/queueing.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h index 663b19b78..875dc463c 100644 --- a/drivers/net/wireguard/queueing.h +++ b/drivers/net/wireguard/queueing.h @@ -106,10 +106,12 @@ static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating) static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id) { - unsigned int cpu = *stored_cpu; + unsigned int cpu = READ_ONCE(*stored_cpu); - while (unlikely(cpu >= nr_cpu_ids || !cpu_online(cpu))) - cpu = *stored_cpu = cpumask_nth(id % num_online_cpus(), cpu_online_mask); + while (unlikely(cpu >= nr_cpu_ids || !cpu_online(cpu))) { + cpu = cpumask_nth(id % num_online_cpus(), cpu_online_mask); + WRITE_ONCE(*stored_cpu, cpu); + } return cpu; }