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=1795892590; b=JhxQxArXC3VKOzPAyGwu/uea5ZvFNegUvwLv/1nULq37OtS674sfpmvFIWCfr5W2ctAm 2ESLgYEH6eq1UOPnfiq9n6L8WvIA5f2wRWbRRgvkh+1q2f130qLwoFkxSVOTRmEs3taqK 0qKFxaGPuC5s+3H58hjfqlNFTTuuhMyiScXbUvBT72Wo27tBV4AAT8zhpgePAK84x+drF XwC0Srb9zpc8ihlLJXx78U5MDM0moBx7CVFNfT+BWfYGsrapJPMCDa6pcuYDw2jilvQE0 HL6LjxJFon6FmdUquA+OP3C4bsM/wnoA1JZX0MF/zDcS+mYdLnZlseWLzoOTRaE3CZg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795892590; 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=t4Fd8lFlLhdoLH7tySUa7ijYZM/Ky5Fb1n1moVtF5Wg=; b=mHJ+CXw65CrU9EWPjMkIEtgnDs5SUs47qh0twoCPCu2ShY0d3+hih7EcHbjGYsGJ3Zzs qI1sd9wn4VfSeCWfWwj9Qwrv5jnYcIqFYfQhsY+ulcVWbWkekKVkW39hwx0iDsxlnzS2+ AO1brycSyId8SdNJcTtM91LhxzWaJJkwqQ8A7V3OBomugThL636GZVWW/VCACkulVy8HB v63dZ8M0NmintGIU0L8atu8nBu2t96/BB0JBIrHb9tHlh5H7N6nXG42kKehf6N9/9ymf4 zuTMVR7fEj++SZ+Vvsh7C2HhMJU6n8EodZSE9WWYXkDiPp6oijLE3LK5kcF53CZCyEQ== 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=H5cGmgNH; 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 BDA15606A31C for ; Sat, 28 Nov 2026 19:03:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=H5cGmgNH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 042781F00893; Sat, 28 Nov 2026 19:03:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795892590; bh=t4Fd8lFlLhdoLH7tySUa7ijYZM/Ky5Fb1n1moVtF5Wg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=H5cGmgNH0RwUmYjeXTmTxpjaQrRQJD1FRfMDA/OJjU02x2h1FyqeMXGbaVMwnqgZi 1onpJPERBUYvtfNkbnE/7Y6Kaqf0fLv+ocASwmjEV8GAmhGcqUyjnPAANnoiYW9Zpa HeIS/+/TFg5s2LSeK2aH+5jyzVN7xv0Kh2Kd39RhvpOyZyunMqrYx8seZ33V5Anfw+ HmShNgV++9vN354dcL1vU0FAJYdK3mSK/gNRK4WayU9aeGkgSND8c63ayv3TTz8Jc/ x7GinVQGVIA9hSqE77aggxjlwAiiubc+LugX/dPXB410UHORol7BU6z4us0EU/uqX8 4vUUl0iYDidVg== Subject: Re: [PATCH net v2] udp: preserve explicit sk_bound_dev_if across __udp_disconnect() From: netdev-bot+sashiko@kernel.org To: dmnk@google.com Cc: willemdebruijn.kernel@gmail.com, edumazet@kernel.org, kuniyu@google.com, pabeni@redhat.com, davem@davemloft.net, kuba@kernel.org, horms@kernel.org, dsahern@kernel.org, netdev@vger.kernel.org, dmnk+artist@google.com Date: Sat, 28 Nov 2026 19:03:09 +0000 Message-ID: <179589258952.3135.7000335148299611948@kernel.org> In-Reply-To: <20261124180603.72523-1-dmnk@google.com> References: <20261124180603.72523-1-dmnk@google.com> X-sashiko-severity: Medium 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 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · 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). - [Medium] Every IPv6 bind() path still lets an unprivileged user change sk_bound_dev_if, with no CAP_NET_RAW check and no L3-scope check. - [Medium] ping_bind() changes sk->sk_bound_dev_if without holding the socket lock, and on its -EINVAL path it never restores the old value. -- udp: preserve explicit sk_bound_dev_if across __udp_disconnect() This patch stops __udp_disconnect() from always zeroing sk_bound_dev_if. When __ip6_datagram_connect() changed the binding for a scoped peer, the old value is saved in struct inet_sock and restored on disconnect. The saved state is cleared on SO_BINDTODEVICE and scoped bind(), and the rawv6, pingv6 and l2tp_ip6 disconnect callbacks now take lock_sock(). > diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c > index 223a0108b74cc..a160c24323d9f 100644 > --- a/net/ipv4/ping.c > +++ b/net/ipv4/ping.c > @@ -442,8 +442,12 @@ int ping_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len) > if (sk->sk_family == AF_INET && isk->inet_rcv_saddr) > sk->sk_userlocks |= SOCK_BINDADDR_LOCK; > #if IS_ENABLED(CONFIG_IPV6) > - if (sk->sk_family == AF_INET6 && !ipv6_addr_any(&sk->sk_v6_rcv_saddr)) > - sk->sk_userlocks |= SOCK_BINDADDR_LOCK; > + if (sk->sk_family == AF_INET6) { > + if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) > + sk->sk_userlocks |= SOCK_BINDADDR_LOCK; > + if (sk->sk_bound_dev_if != dif) > + inet6_clear_connect_ifindex(sk); > + } > #endif [Severity: Medium] The commit message says that holding lock_sock() in the pingv6 disconnect callback serializes with connect(), bind() and setsockopt(). Is that true for ping_bind()? ping_bind() reads dif and writes sk_bound_dev_if before it takes lock_sock(): net/ipv4/ping.c:ping_bind() { int dif = sk->sk_bound_dev_if; err = ping_check_bind_addr(sk, isk, uaddr, addr_len); if (err) return err; lock_sock(sk); ... } For scoped addresses, ping_check_bind_addr() does a plain store: if (scoped) sk->sk_bound_dev_if = addr->sin6_scope_id; Could this store land after __ip6_datagram_connect() samples old_bound_dev_if but before its rollback? Could it also land while udp_locked_disconnect() is restoring bound_dev_if_orig? The error path has a separate problem. A pingv6 socket that is already bound, or that connect() autobound through inet_dgram_connect(), has inet_num != 0. A second bind() to fe80::%Y writes Y and then takes this branch: err = -EINVAL; if (isk->inet_num != 0) goto out; Only the ping_get_port() failure path restores dif. Here bind() returns -EINVAL, but sk_bound_dev_if stays at Y on the hashed socket. Could an unprivileged ping_group_range user use this to leave an SO_BINDTODEVICE or VRF binding without CAP_NET_RAW? The new inet6_clear_connect_ifindex() call runs only on the success path. On this path, bound_dev_if_connect and bound_dev_if_orig are not updated to match the new ifindex. > diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c > index a9b8b4b42a1af..3724129b00e7d 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: Medium] The commit message says that after SO_BINDTODEVICE the kernel "requires CAP_NET_RAW to clear or change sk_bound_dev_if afterwards". It also says the patch closes the case where a user can "clear a VRF binding without CAP_NET_RAW". Does this bind() path enforce that rule? __inet6_bind() overrides sk_bound_dev_if for any scoped address with a non-zero sin6_scope_id. After that it only checks that the device exists and calls ipv6_chk_addr(). The ipv6_chk_addr() check is skipped when ipv6_can_nonlocal_bind() is true, for example with IPV6_FREEBIND. There is no CAP_NET_RAW check and no L3 scope check. ping_check_bind_addr() and rawv6_bind() have the same unchecked override. By contrast, __ip6_datagram_connect() rejects a scope_id that is outside the socket's L3 domain: if (!sk_dev_equal_l3scope(sk, usin->sin6_scope_id)) { err = -EINVAL; goto out; } Take a UDPv6 or pingv6 socket created under ip vrf exec, or one bound with an unprivileged SO_BINDTODEVICE. Could it call bind() on fe80::%Y, with Y outside the VRF, and leave its device binding without CAP_NET_RAW and without any disconnect? For UDPv6, if get_port() fails after the override, __inet6_bind() only calls inet_reset_saddr(). sk_bound_dev_if stays at Y and inet_num stays 0, so the bind() can be retried. This path can't produce ifindex 0, so the port squatting case in the commit message is still fixed. The override itself is long-standing ("Override any existing binding, if another one is supplied by user"). The patch adds inet6_clear_connect_ifindex() next to it, which treats the override as a valid explicit binding. Should these bind() paths get an sk_dev_equal_l3scope() or capability check? Or should the commit message be narrowed to the disconnect case? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124180603.72523-1-dmnk%40google.com