Re: [PATCH] wireguard: socket: fix sticky source address on p2p

From: Jason A. Donenfeld

Date: Tue Nov 10 2026 - 12:51:13 EST


On Tue, Nov 10, 2026 at 5:47 PM David Woodhouse <dwmw2@xxxxxxxxxxxxx> wrote:
>
> On Tue, 2026-11-10 at 17:12 +0100, Jason A. Donenfeld wrote:
> >
> > Hmm... How did you choose __ip_dev_find() over, say,
> > inet_lookup_ifaddr_rcu(), which is structurally more similar to
> > ipv6_chk_addr()?
>
> __ip_dev_find() is what's exported to modules. It internally takes the
> RCU lock and calls inet_lookup_ifaddr_rcu(). It also falls back to a
> RT_TABLE_LOCAL lookup, which I think is the right thing here too.

Okay, makes sense.

This simple patch reproduces the issue in the test suite (and confirms
your fix):

diff --git a/tools/testing/selftests/wireguard/netns.sh
b/tools/testing/selftests/wireguard/netns.sh
index a8f550aecb35..5dfecb4c6ef1 100755
--- a/tools/testing/selftests/wireguard/netns.sh
+++ b/tools/testing/selftests/wireguard/netns.sh
@@ -474,7 +474,7 @@ n2 ping -W 1 -c 1 192.168.241.1

# What happens if the inbound destination address belongs to a
different interface as the default route?
ip1 link add dummy0 type dummy
-ip1 addr add 10.50.0.1/24 dev dummy0
+ip1 addr add 10.50.0.1 peer 10.50.0.2/32 dev dummy0
ip1 link set dummy0 up
ip2 route add 10.50.0.0/24 dev veth2
n2 wg set wg0 peer "$pub1" endpoint 10.50.0.1:1


So I'll add a followup commit adding this to netns.sh.

Thanks for fixing this! Applied to the wireguard repo.


Jason