[PATCH] wireguard: do not use sin6_scope_id if not needed

Torin Carey torin at tcarey.uk
Mon Sep 15 11:58:39 UTC 2025


sin6_scope_id should only be used if the address is link-local and
otherwise ignored.

Currently send6 uses the sin6_scope_id for flowi6_oif without a check of
whether this is needed, so this can cause non-link local endpoints to
use an incorrect device.

Signed-off-by: Torin Carey <torin at tcarey.uk>
---
 drivers/net/wireguard/netlink.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireguard/netlink.c b/drivers/net/wireguard/netlink.c
index 67f962eb8b46..738041f72c2b 100644
--- a/drivers/net/wireguard/netlink.c
+++ b/drivers/net/wireguard/netlink.c
@@ -453,6 +453,8 @@ static int set_peer(struct wg_device *wg, struct nlattr **attrs)
 			wg_socket_set_peer_endpoint(peer, &endpoint);
 		} else if (len == sizeof(struct sockaddr_in6) && addr->sa_family == AF_INET6) {
 			endpoint.addr6 = *(struct sockaddr_in6 *)addr;
+			if (!__ipv6_addr_needs_scope_id(ipv6_addr_type(&endpoint.addr6.sin6_addr)))
+				endpoint.addr6.sin6_scope_id = 0;
 			wg_socket_set_peer_endpoint(peer, &endpoint);
 		}
 	}

base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
-- 
2.48.1




More information about the WireGuard mailing list