🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25358

Re: [PATCH net v3] inet: reject multicast and broadcast bind addresses on SOCK_STREAM

#25358
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 16:04
195 lines
15856 bytes
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

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

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] The fix is gated only on `sk->sk_type == SOCK_STREAM`.
- [Low] `__inet_dev_addr_type()` (net/ipv4/fib_frontend.c:236-237)
  returns RTN_BROADCAST for every 0.0.0.0/8 address before any FIB…
- [Low] `inet_addr_is_mcast_or_bcast()` is exported with
  `EXPORT_SYMBOL()` in net/ipv4/fib_frontend.c, but its only caller is…
- [Low] The v4-mapped branch of `__inet6_bind()`
  (net/ipv6/af_inet6.c:322-331) has the comment "Reproduce AF_INET…
- [Low] The comment above `lock_sock()` in `__inet_bind()` says rcv_saddr
  and saddr "are the same except where it would be illegal to use them…

--

inet: reject multicast and broadcast bind addresses on SOCK_STREAM

This patch makes __inet_bind() return -EINVAL for SOCK_STREAM sockets
bound to multicast, limited broadcast, or FIB-confirmed subnet broadcast
addresses, using a new inet_addr_is_mcast_or_bcast() helper. It also
stops clearing inet_saddr for SOCK_STREAM sockets. The goal is to stop
connect() from moving a socket into another user's bhash2 unicast bucket
without a bind-conflict check.

> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> index 5d03a9149b40f..020924100d9ce 100644
> --- a/net/ipv4/af_inet.c
> +++ b/net/ipv4/af_inet.c
> @@ -500,6 +500,12 @@ int __inet_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len,
>  	tb_id = l3mdev_fib_table_by_index(net, sk->sk_bound_dev_if) ? : tb_id;
>  	chk_addr_ret = inet_addr_type_table(net, addr->sin_addr.s_addr, tb_id);
>  
> +	err = -EINVAL;
> +	if (sk->sk_type == SOCK_STREAM &&
> +	    inet_addr_is_mcast_or_bcast(net, tb_id, addr->sin_addr.s_addr,
> +					chk_addr_ret))
> +		goto out;

[Severity: Medium]
Does this fully close the bypass in the stable trees the patch is tagged
for?

Mainline no longer has DCCP, so SOCK_STREAM covers every bhash2 user
there. The patch carries Cc: stable and Fixes: 28044fc1d495 (v6.1),
though, and the 6.1, 6.6 and 6.12 trees still have DCCP. DCCP sockets
use .bind = inet_bind and reach __inet_bind() with sk_type ==
SOCK_DCCP.

On those trees, a DCCP socket bound to something like 224.0.0.1:P skips
the new -EINVAL check. inet_saddr is still cleared for it, because the
new sk_type != SOCK_STREAM condition further down is true for DCCP.
connect() then goes:

dccp_v4_connect()  (or dccp_v6_connect())
    if (inet->inet_saddr == 0)
        inet_bhash2_update_saddr()
            __inet_bhash2_update_saddr()

That relinks the socket into the (real_saddr, P) bucket with no
bind-conflict check. tcp_v4_connect() does the same move.

Should the backports cover SOCK_DCCP as well? Or could the commit
message at least warn backporters about this gap?

[Severity: Low]
Should the v4-mapped branch of __inet6_bind() in net/ipv6/af_inet6.c
get the same check? That branch says it reproduces the AF_INET checks:

	/* Reproduce AF_INET checks to make the bindings consistent */
	v4addr = addr->sin6_addr.s6_addr32[3];
	chk_addr_ret = inet_addr_type_dev_table(net, dev, v4addr);
	rcu_read_unlock();

	if (!inet_addr_valid_or_nonlocal(net, inet, v4addr,
					 chk_addr_ret)) {

inet_addr_valid_or_nonlocal() accepts RTN_MULTICAST and RTN_BROADCAST.
The earlier IPV6_ADDR_MULTICAST && SOCK_STREAM check does not catch
these addresses, because ipv6_addr_type() reports them as
IPV6_ADDR_MAPPED.

As a result, a dual-stack TCP socket can still bind to ::ffff:224.0.0.1,
::ffff:255.255.255.255 or a mapped subnet broadcast address. An AF_INET
TCP socket that asks for the same IPv4 address now gets -EINVAL.

The conflict bypass is not reachable this way.
__inet6_bind() sets inet->inet_saddr = v4addr and never clears it, so
connect() fails in ip_route_output_key_hash_rcu(). The two bind paths
still give different results, though, and the socket ends up bound to an
address it cannot use.

> [ ... ]
> @@ -535,7 +541,8 @@ int __inet_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len,
>  		goto out_release_sock;
>  
>  	inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
> -	if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
> +	if (sk->sk_type != SOCK_STREAM &&
> +	    (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST))
>  		inet->inet_saddr = 0;  /* Use device */

[Severity: Low]
This isn't a bug, but the comment just above lock_sock() in
__inet_bind() no longer matches what happens for SOCK_STREAM:

	 *      In the BSD API these are the same except where it
	 *      would be illegal to use them (multicast/broadcast) in
	 *      which case the sending device address is used.

For SOCK_STREAM, some addresses are classified RTN_BROADCAST by
inet_addr_type_table() but pass the new helper. Examples are 0.0.0.0/8
and the missing-FIB-table fallback. These now keep the bound address in
inet_saddr.

Could a short comment explain why stream sockets are excluded here? It
would make it less likely that a later cleanup restores the clearing and
reopens the bhash2 bypass.

> diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
> index 8c123b111b3d8..10edb607d99db 100644
> --- a/net/ipv4/fib_frontend.c
> +++ b/net/ipv4/fib_frontend.c
> @@ -289,6 +289,30 @@ unsigned int inet_addr_type_dev_table(struct net *net,
>  }
>  EXPORT_SYMBOL(inet_addr_type_dev_table);
>  
> +bool inet_addr_is_mcast_or_bcast(struct net *net, u32 tb_id, __be32 addr,
> +				 unsigned int addr_type)
> +{
> +	struct flowi4 fl4 = { .daddr = addr };
> +	struct fib_result res;
> +	bool is_bcast = false;
> +	struct fib_table *tb;
> +
> +	if (addr == htonl(INADDR_ANY))
> +		return false;
> +	if (addr_type == RTN_MULTICAST || ipv4_is_lbcast(addr))
> +		return true;
> +	if (addr_type != RTN_BROADCAST)
> +		return false;
> +
> +	rcu_read_lock();
> +	tb = fib_get_table(net, tb_id);
> +	if (tb && !fib_table_lookup(tb, &fl4, &res, FIB_LOOKUP_NOREF))
> +		is_bcast = res.type == RTN_BROADCAST;
> +	rcu_read_unlock();
> +	return is_bcast;
> +}

[Severity: Low]
How are 0.0.0.0/8 addresses meant to be handled here?
__inet_dev_addr_type() returns RTN_BROADCAST for them before any FIB
lookup:

	if (ipv4_is_zeronet(addr) || ipv4_is_lbcast(addr))
		return RTN_BROADCAST;

A 0.x.y.z address normally has no RTN_BROADCAST route in tb_id, so this
helper returns false for it. inet_addr_valid_or_nonlocal() accepts
RTN_BROADCAST, so a TCP bind() to a non-local 0.1.2.3 still succeeds,
even without IP_FREEBIND.

Before this patch, __inet_bind() cleared inet_saddr for such a socket.
tcp_v4_connect() then moved it with inet_bhash2_update_saddr(), which is
the same bypass.

With this patch, only the "never clear inet_saddr on SOCK_STREAM" change
closes this case. inet_saddr stays 0.1.2.3, and connect() now returns
-ENETUNREACH, because __ip_dev_find() fails for a non-local saddr in
ip_route_output_key_hash_rcu(). Before the patch, connect() succeeded
with a routed source address.

The commit message describes the saddr change only as covering the case
"when a missing FIB table falls back to broadcast". Could it also say
that this change is what closes the 0.0.0.0/8 case? It could also note
that bind() to these addresses still succeeds while connect() now fails.

> +EXPORT_SYMBOL(inet_addr_is_mcast_or_bcast);

[Severity: Low]
Is this export needed? The only caller is __inet_bind() in
net/ipv4/af_inet.c. Both files are always-built-in IPv4 core, so no
module can use it.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130160424.2650506-1-dmnk%40google.com
Technical Details
Message-ID: <179614108438.3146.3576948972381397740@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375207-linux-kernel-netdev=dewy.ru
References: <20261130160424.2650506-1-dmnk@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375207-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3] inet: reject multicast and broadcast bind
 addresses on SOCK_STREAM
Date: Tue, 01 Dec 2026 16:04:44 +0000
Organization: Usenet Network
Message-ID: <179614108438.3146.3576948972381397740@kernel.org>
References: <20261130160424.2650506-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="1757074"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:DWkAmpsNjmic/ogZFqJZV5P/csQ= sha256:5QWjR8SN4NztUFgEaaN+YbqZq6hQ+7koDJL6hvZdaxg=
	sha1:hU6PK1xq2i1TD/7zaxTYURT242I= sha256:oE7M8zouDSLtoHy9oHhENMmELDbASICP7yA/lDlCiYk=
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 5519511740F; Tue,  1 Dec 2026 19:05:11 +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 Y8dg9IelsucY;
	Tue,  1 Dec 2026 19:05:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-375207-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 0286E11740E; Tue,  1 Dec 2026 19:04:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id D6B9920998; Tue,  1 Dec 2026 16:04:49 +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=1796141087;
	b=C/U03STO0VqK9ycgH3Ev7ugZKAiAr7ggAhFQpzl83kLNKBnuVIVt22TtufvHmx/dw+0+
	 ZZO9mCjmNzPJZ3im4naTwISqlRbDyIF6dsS2htNcPJrScKGxCwBEHZ7jBbYuH/qkjs2wi
	 A6+jQ5UIrH8UuAxlnHJh89zzKkcSWgh+qRqhPVWpPSnQLGmu1sLaW+x5osx8RZLAhpHMW
	 Cj66tOCWOGBz9nHq0VaLZwXKmXhDTQkghDtR2wrIwZnRswyctYfZnCIcXPJvmdu3yKaHt
	 Wvbiv/J/l/HQzJA5ZeuruJfL4wd1Q90NuU8wjQi2kXCwhJcJZUBkZqiYtOQubwN1o9Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796141087;
	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=lKP5/V+ERTXsqB+ooZhAyXMy4j5pRof1lp2PrJAWNLk=;
	b=mERfQc+ASyRMqXEzZc9OF6N8xBOeD3hXYP9wZMH+n7TDqpN7y/ib+pg+oe94nJTs1O3E
	 JCGapjwQlwTtswEv6NJxz2lJmSnpEweOPrWkRItBUY1hdAoJeKhgh9drlDXaNJVNjTAIt
	 9YEcNhyBC0D9O62VXtMub6FhkXTLQw7gY7cn9DayB0WWhiVQOJTC548EXy36PtWFGqUmA
	 0izWuw0Fr2/pwj5dXsgf5hvfPd03Z+dsegzwwcrYt3Pf0zAi2B3+Y8IyMw5gRUQLcyHDs
	 3OiGmPgaPKApXWdutKR2+avA/rZpyAxysCviRb3/t/mRPlaL2Qccyg4bPDuDpw/BHxg==
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="QTKEf/EN";
	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 0899D606A32F;
	Tue,  1 Dec 2026 16:04:47 +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=QTKEf/EN
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=1796141086;
	b=4g1pDQut8IvUTRRjK9ntZ5Qv6doLnPiBtUPMHlmdqVdgExaU4BpNip1r5wSZmlhKOPtF
	 sIMljooMxs4dQZOcmjuopIzT1BV6KP39yLqMXpu6Wbokvw7gUpqjRKw8oXEhfsxHIOCHb
	 X9SyUPRMiWbdfSH/HVqYqPI7/k1SqIfYMyx1SmGvZWSEycRiy9jj7LglxMTYsyAkd+EZp
	 bjiLGbhRIz4SCcKJ0ntTYwPKT7RLkKmYvyXV7KxhmdzQtElOns5A6ptObioUDdtoUWCN5
	 WKnuro+koNIFBmtebVebUXBbldvgXTJ4n5NT0FfcfSt+InUp2fwYxODZIJYoWVrx63g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796141086;
	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=lKP5/V+ERTXsqB+ooZhAyXMy4j5pRof1lp2PrJAWNLk=;
	b=KgP+5NmfEBqScCt0z8XVANLMYkumjv/u8lmTyqUNneFjuZPodFbXMJlfmcaDsDi7T9Mb
	 Oc2OvBS0ylAN+sg79CFbJqtA++PWsTKA0cTbUy5p8zGFe7nuPY4fiHGJym1TpUOqb9KA9
	 YJW2gnkkRC3yEfKPHXUYCic9oPg2GozIHlc7i9lJiuFPShKNbalyzLGN7mHExsIUJ5YOR
	 oH0wo8kY7zzcT2v3qUHEeTWKZEkPz+oAsiNy29PCOr9cGVs7ajVPRsMZxuclII47aAEhe
	 uMu5lRBOW2R/ol5yD2KhxuzXD0biUu1fjXdXqNLPULh+OcdhrpBjmbPisshpyhLHyiQ==
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="QTKEf/EN";
	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 2B976606A327
	for <netdev@vger.kernel.org>; Tue,  1 Dec 2026 16:04:45 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7E9D1F00A2A;
	Tue,  1 Dec 2026 16:04:44 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796141085;
	bh=lKP5/V+ERTXsqB+ooZhAyXMy4j5pRof1lp2PrJAWNLk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=QTKEf/ENjGx0lsUPb6MWH8POm954J9RhCYjtGnG9gN87wlRVEn2lprq6OHzPzrbw8
	 oj9b33DtcI4LWDyD+Z6v+Pv2UB7J2ouhXLy/it9GgCISn1f5KsXPDif29Udd4QwkuS
	 A2wjc8eWhUBUhNw3nO+8XmASrn7Z5qAHqU7+hL0047rbIhzc9U1S1IukjgE25um9ju
	 qqYGwlip9tX8uoEREOka7KUb6M/mm4RvCQcGgJeD0D7OJSEMoxd3TiMJt82lWJEmA5
	 uAu4OMWQ5Ytsp7BbsgllltcbFIuWQ1F9hqOB3AJcY3VmgxHp2nscxk+MS8J+VIxn/d
	 QtyK7AsTYy4uQ==
X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
 pabeni@redhat.com, dsahern@kernel.org, idosch@nvidia.com, horms@kernel.org,
 kuniyu@google.com, joannelkoong@gmail.com, netdev@vger.kernel.org,
 dmnk+artist@google.com
X-In-Reply-To: <20261130160424.2650506-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