Skip to content

Commit 484996b

Browse files
leitaogregkh
authored andcommitted
netpoll: fix IPv6 local-address corruption
[ Upstream commit 3bc179b ] netpoll_setup() decides whether to auto-populate the local source address by testing np->local_ip.ip, which only inspects the first 4 bytes of the union inet_addr storage. For an IPv6 netpoll whose caller-supplied local address has a zero high-32 bits (::1, ::<suffix>, IPv4-mapped ::ffff:a.b.c.d, etc.), this misdetects the address as unset (which they are not, but the first 4 bytes are empty), calls netpoll_take_ipv6() and overwrites it with whatever matching link-local/global address the device happens to expose first. Introduce a helper netpoll_local_ip_unset() that picks the correct family-aware test (ipv6_addr_any() for IPv6, !.ip for IPv4) and use it from netpoll_setup(). Reproducer is something like: echo "::2" > local_ip echo 1 > enabled cat local_ip # before this fix: 2001:db8::1 (caller-supplied ::2 was clobbered) # after this fix: ::2 Fixes: b7394d2 ("netpoll: prepare for ipv6") Signed-off-by: Breno Leitao <leitao@debian.org> Link: https://patch.msgid.link/20260424-netpoll_fix-v1-1-3a55348c625f@debian.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ebeb841 commit 484996b

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

net/core/netpoll.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,23 @@ static int netpoll_take_ipv4(struct netpoll *np, struct net_device *ndev)
750750
return 0;
751751
}
752752

753+
/*
754+
* Test whether the caller left np->local_ip unset, so that
755+
* netpoll_setup() should auto-populate it from the egress device.
756+
*
757+
* np->local_ip is a union of __be32 (IPv4) and struct in6_addr (IPv6),
758+
* so an IPv6 address whose first 4 bytes are zero (e.g. ::1, ::2,
759+
* IPv4-mapped ::ffff:a.b.c.d) must not be tested via the IPv4 arm —
760+
* doing so would misclassify a caller-supplied address as unset and
761+
* silently overwrite it with whatever address the device exposes.
762+
*/
763+
static bool netpoll_local_ip_unset(const struct netpoll *np)
764+
{
765+
if (np->ipv6)
766+
return ipv6_addr_any(&np->local_ip.in6);
767+
return !np->local_ip.ip;
768+
}
769+
753770
int netpoll_setup(struct netpoll *np)
754771
{
755772
struct net *net = current->nsproxy->net_ns;
@@ -793,7 +810,7 @@ int netpoll_setup(struct netpoll *np)
793810
rtnl_lock();
794811
}
795812

796-
if (!np->local_ip.ip) {
813+
if (netpoll_local_ip_unset(np)) {
797814
if (!np->ipv6) {
798815
err = netpoll_take_ipv4(np, ndev);
799816
if (err)

0 commit comments

Comments
 (0)