netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <wujianguo106@163.com>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <kuniyu@amazon.com>,
	<netdev@vger.kernel.org>
Subject: Re: [PATCH] tcp: Fix inet_bind2_bucket_match_addr_any() regression
Date: Wed, 20 Mar 2024 21:55:33 -0700	[thread overview]
Message-ID: <20240321045533.8446-1-kuniyu@amazon.com> (raw)
In-Reply-To: <23b5678b-1e5a-be6c-ea68-b7a20dff4bbc@163.com>

Hi,

Thanks for the patch.

From: Jianguo Wu <wujianguo106@163.com>
Date: Thu, 21 Mar 2024 11:02:36 +0800
> From: Jianguo Wu <wujianguo@chinatelecom.cn>
> 
> If we bind() a TCPv4 socket to 0.0.0.0:8090, then bind() a TCPv6(ipv6only) socket

Please wrap each line at <75 characters except for logs/output like below.


> to :::8090, both without SO_REUSEPORT, then bind() 127.0.0.1:8090, it should fail

[::]:8090 is easier to read and the recommended way.
https://datatracker.ietf.org/doc/html/rfc5952#section-6

But please keep the netstat output as is.

> but now succeeds. like this:
>   tcp        0      0 127.0.0.1:8090          0.0.0.0:*               LISTEN
>   tcp        0      0 0.0.0.0:8090            0.0.0.0:*               LISTEN
>   tcp6       0      0 :::8090                 :::*                    LISTEN
> 
> bind() 0.0.0.0:8090, :::8090 and ::1:8090 are all fail.

What do you mean by all fail ?
At least, [::1]:8090 would fail with the current code in this case.


> But if we bind() a TCPv6(ipv6only) socket to :::8090 first, then  bind() a TCPv4
> socket to 0.0.0.0:8090, then bind() 127.0.0.1:8090, 0.0.0.0:8090, :::8090 and ::1:8090 are all fail.
> 
> When bind() 127.0.0.1:8090, inet_bind2_bucket_match_addr_any() will return true as tb->addr_type == IPV6_ADDR_ANY,

Let's use tb2 here for inet_bind2_bucket.. yes it's not consistent
in some functions like inet_bind2_bucket_match_addr_any() though.


> and tb is refer to the TCPv6 socket(:::8090), then inet_bhash2_conflict() return false, That is, there is no conflict,

Also make it clear that the TCPv6 socket is ipv6only one.


> so bind() succeeds.
> 
>   inet_bhash2_addr_any_conflict()
>   {
> 	inet_bind_bucket_for_each(tb2, &head2->chain)
> 		// tb2 is IPv6
> 		if (inet_bind2_bucket_match_addr_any(tb2, net, port, l3mdev, sk))
> 			break;
> 
> 	// inet_bhash2_conflict() return false
> 	if (tb2 && inet_bhash2_conflict(sk, tb2, uid, relax, reuseport_cb_ok,
>                                 reuseport_ok)) {
> 		spin_unlock(&head2->lock);
> 		return true;
> 	}
> 
>   }
> 
> Fixes: 5a22bba13d01 ("tcp: Save address type in inet_bind2_bucket.")

This is not the commit that introduced the regression.

Also, you need Signed-off-by tag here.


> ---
>  net/ipv4/inet_hashtables.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
> index 7498af320164..3eeaca8a113f 100644
> --- a/net/ipv4/inet_hashtables.c
> +++ b/net/ipv4/inet_hashtables.c
> @@ -830,8 +830,8 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const
>  		return false;
> 
>  #if IS_ENABLED(CONFIG_IPV6)
> -	if (tb->addr_type == IPV6_ADDR_ANY)
> -		return true;
> +	if (sk->sk_family == AF_INET6)
> +		return tb->addr_type == IPV6_ADDR_ANY;

This fix is not correct and will break v4-mapped-v6 address cases.
You can run bind_wildcard under the selftest directory.

Probably we need v6_only bit in tb2 and should add some test cases
in the selftest.


> 
>  	if (tb->addr_type != IPV6_ADDR_MAPPED)
>  		return false;

  reply	other threads:[~2024-03-21  4:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-21  3:02 [PATCH] tcp: Fix inet_bind2_bucket_match_addr_any() regression Jianguo Wu
2024-03-21  4:55 ` Kuniyuki Iwashima [this message]
2024-03-22  3:16   ` Jianguo Wu
2024-03-25 17:51     ` 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=20240321045533.8446-1-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    --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 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).