Article View: linux.kernel.netdev
Article #25371Re: [PATCH net v3] udp: preserve explicit sk_bound_dev_if across __udp_disconnect()
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 16:56
Date: Tue, 01 Dec 2026 16:56
235 lines
16748 bytes
16748 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 2
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] On IPv6 datagram sockets, an unprivileged user can still change
an explicit device binding without CAP_NET_RAW.
- [Medium] ping: ping_bind() fails to clear connect ifindex when
scoped_ifindex == dif
- [Low] The ping_bind() rework in net/ipv4/ping.c also fixes a second,
independent CAP_NET_RAW bypass and changes a user-visible error, and…
- [Low] The patch adds two CONFIG_IPV6-only fields to struct inet_sock in
include/net/inet_sock.h: `bool bound_dev_if_connect` after…
--
udp: preserve explicit sk_bound_dev_if across __udp_disconnect()
With this commit, __udp_disconnect() no longer always zeroes
sk_bound_dev_if. When an IPv6 connect() sets an implicit scoped interface,
the previous ifindex is recorded and then restored on disconnect. That
state is cleared on SO_BINDTODEVICE and scoped binds, and the socket lock
is now taken in the rawv6, pingv6 and l2tp_ip6 disconnect and bind paths.
> diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
> index 24cbabc245823..069b1586a10ad 100644
> --- a/include/net/inet_sock.h
> +++ b/include/net/inet_sock.h
> @@ -241,10 +241,16 @@ struct inet_sock {
> __u8 pmtudisc;
> __u8 rcv_tos;
> __u8 convert_csum;
> +#if IS_ENABLED(CONFIG_IPV6)
> + bool bound_dev_if_connect;
> +#endif
> int uc_index;
> int mc_index;
> __be32 mc_addr;
> u32 local_port_range; /* high << 16 | low */
> +#if IS_ENABLED(CONFIG_IPV6)
> + int bound_dev_if_orig;
> +#endif
[Severity: Low]
This isn't a bug, but Documentation/networking/net_cachelines/inet_sock.rst
lists the inet_sock fields and wasn't updated for bound_dev_if_connect and
bound_dev_if_orig. It still goes from convert_csum straight to uc_index and
ends at local_port_range.
Should entries for the two new fields be added there? The commit message
also makes a padding/layout claim that this file tracks.
[ ... ]
> diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
> index 223a0108b74cc..75416ab449ac2 100644
> --- a/net/ipv4/ping.c
> +++ b/net/ipv4/ping.c
[ ... ]
> @@ -378,7 +379,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
> return -EADDRNOTAVAIL;
>
> if (scoped)
> - sk->sk_bound_dev_if = addr->sin6_scope_id;
> + *scoped_ifindex = addr->sin6_scope_id;
> #endif
> } else {
> return -EAFNOSUPPORT;
> @@ -411,13 +412,10 @@ static void ping_set_saddr(struct sock *sk, struct sockaddr_unsized *saddr)
> int ping_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len)
> {
> struct inet_sock *isk = inet_sk(sk);
> + int scoped_ifindex = 0;
> unsigned short snum;
> + int dif;
> int err;
> - int dif = sk->sk_bound_dev_if;
> -
> - err = ping_check_bind_addr(sk, isk, uaddr, addr_len);
> - if (err)
> - return err;
>
> lock_sock(sk);
>
> @@ -425,11 +423,19 @@ int ping_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len)
> if (isk->inet_num != 0)
> goto out;
>
> + dif = sk->sk_bound_dev_if;
> + err = ping_check_bind_addr(sk, isk, uaddr, addr_len, &scoped_ifindex);
> + if (err)
> + goto out;
> +
[Severity: Medium]
Why is the clear here gated on scoped_ifindex != dif? Both
__inet6_bind() and rawv6_bind() call inet6_clear_connect_ifindex()
whenever the user supplies a scope id. ping_bind() skips it when the
scope id matches the current sk_bound_dev_if.
That matters when sk_bound_dev_if already equals the scope id because
of an earlier scoped connect(), so bound_dev_if_connect is still true.
This state is reachable:
- ping_bind() only rejects inet_num != 0 and never checks sk_state.
- inet_dgram_connect() drops the socket lock between inet_autobind()
and prot->connect().
- A concurrent connect(AF_UNSPEC) in that window goes through
udp_locked_disconnect() -> __udp_disconnect() -> ping_unhash(),
which resets inet_num to 0.
The original connect then carries on:
connect(fe80::y%X)
inet_autobind() inet_num = N, lock dropped
connect(AF_UNSPEC): inet_num = 0
__ip6_datagram_connect() sk_bound_dev_if = X,
bound_dev_if_orig = 0,
bound_dev_if_connect = true
bind(fe80::z%X)
inet_num == 0, scoped_ifindex == dif == X
inet6_clear_connect_ifindex() skipped
connect(AF_UNSPEC)
__udp_disconnect(): sk_bound_dev_if = bound_dev_if_orig (0)
After the last step the socket still has its link-local source address
under SOCK_BINDADDR_LOCK, but it has no interface binding. The user
explicitly bound it to X. This is the same silent loss of a binding
that this patch sets out to fix, and a ping_group_range user can
reach it without CAP_NET_RAW.
Should the condition simply be if (scoped_ifindex), matching
__inet6_bind() and rawv6_bind()? Or should ping_bind() also refuse a
socket that isn't in TCP_CLOSE, the way __inet6_bind() does?
[Severity: Low]
On this part of ping_bind(), the commit message body only says "hold the
socket lock across rawv6, pingv6, and l2tp_ip6 updates". The reordering
also changes behaviour in two ways that the body doesn't describe.
First, it closes a separate leak. Before this patch,
ping_check_bind_addr() wrote sk->sk_bound_dev_if = addr->sin6_scope_id
before lock_sock() and before the inet_num double-bind check. The -EINVAL
double-bind path never restored dif. So bind(fe80::x%B) on an
already-bound pingv6 socket left sk_bound_dev_if set to B and then
returned -EINVAL. That overrode an explicit SO_BINDTODEVICE without a
disconnect.
Second, it changes which error comes first. A second bind() on a bound
ping socket now returns -EINVAL before any address validation. Before, it
could return -EAFNOSUPPORT, -EINVAL, -ENODEV or -EADDRNOTAVAIL.
Could the commit message describe both of these? Right now the reasoning
is only in the v3 changelog below the --- line, which is dropped when the
patch is applied.
[ ... ]
> diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
> index b85125c3f14bd..7e05ec0b12075 100644
> --- a/net/ipv6/af_inet6.c
> +++ b/net/ipv6/af_inet6.c
> @@ -341,6 +341,7 @@ int __inet6_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len,
> * is supplied by user.
> */
> sk->sk_bound_dev_if = addr->sin6_scope_id;
> + inet6_clear_connect_ifindex(sk);
> }
>
> /* Binding to link-local address requires an interface */
[Severity: High]
The commit message assumes that once a socket has an explicit device
binding, only CAP_NET_RAW can clear it. Does that hold for IPv6 datagram
sockets?
Here __inet6_bind() replaces sk_bound_dev_if with the user's
sin6_scope_id. There is no ns_capable(CAP_NET_RAW) or
sk_dev_equal_l3scope() check. The new value also stays in place if bind()
later fails with -ENODEV, -EADDRNOTAVAIL or -EADDRINUSE.
The same unchecked override is in rawv6_bind(), in ping_bind() through
scoped_ifindex, and in l2tp_ip6_bind(). At each of these assignments the
patch adds inet6_clear_connect_ifindex() but leaves the override itself
ungated.
__ip6_datagram_connect(), by contrast, rejects a scope id outside the
socket's L3 scope:
if (!sk_dev_equal_l3scope(sk, usin->sin6_scope_id)) {
err = -EINVAL;
goto out;
}
This works directly on a fresh device-bound socket (TCP_CLOSE,
inet_num == 0). For an autobound socket that is already in use, the
disconnect path changed here reopens bind(). SOCK_BINDPORT_LOCK is clear
in that case, so:
__udp_disconnect()
sk->sk_prot->unhash(sk)
udp_lib_unhash()
inet_sk(sk)->inet_num = 0;
So for a socket bound to device A through SO_BINDTODEVICE or ip vrf exec:
bind(fe80::<addr on B>%B, 0) /* or any fe80:: with IPV6_FREEBIND */
sk_bound_dev_if: A -> B
connect(AF_UNSPEC)
unhash, inet_num = 0
bind(::, 0)
socket now bound to B with a wildcard address
Doesn't this still let an unprivileged user leave the device or VRF
binding that c427bfec18f2 restricts to CAP_NET_RAW? pingv6 (for
ping_group_range users) and l2tp_ip6 sockets behave the same way.
Should these scoped bind overrides get the same CAP_NET_RAW or l3scope
check? If not, should the commit message state the limitation? At the
moment only the v3 notes below the --- line say scoped bind behaviour is
unchanged.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130160430.2657088-1-dmnk%40google.com
Technical Details
Message-ID:
<179614420812.3146.6814639156432707669@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375221-linux-kernel-netdev=dewy.ruReferences:
<20261130160430.2657088-1-dmnk@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375221-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v3] udp: preserve explicit sk_bound_dev_if across __udp_disconnect() Date: Tue, 01 Dec 2026 16:56:48 +0000 Organization: Usenet Network Message-ID: <179614420812.3146.6814639156432707669@kernel.org> References: <20261130160430.2657088-1-dmnk@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1770964"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:8bIH6m1eNzlFQYDynh9Ga0aB1Pg= sha256:z+r+BaVrl1+vdv5qek2i7CQL0koUJzK2K01lI9TjWbY= sha1:Q0FlJpcEUniXLzqX1J4X2T/RFlo= sha256:vomQjIGSnBVwADmSBXiWp0jXW5VX5aJxDaFCtn9FhAA= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 77B4C117421; Tue, 1 Dec 2026 19:57:22 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id P-O0sqMTcT-G; Tue, 1 Dec 2026 19:57:18 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375221-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 0279111740F; Tue, 1 Dec 2026 19:57:09 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 8708128B4E; Tue, 1 Dec 2026 16:56:51 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796144210; b=0wPqd7GOvd8URuPr1Nn2GMvNbpmBbtROe5YIBt5I4JOtaWDqKLb8N0t77E3ki+y76UVo 8LJpv6aZ9mbFm/iBTW/1y4E95mnPMlZF/tcnilM7IpvnxGerg7oU9bOJzSL2UW9qVIH0N tiCx+CTnW3uphuwKLDAd0I9QnylsfyGQu1yGG/uv3bufTGNEa2oZDqj0heEkxmL75/JXI CIQuV6bFU0T+d2+XjnKgKOVUb7e05hYOjezqv75kA4i8u8MYOAB/a3ncqVJTP4tiNTuFk f+sigJxwGdrfvS46XyvWOi/0QlZ3sYGweTdK8y6Fvf9vA2lXH/nZU10Sh/5kVaRKDYw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144210; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=s8sbgk7BNdbe2+Lj78dDZh+0CeSsGS8DdS+lI/QVkxA=; b=XAFNKyI8bqLI6kLvsM+MAkIWLW+K4WQjmZzUJOvHBqsALVFvWUXYX3imr0P0aS98SszM asHnOkAnf+l4RRq9KM9P8V2BwZSpLs5soLjrMfgIMzOpcPgdgQotVpWFC6ulCIAcFRcc2 gfk2MNEziF7IXsdfegEDZT9whzLzhI628dN232BWq49yRrXURc08EHpJQEIdzm1qeIl+9 wP/nDBImcVogs5/1VaEF/uyEvZ5fUr0mA5QwBbo601LECMEQG7ZG+D0jx9TGo8Rd2+uih oFKiMvX1B45Gtjfq3m6z5pZNpudB8RlWDhWWWTJNnGkAePKcSfRrpj1d5N9940/j9ZQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R+ARv7Nr; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F8D4606A332; Tue, 1 Dec 2026 16:56:50 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R+ARv7Nr X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144209; b=IOAwi1CAwLNFj/Y65lQNLYmdLMLbO7mNI3ObmbJ1DiYZIO+Gd8zl1naARvSIZ8SESSno uFUQh/4M+Y+YR5QFFQSjG2kbj5I2RaKgn81QUc2sqw80IhcIGM0lzj7JPL1h6cZkVGeNn u45p/yrtSx8QxaFpKW2IV0snvynamw5sHBuEyOcAAd+E7rLhD9JGWb0aIns8yBs+/3yL4 vsu4c2supSIFpkfjEdYNO173znNqih65zw5NcWcfCG6b2U0ihB+ScgWz4s5ZCRSIVc42f faRbh4N8mOHwV69o5yQ6h+GwahbPV/8VbgiG5qdEQ1C5LbKx4g72oUM6HbYaFqfMN+A== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144209; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=s8sbgk7BNdbe2+Lj78dDZh+0CeSsGS8DdS+lI/QVkxA=; b=yeUKlOSKIjd3Vz75E5DFbJjbQ2x9+bF9X9i0OAvVmKJ/BP4c+EJMQuM9adJHv1suKS2c vw10v3HiU4xJPhaNiRz6SXh5QH+8PwSGlnwVfgTD2m9ZauWA6i8hpsjDDxfYkvJuuXpYo QkcOPtJbDAcVK+JrbHHzxTTZRItWtL8Zq7lOEKFmAgV4PGRhhWYvsaoXxlNEFGiYzoq8t 4CNA2vLzh7yMyYphIbEg0j18WZSwe2SG+bK71mTdHyfJO6Wc+N99oBNfmlJX/LXsOhqs3 8H2pkjKMByC7lzeG02N/T5ikuEyLQ5SUr07oDRRQuqa2vRrvbj45UYOALbCWnrtnGtw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R+ARv7Nr; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C929606A320 for <netdev@vger.kernel.org>; Tue, 1 Dec 2026 16:56:49 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E1901F00899; Tue, 1 Dec 2026 16:56:48 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796144209; bh=s8sbgk7BNdbe2+Lj78dDZh+0CeSsGS8DdS+lI/QVkxA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=R+ARv7Nr2MMcPlVldtLR6Db7CLO+TPcitRsCkP/zvyXbhXdrkqXNndWyQkLhetYhv NAMIjFfV+fAjo5bNkhoo+XhL11tppTxXPLUSTO921533pKCovFfh8mrk57BOOvFDYE wG3R3h4eYJVZQgYsyQmLMgV/Enf7a9OoyB65Q8TuG/+hlXST5O7d+D9LeQKNtJbeCB swKTGWscp8W+il0Zwy9mAJyHLTo9rnKaQEMFV9k75CPCplQ/niYz7MswnDxVKNA852 YF2VgOZtECywSMHr8oFYMKmSAvtIaQaA0V3Yi19e4V1EsQYs707DKhpHjm53tCv8qJ X7S/DQQtYplHg== X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, horms@kernel.org, willemdebruijn.kernel@gmail.com, kuniyu@google.com, netdev@vger.kernel.org, dmnk+artist@google.com X-In-Reply-To: <20261130160430.2657088-1-dmnk@google.com> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list