From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Ahern <dsahern@kernel.org>
Cc: Joanne Koong <joannelkoong@gmail.com>,
Jianguo Wu <wujianguo106@163.com>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>
Subject: [PATCH v1 net 1/8] tcp: Fix bind() regression for v6-only wildcard and v4-mapped-v6 non-wildcard addresses.
Date: Mon, 25 Mar 2024 11:19:16 -0700 [thread overview]
Message-ID: <20240325181923.48769-2-kuniyu@amazon.com> (raw)
In-Reply-To: <20240325181923.48769-1-kuniyu@amazon.com>
Commit 5e07e672412b ("tcp: Use bhash2 for v4-mapped-v6 non-wildcard
address.") introduced bind() regression for v4-mapped-v6 address.
When we bind() the following two addresses on the same port, the 2nd
bind() should succeed but fails now.
1. [::] w/ IPV6_ONLY
2. ::ffff:127.0.0.1
After the chagne, v4-mapped-v6 uses bhash2 instead of bhash to
detect conflict faster, but I forgot to add a necessary change.
During the 2nd bind(), inet_bind2_bucket_match_addr_any() returns
the tb2 bucket of [::], and inet_bhash2_conflict() finally calls
inet_bind_conflict(), which returns true, meaning conflict.
inet_bhash2_addr_any_conflict
|- inet_bind2_bucket_match_addr_any <-- return [::] bucket
`- inet_bhash2_conflict
`- __inet_bhash2_conflict <-- checks IPV6_ONLY for AF_INET
| but not for v4-mapped-v6 address
`- inet_bind_conflict <-- does not check address
inet_bind_conflict() does not check socket addresses because
__inet_bhash2_conflict() is expected to do so.
However, it checks IPV6_V6ONLY attribute only against AF_INET
socket, and not for v4-mapped-v6 address.
As a result, v4-mapped-v6 address conflicts with v6-only wildcard
address.
To avoid that, let's add the missing test to use bhash2 for
v4-mapped-v6 address.
Fixes: 5e07e672412b ("tcp: Use bhash2 for v4-mapped-v6 non-wildcard address.")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
net/ipv4/inet_connection_sock.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 7d8090f109ef..612aa1d2eff7 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -203,7 +203,8 @@ static bool __inet_bhash2_conflict(const struct sock *sk, struct sock *sk2,
kuid_t sk_uid, bool relax,
bool reuseport_cb_ok, bool reuseport_ok)
{
- if (sk->sk_family == AF_INET && ipv6_only_sock(sk2))
+ if (ipv6_only_sock(sk2) &&
+ (sk->sk_family == AF_INET || ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr)))
return false;
return inet_bind_conflict(sk, sk2, sk_uid, relax,
--
2.30.2
next prev parent reply other threads:[~2024-03-25 18:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-25 18:19 [PATCH v1 net 0/8] tcp: Fix bind() regression and more tests Kuniyuki Iwashima
2024-03-25 18:19 ` Kuniyuki Iwashima [this message]
2024-03-25 23:56 ` [PATCH v1 net 1/8] tcp: Fix bind() regression for v6-only wildcard and v4-mapped-v6 non-wildcard addresses Jakub Kicinski
2024-03-26 0:01 ` Kuniyuki Iwashima
2024-03-26 10:41 ` kernel test robot
2024-03-26 11:11 ` kernel test robot
2024-03-25 18:19 ` [PATCH v1 net 2/8] tcp: Fix bind() regression for v6-only wildcard and v4(-mapped-v6) " Kuniyuki Iwashima
2024-03-25 18:19 ` [PATCH v1 net 3/8] selftest: tcp: Make bind() selftest flexible Kuniyuki Iwashima
2024-03-25 18:19 ` [PATCH v1 net 4/8] selftest: tcp: Define the reverse order bind() tests explicitly Kuniyuki Iwashima
2024-03-25 18:19 ` [PATCH v1 net 5/8] selftest: tcp: Add v4-v4 and v6-v6 bind() conflict tests Kuniyuki Iwashima
2024-03-25 18:19 ` [PATCH v1 net 6/8] selftest: tcp: Add more bind() calls Kuniyuki Iwashima
2024-03-25 18:19 ` [PATCH v1 net 7/8] selftest: tcp: Add bind() tests for IPV6_V6ONLY Kuniyuki Iwashima
2024-03-25 18:19 ` [PATCH v1 net 8/8] selftest: tcp: Add bind() tests for SO_REUSEADDR/SO_REUSEPORT Kuniyuki Iwashima
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=20240325181923.48769-2-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=joannelkoong@gmail.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=wujianguo106@163.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.