From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Tue, 1 Dec 2026 16:56:49 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E1901F00899; Tue, 1 Dec 2026 16:56:48 +0000 (UTC) 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== Subject: Re: [PATCH net v3] udp: preserve explicit sk_bound_dev_if across __udp_disconnect() From: netdev-bot+sashiko@kernel.org To: dmnk@google.com 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 Date: Tue, 01 Dec 2026 16:56:48 +0000 Message-ID: <179614420812.3146.6814639156432707669@kernel.org> In-Reply-To: <20261130160430.2657088-1-dmnk@google.com> References: <20261130160430.2657088-1-dmnk@google.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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::%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