All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] wireguard: peerlookup: avoid redundant peer pointer store
@ 2026-11-24 15:05 Zheng Shuhao
  2026-12-02 12:17 ` Paolo Abeni
  0 siblings, 1 reply; 3+ messages in thread
From: Zheng Shuhao @ 2026-11-24 15:05 UTC (permalink / raw)
  To: netdev
  Cc: Jason, wireguard, andrew+netdev, davem, edumazet, kuba, pabeni,
	syzbot+434045ea68296f3f0219

syzbot reported a KCSAN data race between
wg_index_hashtable_lookup() and wg_packet_decrypt_worker().

wg_index_hashtable_lookup() obtains a reference to entry->peer, then
writes the reference back to entry->peer. The peer pointer is set when
the index entry is initialized; the lookup does not need to modify it.
Packet workers read this field concurrently, so the redundant store
triggers the KCSAN report.

Keep the acquired reference in a local variable and return it through
the peer output parameter instead.

Testing:
- Built x86_64 with CONFIG_KCSAN=y and CONFIG_KCSAN_EARLY_ENABLE=y.
  CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY and
  CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC were unset.
- Ran a 120-second local QEMU stress test with bidirectional UDP traffic
  over two WireGuard network namespaces. Four iperf3 ports with -P 8
  generated 32 streams per direction (64 total). The baseline reported
  39 races involving wg_packet_decrypt_worker and 115 reports involving
  wg_index_hashtable_lookup overall. The patched kernel reported none
  involving wg_index_hashtable_lookup. Both runs completed successfully;
  unrelated KCSAN reports remained in the patched run.
- The upstream WireGuard QEMU selftest suite was not rerun with this
  exact KCSAN configuration.

Reported-by: syzbot+434045ea68296f3f0219@syzkaller.appspotmail.com
Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
Closes: https://syzkaller.appspot.com/bug?extid=434045ea68296f3f0219
Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
---
 drivers/net/wireguard/peerlookup.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireguard/peerlookup.c b/drivers/net/wireguard/peerlookup.c
index 99651a86ac953..6c8d41f12cc6d 100644
--- a/drivers/net/wireguard/peerlookup.c
+++ b/drivers/net/wireguard/peerlookup.c
@@ -204,6 +204,7 @@ wg_index_hashtable_lookup(struct index_hashtable *table,
 			  const __le32 index, struct wg_peer **peer)
 {
 	struct index_hashtable_entry *iter_entry, *entry = NULL;
+	struct wg_peer *peer_ref;
 
 	rcu_read_lock_bh();
 	hlist_for_each_entry_rcu_bh(iter_entry, index_bucket(table, index),
@@ -215,9 +216,9 @@ wg_index_hashtable_lookup(struct index_hashtable *table,
 		}
 	}
 	if (likely(entry)) {
-		entry->peer = wg_peer_get_maybe_zero(entry->peer);
-		if (likely(entry->peer))
-			*peer = entry->peer;
+		peer_ref = wg_peer_get_maybe_zero(entry->peer);
+		if (likely(peer_ref))
+			*peer = peer_ref;
 		else
 			entry = NULL;
 	}

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] wireguard: peerlookup: avoid redundant peer pointer store
  2026-11-24 15:05 [PATCH net] wireguard: peerlookup: avoid redundant peer pointer store Zheng Shuhao
@ 2026-12-02 12:17 ` Paolo Abeni
  2026-12-02 12:32   ` Jason A. Donenfeld
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Abeni @ 2026-12-02 12:17 UTC (permalink / raw)
  To: Zheng Shuhao, netdev
  Cc: Jason, wireguard, andrew+netdev, davem, edumazet, kuba,
	syzbot+434045ea68296f3f0219

On 11/24/26 16:05, Zheng Shuhao wrote:
> syzbot reported a KCSAN data race between
> wg_index_hashtable_lookup() and wg_packet_decrypt_worker().
> 
> wg_index_hashtable_lookup() obtains a reference to entry->peer, then
> writes the reference back to entry->peer. The peer pointer is set when
> the index entry is initialized; the lookup does not need to modify it.
> Packet workers read this field concurrently, so the redundant store
> triggers the KCSAN report.
> 
> Keep the acquired reference in a local variable and return it through
> the peer output parameter instead.
> 
> Testing:
> - Built x86_64 with CONFIG_KCSAN=y and CONFIG_KCSAN_EARLY_ENABLE=y.
>    CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY and
>    CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC were unset.
> - Ran a 120-second local QEMU stress test with bidirectional UDP traffic
>    over two WireGuard network namespaces. Four iperf3 ports with -P 8
>    generated 32 streams per direction (64 total). The baseline reported
>    39 races involving wg_packet_decrypt_worker and 115 reports involving
>    wg_index_hashtable_lookup overall. The patched kernel reported none
>    involving wg_index_hashtable_lookup. Both runs completed successfully;
>    unrelated KCSAN reports remained in the patched run.
> - The upstream WireGuard QEMU selftest suite was not rerun with this
>    exact KCSAN configuration.
> 
> Reported-by: syzbot+434045ea68296f3f0219@syzkaller.appspotmail.com
> Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
> Closes: https://syzkaller.appspot.com/bug?extid=434045ea68296f3f0219
> Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
@Jason: I assume this will go via your tree first, please LMK if you
prefer we take it directly.

FTR, the data race looks harmless, this is net-next material,

/P

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] wireguard: peerlookup: avoid redundant peer pointer store
  2026-12-02 12:17 ` Paolo Abeni
@ 2026-12-02 12:32   ` Jason A. Donenfeld
  0 siblings, 0 replies; 3+ messages in thread
From: Jason A. Donenfeld @ 2026-12-02 12:32 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: Zheng Shuhao, netdev, wireguard, andrew+netdev, davem, edumazet,
	kuba, syzbot+434045ea68296f3f0219

Yes, this will go via my tree.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-02 12:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 15:05 [PATCH net] wireguard: peerlookup: avoid redundant peer pointer store Zheng Shuhao
2026-12-02 12:17 ` Paolo Abeni
2026-12-02 12:32   ` Jason A. Donenfeld

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.