Article View: linux.kernel.netdev
Article #23972Re: [PATCH net v2] udp: preserve explicit sk_bound_dev_if across __udp_disconnect()
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 19:03
Date: Sat, 28 Nov 2026 19:03
147 lines
13594 bytes
13594 bytes
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::<own LL>%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::<own LL>%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
Technical Details
Message-ID:
<179589258952.3135.7000335148299611948@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373265-linux-kernel-netdev=dewy.ruReferences:
<20261124180603.72523-1-dmnk@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373265-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v2] udp: preserve explicit sk_bound_dev_if across __udp_disconnect() Date: Sat, 28 Nov 2026 19:03:09 +0000 Organization: Usenet Network Message-ID: <179589258952.3135.7000335148299611948@kernel.org> References: <20261124180603.72523-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="1011058"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:q09ViQNz1Lr/DXCc/jY3kHSr4jk= sha256:bwErP3b7KeXbFaSwckm9sX7jmKuoINBUjBQ4WYThaRk= sha1:ejDrD+iUAePrSQMu7I4R3V3cSic= sha256:KdPQra7qFDs6HgL/BTQlfK+JOjEA856AY8gPBN0uYmI= 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 C8252125F8A; Sat, 28 Nov 2026 22:03:25 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, 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, URIBL_BLOCKED=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 9an8DwPHA0sY; Sat, 28 Nov 2026 22:03:22 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373265-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id D92BA125F88; Sat, 28 Nov 2026 22:03:13 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 77BFC23818; Sat, 28 Nov 2026 19:03:12 +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=1795892591; b=pbOBF5E6FWWPVYfaPzEzHxeqhoO3+qj19JEi7dX+wsWHfyCNdFakF6jqH5C8gE7Ms9Ox DMa8lHwXv5+EzH+e3g8jrCrl+9xTA20eOwt21uvAGJXUT4T744XRduYUYQ4Fi74sfZ1LM rVV3auHWNsFKq04sTEKyYp/PAJnFUyd/nDSeJL5/w92KK6q0YN8xakpbKt6zw+RhqujB4 CWDzya7iylxMP01eFMnqreq8glFkcxyEniBhN2/gs/IJQdb7I8vbKCfemca7uU1CsbLAT juh5fEzjcUxoCRC0rKK38U5sLMNCQ3x3F18vu9d7vu2/l/Xy+X/Ysj3i496wdBt4jkw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795892591; 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=t4Fd8lFlLhdoLH7tySUa7ijYZM/Ky5Fb1n1moVtF5Wg=; b=OktuBgQWbElZVMztOANvBJs12EV4ILC8bx5F0lZYPiuLFhgWLA99Mf0frOylJ3CNCFFx o17LlbfRlJ1Q5nkSFZtHYOzY6iuz449slDkis0IZ9ZBLJPN5yQJUFxGDG4M8EumgSaOW+ xi4leDT/utypY6QqDH/+Jrf1yMWRGvTzN2Akicx6VFe8pKXhvU139+CkXAU4ituOBHnXh FE2Z0nlD+zWztmXQoub7BnkIhILAykpz3ctJH9lHBjqpwZpUJQ2MVE+98sXusknm9x+yc FjPjEbYTwoCXsRydGp7+P6xIr80MJhZzjEy0Dxjj0kpovQ5D8MtvTQphXkotvM+UZAA== 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=H5cGmgNH; 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 A0C93606A329; Sat, 28 Nov 2026 19:03:11 +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=H5cGmgNH 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=1795892590; b=JhxQxArXC3VKOzPAyGwu/uea5ZvFNegUvwLv/1nULq37OtS674sfpmvFIWCfr5W2ctAm 2ESLgYEH6eq1UOPnfiq9n6L8WvIA5f2wRWbRRgvkh+1q2f130qLwoFkxSVOTRmEs3taqK 0qKFxaGPuC5s+3H58hjfqlNFTTuuhMyiScXbUvBT72Wo27tBV4AAT8zhpgePAK84x+drF XwC0Srb9zpc8ihlLJXx78U5MDM0moBx7CVFNfT+BWfYGsrapJPMCDa6pcuYDw2jilvQE0 HL6LjxJFon6FmdUquA+OP3C4bsM/wnoA1JZX0MF/zDcS+mYdLnZlseWLzoOTRaE3CZg== X-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== 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=H5cGmgNH; 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 BDA15606A31C for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 19:03:10 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 042781F00893; Sat, 28 Nov 2026 19:03:09 +0000 (UTC) X-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== X-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 X-In-Reply-To: <20261124180603.72523-1-dmnk@google.com> X-sashiko-severity: Medium 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