From: netdev-bot+sashiko@kernel.org
To: dmnk@google.com
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, ncardwell@google.com, kuniyu@google.com,
horms@kernel.org, joannelkoong@gmail.com, netdev@vger.kernel.org,
dmnk+artist@google.com
Subject: Re: [PATCH net] inet: reject multicast and broadcast bind addresses on SOCK_STREAM
Date: Mon, 23 Nov 2026 21:28:07 +0000 [thread overview]
Message-ID: <179546928758.3135.1400767434595880617@kernel.org> (raw)
In-Reply-To: <20261119192152.2643304-1-dmnk@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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] The new SOCK_STREAM check in __inet_bind()
(net/ipv4/af_inet.c) and in the IPV6_ADDR_MAPPED branch of…
--
inet: reject multicast and broadcast bind addresses on SOCK_STREAM
This patch makes __inet_bind() and the IPV6_ADDR_MAPPED branch of
__inet6_bind() return -EINVAL when a SOCK_STREAM socket binds to a
non-INADDR_ANY address classified as RTN_MULTICAST or RTN_BROADCAST. The
goal is to stop such binds from skipping the bhash2 conflict checks on a
later active connect.
> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> index 8822bae439f88..b1ea55457c747 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 &&
> + addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
> + (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST))
> + goto out;
[Severity: Medium]
Can chk_addr_ret be RTN_BROADCAST here because the FIB table is missing,
even when the address is not a broadcast address?
__inet_dev_addr_type() uses RTN_BROADCAST as its default. It only changes
that value when the table exists:
net/ipv4/fib_frontend.c:__inet_dev_addr_type() {
...
unsigned int ret = RTN_BROADCAST;
...
table = fib_get_table(net, tb_id);
if (table) {
ret = RTN_UNICAST;
...
}
...
return ret;
}
With CONFIG_IP_MULTIPLE_TABLES, ip_fib_net_init()->fib4_rules_init() only
registers rules. RT_TABLE_LOCAL is created later by fib_new_table(), the
first time an IPv4 address or route is added.
For loopback, inetdev_event() adds 127.0.0.1 only when lo gets NETDEV_UP. A
VRF/l3mdev table with no entries yet behaves the same way.
So in a new netns (for example one created with unshare -rn) where lo is
still down, every non-zero IPv4 address seems to come back as
RTN_BROADCAST.
Before this patch, inet_addr_valid_or_nonlocal() accepted RTN_BROADCAST, so
these binds succeeded. The new check now runs first. Would these binds fail
with -EINVAL?
- TCP/MPTCP bind() to 127.0.0.1 in a new netns before lo is up
- binds that use IP_FREEBIND, IP_TRANSPARENT or
net.ipv4.ip_nonlocal_bind, which the existing comment in __inet_bind()
says must keep working
- the same binds through v4-mapped addresses in __inet6_bind(), where
inet_addr_type_dev_table() returns the same fallback value
There is also a second case. __inet_dev_addr_type() returns RTN_BROADCAST
for any ipv4_is_zeronet() address, but the new check only exempts exactly
INADDR_ANY. Are non-zero 0.x.x.x addresses now rejected as well?
This patch is tagged for stable. Could the check use a classification that
does not depend on the missing-table default instead? Examples are
ipv4_is_multicast()/ipv4_is_lbcast(), or an RTN_BROADCAST result that the
FIB lookup actually confirmed.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119192152.2643304-1-dmnk%40google.com
prev parent reply other threads:[~2026-11-23 21:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 19:21 [PATCH net] inet: reject multicast and broadcast bind addresses on SOCK_STREAM Dominik Maier
2026-11-23 21:28 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179546928758.3135.1400767434595880617@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=dmnk+artist@google.com \
--cc=dmnk@google.com \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=joannelkoong@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox