From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <avagin@google.com>
Cc: <davem@davemloft.net>, <dsahern@kernel.org>,
<edumazet@google.com>, <joannelkoong@gmail.com>,
<kuba@kernel.org>, <kuni1840@gmail.com>, <kuniyu@amazon.com>,
<netdev@vger.kernel.org>, <pabeni@redhat.com>
Subject: Re: [PATCH v1 net 1/5] tcp: Fix bind() regression for v4-mapped-v6 wildcard address.
Date: Mon, 11 Sep 2023 13:05:43 -0700 [thread overview]
Message-ID: <20230911200543.78783-1-kuniyu@amazon.com> (raw)
In-Reply-To: <CAEWA0a5t+XfrP6BvWCVg2P8e05Bpu2hd7OpmKnB2NVYLwRmcAg@mail.gmail.com>
From: Andrei Vagin <avagin@google.com>
Date: Mon, 11 Sep 2023 13:00:19 -0700
> On Mon, Sep 11, 2023 at 9:52 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
> >
> > Andrei Vagin reported bind() regression with strace logs.
> >
> > If we bind() a TCPv6 socket to ::FFFF:0.0.0.0 and then bind() a TCPv4
> > socket to 127.0.0.1, the 2nd bind() should fail but now succeeds.
> >
> > from socket import *
> >
> > s1 = socket(AF_INET6, SOCK_STREAM)
> > s1.bind(('::ffff:0.0.0.0', 0))
> >
> > s2 = socket(AF_INET, SOCK_STREAM)
> > s2.bind(('127.0.0.1', s1.getsockname()[1]))
> >
> > During the 2nd bind(), if tb->family is AF_INET6 and sk->sk_family is
> > AF_INET in inet_bind2_bucket_match_addr_any(), we still need to check
> > if tb has the v4-mapped-v6 wildcard address.
> >
> > The example above does not work after commit 5456262d2baa ("net: Fix
> > incorrect address comparison when searching for a bind2 bucket"), but
> > the blamed change is not the commit.
> >
> > Before the commit, the leading zeros of ::FFFF:0.0.0.0 were treated
> > as 0.0.0.0, and the sequence above worked by chance. Technically, this
> > case has been broken since bhash2 was introduced.
> >
> > Note that if we bind() two sockets to 127.0.0.1 and then ::FFFF:0.0.0.0,
> > the 2nd bind() fails properly because we fall back to using bhash to
> > detect conflicts for the v4-mapped-v6 address.
>
> I think we have one more issue here:
>
> socket(AF_INET6, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 3
> socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 4
> bind(3, {sa_family=AF_INET6, sin6_port=htons(9999),
> sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "::ffff:127.0.0.1",
> &sin6_addr), sin6_scope_id=0}, 28) = 0
> bind(4, {sa_family=AF_INET, sin_port=htons(9999),
> sin_addr=inet_addr("127.0.0.1")}, 16) = 0
>
> I think the second bind has to return EADDRINUSE, doesn't it?
Correct, and the following patch fixes it separately.
Sorry, I forgot to add you in CC of the entire series.
https://lore.kernel.org/netdev/20230911183700.60878-4-kuniyu@amazon.com/
next prev parent reply other threads:[~2023-09-11 20:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 16:51 [PATCH v1 net 0/5] tcp: Fix bind() regression for v4-mapped-v6 address Kuniyuki Iwashima
2023-09-11 16:51 ` [PATCH v1 net 1/5] tcp: Fix bind() regression for v4-mapped-v6 wildcard address Kuniyuki Iwashima
2023-09-11 20:00 ` Andrei Vagin
2023-09-11 20:05 ` Kuniyuki Iwashima [this message]
2023-09-11 16:51 ` [PATCH v1 net 2/5] tcp: Fix bind() regression for v4-mapped-v6 non-wildcard address Kuniyuki Iwashima
2023-09-11 17:51 ` Eric Dumazet
2023-09-11 18:05 ` Kuniyuki Iwashima
2023-09-11 16:51 ` [PATCH v1 net 3/5] selftest: tcp: Fix address length in bind_wildcard.c Kuniyuki Iwashima
2023-09-11 16:51 ` [PATCH v1 net 4/5] selftest: tcp: Move expected_errno into each test case " Kuniyuki Iwashima
2023-09-11 16:51 ` [PATCH v1 net 5/5] selftest: tcp: Add v4-mapped-v6 cases " 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=20230911200543.78783-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=avagin@google.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 \
/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;
as well as URLs for NNTP newsgroup(s).