Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: juanagusnicco@gmail.com
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, kuniyu@google.com,
	willemb@google.com, willemdebruijn.kernel@gmail.com,
	dsahern@kernel.org, idosch@nvidia.com, shuah@kernel.org,
	tpluszz77@gmail.com, brauner@kernel.org,
	alice.kernel@fastmail.im, kylebot@openai.com, joe@dama.to,
	leitao@debian.org, xudu@redhat.com, netdev@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2 1/3] udp: Keep the bound device on disconnect unless connect() set it
Date: Tue, 01 Dec 2026 05:29:11 +0000	[thread overview]
Message-ID: <179610295120.3146.5772948202560480809@kernel.org> (raw)
In-Reply-To: <20261130050729.893-2-juanagusnicco@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] After the whole series, disconnect can still widen a
  connect()-narrowed device back to 'all devices' with no conflict…

--

udp: Keep the bound device on disconnect unless connect() set it

When __ip6_datagram_connect() sets the device of a socket that had none,
this commit records that in sk_userlocks as SOCK_CONNECT_DEV.
__udp_disconnect() then clears sk_bound_dev_if only when that flag is set.
IPv6 ping, raw and L2TP sockets now use a new ip6_datagram_disconnect(),
which takes the socket lock around __udp_disconnect().

> diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
> index bdaae1b64d25a..36f79b098113b 100644
> --- a/net/l2tp/l2tp_ip6.c
> +++ b/net/l2tp/l2tp_ip6.c
> @@ -441,7 +441,7 @@ static int l2tp_ip6_disconnect(struct sock *sk, int flags)
>  	if (sock_flag(sk, SOCK_ZAPPED))
>  		return 0;
>  
> -	return __udp_disconnect(sk, flags);
> +	return ip6_datagram_disconnect(sk, flags);
>  }

[Severity: High]
Can L2TP/IPv6 sockets still be used for the takeover that the commit
message describes?

This path clears a device set by connect() without a conflict check. That
is only safe if every bind conflict check ignores devices set by connect().
__l2tp_ip6_bind_lookup() still compares against the live device:

net/l2tp/l2tp_ip6.c:__l2tp_ip6_bind_lookup() {
    ...
		bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
		if (bound_dev_if && dif && bound_dev_if != dif)
			continue;
    ...
}

IPPROTO_L2TP sockets are SOCK_DGRAM, so CAP_NET_RAW is not needed. Could
an unprivileged user run this sequence?

1) Attacker A binds L2TP/IPv6 conn_id C with no device.

2) A connects to fe80::x with scope_id=eth0. The call chain
   l2tp_ip6_connect()->__ip6_datagram_connect()->ip6_datagram_connect_dev()
   sets sk_bound_dev_if=eth0 and SOCK_CONNECT_DEV.

3) While A is connected, victim V calls SO_BINDTODEVICE(eth1) and binds
   conn_id C. l2tp_ip6_bind() calls __l2tp_ip6_bind_lookup() with
   dif=eth1. A is skipped because its live device is eth0, so V's bind
   succeeds.

4) A calls connect(AF_UNSPEC). The call chain
   l2tp_ip6_disconnect()->ip6_datagram_disconnect()->__udp_disconnect()
   sees SOCK_CONNECT_DEV and sets sk_bound_dev_if=0.

   l2tp_ip6_unhash() only touches sk_node, so A stays in
   l2tp_ip6_bind_table. Without SOCK_BINDADDR_LOCK, inet_reset_saddr()
   also turns A's local address into a wildcard.

5) A connects to a non-scoped peer P. No device is set, and A moves to the
   head of the bind list. On receive, __l2tp_ip6_bind_lookup() then returns
   A ahead of V for conn_id C traffic from P, on any device.

A later commit in this series, "udp: Ignore a connect()-set device in the
bind conflict check", fixes the UDP side. It changes udp_lib_lport_inuse()
and udp_lib_lport_inuse2() to use udp_bound_dev_if(), which returns 0 for
a SOCK_CONNECT_DEV socket.

I couldn't find a matching change to __l2tp_ip6_bind_lookup() anywhere in
the series. Should L2TP/IPv6 get the same treatment, given that this patch
moves it to the new disconnect behaviour?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130050729.893-1-juanagusnicco%40gmail.com

  reply	other threads:[~2026-12-01  5:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  5:07 [PATCH net v2 0/3] udp: Fix bind conflict check bypasses Juan Agustin Niccolini
2026-11-30  5:07 ` [PATCH net v2 1/3] udp: Keep the bound device on disconnect unless connect() set it Juan Agustin Niccolini
2026-12-01  5:29   ` netdev-bot+sashiko [this message]
2026-11-30  5:07 ` [PATCH net v2 2/3] udp: Ignore a connect()-set device in the bind conflict check Juan Agustin Niccolini
2026-12-01  5:29   ` netdev-bot+sashiko
2026-11-30  5:07 ` [PATCH net v2 3/3] selftests: net: Add UDP bind conflict tests Juan Agustin Niccolini
2026-12-01  5:29   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179610295120.3146.5772948202560480809@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alice.kernel@fastmail.im \
    --cc=brauner@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=joe@dama.to \
    --cc=juanagusnicco@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=kylebot@openai.com \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=tpluszz77@gmail.com \
    --cc=willemb@google.com \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=xudu@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox