Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Xia Yan
Thu, 29 Oct 2026 13:58
[PATCH net] ipv6: fix device binding after failed datagram connect
Author: Xia Yan
Date: Thu, 29 Oct 2026 13:58
Date: Thu, 29 Oct 2026 13:58
70 lines
11204 bytes
11204 bytes
__ip6_datagram_connect() can change sk_bound_dev_if when connecting to
an address that needs a scope ID. If ip6_datagram_dst_update() fails,
the old peer address and port are restored, but the new device binding
is left behind.
A UDP socket can then keep reporting its original peer while sends and
attempts to reconnect to that peer fail with ENETUNREACH. Replies to the
socket are also dropped by the device match. The same problem occurs
when a scoped multicast destination picks up np->mcast_oif.
Save the original binding before processing the scope and restore it
along with the peer information on failure. This completes the rollback
in commit 2f987a76a977 ("net: ipv6: keep sk status consistent after
datagram connect failure") and preserves the new binding on success.
Found while reviewing scope-ID handling in __ip6_datagram_connect().
Confirmed by exchanging UDP traffic over ::1, then attempting a link-local
connect with a nonexistent scope ifindex or a down interface. After that
connect fails, the original peer is still reported but communication and
reconnecting to it fail.
Tested before and after the fix in UML for three rounds, covering explicit
scopes, multicast interface fallback, initially unconnected sockets and
existing bindings. With the fix, the old binding and peer are retained,
and traffic and reconnection to the original peer work. Also built on
x86_64 with W=1 using adjusted allmodconfig and allyesconfig
configurations, with no new warnings.
Fixes: 2f987a76a977 ("net: ipv6: keep sk status consistent after datagram connect failure")
Cc: stable@vger.kernel.org
Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
---
net/ipv6/datagram.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index 191c9733ff9fa..ff7a7ffbf9833 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -149,6 +149,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
__be32 fl6_flowlabel = 0;
__be32 old_fl6_flowlabel;
__be16 old_dport;
+ int old_bound_dev_if;
int addr_type;
int err;
@@ -219,6 +220,8 @@ ipv4_connected:
goto out;
}
+ old_bound_dev_if = sk->sk_bound_dev_if;
+
if (__ipv6_addr_needs_scope_id(addr_type)) {
if (addr_len >= sizeof(struct sockaddr_in6) &&
usin->sin6_scope_id) {
@@ -261,6 +264,7 @@ ipv4_connected:
sk->sk_v6_daddr = old_daddr;
np->flow_label = old_fl6_flowlabel;
inet->inet_dport = old_dport;
+ WRITE_ONCE(sk->sk_bound_dev_if, old_bound_dev_if);
goto out;
}
base-commit: d7314b51341c037973ce022f12c6009fd07b021e
--
2.39.0.windows.2
Re: [PATCH net] ipv6: fix device binding after failed datagram connect
Author: patchwork-bot+netdevbpf
Date: Tue, 03 Nov 2026 21:20
Date: Tue, 03 Nov 2026 21:20
27 lines
8850 bytes
8850 bytes
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Thu, 29 Oct 2026 21:58:22 +0800 you wrote:
> __ip6_datagram_connect() can change sk_bound_dev_if when connecting to
> an address that needs a scope ID. If ip6_datagram_dst_update() fails,
> the old peer address and port are restored, but the new device binding
> is left behind.
>
> A UDP socket can then keep reporting its original peer while sends and
> attempts to reconnect to that peer fail with ENETUNREACH. Replies to the
> socket are also dropped by the device match. The same problem occurs
> when a scoped multicast destination picks up np->mcast_oif.
>
> [...]
Here is the summary with links:
- [net] ipv6: fix device binding after failed datagram connect
https://git.kernel.org/netdev/net/c/bc53aab4881a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads