Skip to contentSkip to conversation

tcp: Fix bind() regression for dual-stack wildcard address.

PATCH Applied Kuniyuki Iwashima 7 participants 11 messages Mar 12, 2023 – Mar 15, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover tcp: Fix bind() regression for dual-stack wildcard address.

The first patch fixes the regression reported in [0], and the second patch adds a test for similar cases to catch future regression.

[0]: https://lore.kernel.org/netdev/[email protected]/

Kuniyuki Iwashima (2):
tcp: Fix bind() conflict check for dual-stack wildcard address.
selftest: Add test for bind() conflicts.

 net/ipv4/inet_hashtables.c                  |   8 +-
 tools/testing/selftests/net/.gitignore      |   1 +
 tools/testing/selftests/net/Makefile        |   1 +
 tools/testing/selftests/net/bind_wildcard.c | 114 ++++++++++++++++++++
 4 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/net/bind_wildcard.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/2 tcp: Fix bind() conflict check for dual-stack wildcard address.

Paul Holzinger reported [0] that commit 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket") introduced a bind() regression. Paul also gave a nice repro that calls two types of bind() on the same port, both of which now succeed, but the second call should fail:

bind(fd1, ::, port) + bind(fd2, 127.0.0.1, port)

The cited commit added address family tests in three functions to fix the uninit-value KMSAN report. [1] However, the test added to inet_bind2_bucket_match_addr_any() removed a necessary conflict check; the dual-stack wildcard address no longer conflicts with an IPv4 non-wildcard address.

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 dual-stack wildcard address.

Note that the IPv4 wildcard address does not conflict with IPv6 non-wildcard addresses.

[0]: https://lore.kernel.org/netdev/[email protected]/
[1]: https://lore.kernel.org/netdev/CAG_fn=Ud3zSW7AZWXc+asfMhZVL5ETnvuY44Pmyv4NPv-ijN-A@mail.gmail.com/

Fixes 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket")

---
Cc: Martin KaFai Lau <[email protected]>
---
Some cleanup patches will be posted against net-next later:

* s/addr_any/in6addr_any/
* Remove duplicated tests for net, port, and l3mdev.

---
 net/ipv4/inet_hashtables.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
net/ipv4/inet_hashtables.c +7 -1
index e41fdc38ce19..6edae3886885 100644
@@ -828,8 +828,14 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const
 #if IS_ENABLED(CONFIG_IPV6)
 	struct in6_addr addr_any = {};
 
-	if (sk->sk_family != tb->family)
+	if (sk->sk_family != tb->family) {
+		if (sk->sk_family == AF_INET)
+			return net_eq(ib2_net(tb), net) && tb->port == port &&
+				tb->l3mdev == l3mdev &&
+				ipv6_addr_equal(&tb->v6_rcv_saddr, &addr_any);
+
 		return false;
+	}
 
 	if (sk->sk_family == AF_INET6)
 		return net_eq(ib2_net(tb), net) && tb->port == port &&
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH v1 net 1/2] tcp: Fix bind() conflict check for dual-stack wildcard address.

Thx for working on this. There is one small detail to improve:

Quoted 21 lines · Kuniyuki Iwashima

Paul Holzinger reported [0] that commit 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket") introduced a bind() regression. Paul also gave a nice repro that calls two types of bind() on the same port, both of which now succeed, but the second call should fail:

bind(fd1, ::, port) + bind(fd2, 127.0.0.1, port)

The cited commit added address family tests in three functions to fix the uninit-value KMSAN report. [1] However, the test added to inet_bind2_bucket_match_addr_any() removed a necessary conflict check; the dual-stack wildcard address no longer conflicts with an IPv4 non-wildcard address.

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 dual-stack wildcard address.

Note that the IPv4 wildcard address does not conflict with IPv6 non-wildcard addresses.

Quoted 6 lines

[0]: https://lore.kernel.org/netdev/[email protected]/
[1]: https://lore.kernel.org/netdev/CAG_fn=Ud3zSW7AZWXc+asfMhZVL5ETnvuY44Pmyv4NPv-ijN-A@mail.gmail.com/

Fixes 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket")

The links above should use proper link tags, this thus ideally should look something like this:

Link:
https://lore.kernel.org/netdev/CAG_fn=Ud3zSW7AZWXc+asfMhZVL5ETnvuY44Pmyv4NPv-ijN-A@mail.gmail.com/

[1]
Fixes 5456262d2baa ("net: Fix incorrect address comparison when

searching for a bind2 bucket")

Link:
https://lore.kernel.org/netdev/[email protected]/
[0]

[placing the link [1] at the end would be fine, too]

Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) --
Everything you wanna know about Linux kernel regression tracking:
https://linux-regtracking.leemhuis.info/about/#tldr
If I did something stupid, please tell me, as explained on that page.

P.S.: While at it:

#regzbot ^backmonitor:
https://lore.kernel.org/netdev/[email protected]/

maintainer
#3 lore raw

Re: [PATCH v1 net 1/2] tcp: Fix bind() conflict check for dual-stack wildcard address.

Quoted 9 lines · On Sun, 12 Mar 2023 12:42:48 +0100 Linux regression tracking (Thorsten…

Link:
https://lore.kernel.org/netdev/CAG_fn=Ud3zSW7AZWXc+asfMhZVL5ETnvuY44Pmyv4NPv-ijN-A@mail.gmail.com/

[1]
Fixes 5456262d2baa ("net: Fix incorrect address comparison when

searching for a bind2 bucket")

Link:
https://lore.kernel.org/netdev/[email protected]/
[0]

I tried to fix this manually when applying but:
- your email client wraps your replies
- please don't reply to patches with tags which will look to scripts and patchwork like tags it should pull into the submission (Reported-by in particular, here)

#4 lore raw

Re: [PATCH v1 net 1/2] tcp: Fix bind() conflict check for dual-stack wildcard address.

Quoted 12 lines · Jakub Kicinski
Quoted 9 lines · On Sun, 12 Mar 2023 12:42:48 +0100 Linux regression tracking (Thorsten…

Link:
https://lore.kernel.org/netdev/CAG_fn=Ud3zSW7AZWXc+asfMhZVL5ETnvuY44Pmyv4NPv-ijN-A@mail.gmail.com/

[1]
Fixes 5456262d2baa ("net: Fix incorrect address comparison when

searching for a bind2 bucket")

Link:
https://lore.kernel.org/netdev/[email protected]/
[0]

Quoted 5 lines

I tried to fix this manually when applying but:
- your email client wraps your replies
- please don't reply to patches with tags which will look to scripts and patchwork like tags it should pull into the submission (Reported-by in particular, here)

Sorry for the mixup and thx for letting me know, will simply quote my suggestion next time, that should avoid both problems.

Ciao, Thorsten

maintainer
#5 lore raw

Re: [PATCH v1 net 1/2] tcp: Fix bind() conflict check for dual-stack wildcard address.

Quoted 13 lines · On Wed, 15 Mar 2023 09:05:29 +0100 Thorsten Leemhuis wrote:
Quoted 12 lines · Jakub Kicinski
Quoted 9 lines · On Sun, 12 Mar 2023 12:42:48 +0100 Linux regression tracking (Thorsten…

Link:
https://lore.kernel.org/netdev/CAG_fn=Ud3zSW7AZWXc+asfMhZVL5ETnvuY44Pmyv4NPv-ijN-A@mail.gmail.com/

[1]
Fixes 5456262d2baa ("net: Fix incorrect address comparison when

searching for a bind2 bucket")

Link:
https://lore.kernel.org/netdev/[email protected]/
[0]

Quoted 8 lines
Quoted 5 lines

I tried to fix this manually when applying but:
- your email client wraps your replies
- please don't reply to patches with tags which will look to scripts and patchwork like tags it should pull into the submission (Reported-by in particular, here)

Sorry for the mixup and thx for letting me know, will simply quote my suggestion next time, that should avoid both problems.

FWIW indenting with spaces would work too, for our scripts at least. We match on tags only at start of the line.

Reviewed-by on v1 1/2
#6 lore raw

Re: [PATCH v1 net 1/2] tcp: Fix bind() conflict check for dual-stack wildcard address.

In reply to Kuniyuki Iwashima
Quoted 22 lines · Kuniyuki Iwashima

Paul Holzinger reported [0] that commit 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket") introduced a bind() regression. Paul also gave a nice repro that calls two types of bind() on the same port, both of which now succeed, but the second call should fail:

bind(fd1, ::, port) + bind(fd2, 127.0.0.1, port)

The cited commit added address family tests in three functions to fix the uninit-value KMSAN report. [1] However, the test added to inet_bind2_bucket_match_addr_any() removed a necessary conflict check; the dual-stack wildcard address no longer conflicts with an IPv4 non-wildcard address.

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 dual-stack wildcard address.

Note that the IPv4 wildcard address does not conflict with IPv6 non-wildcard addresses.

Quoted 7 lines

[0]: https://lore.kernel.org/netdev/[email protected]/
[1]: https://lore.kernel.org/netdev/CAG_fn=Ud3zSW7AZWXc+asfMhZVL5ETnvuY44Pmyv4NPv-ijN-A@mail.gmail.com/

Fixes 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket")

SGTM, thanks.

Tested-by on v1 1/2
#7 lore raw

Re: [PATCH v1 net 1/2] tcp: Fix bind() conflict check for dual-stack wildcard address.

In reply to Kuniyuki Iwashima

Thanks Kuniyuki, patch works for me.

Quoted 48 lines · Kuniyuki Iwashima

Paul Holzinger reported [0] that commit 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket") introduced a bind() regression. Paul also gave a nice repro that calls two types of bind() on the same port, both of which now succeed, but the second call should fail:

   bind(fd1, ::, port) + bind(fd2, 127.0.0.1, port)

The cited commit added address family tests in three functions to fix the uninit-value KMSAN report. [1] However, the test added to inet_bind2_bucket_match_addr_any() removed a necessary conflict check; the dual-stack wildcard address no longer conflicts with an IPv4 non-wildcard address.

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 dual-stack wildcard address.

Note that the IPv4 wildcard address does not conflict with IPv6 non-wildcard addresses.

[0]: https://lore.kernel.org/netdev/[email protected]/
[1]: https://lore.kernel.org/netdev/CAG_fn=Ud3zSW7AZWXc+asfMhZVL5ETnvuY44Pmyv4NPv-ijN-A@mail.gmail.com/

Fixes 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket")

---
Cc: Martin KaFai Lau <[email protected]>
---
Some cleanup patches will be posted against net-next later:

* s/addr_any/in6addr_any/
* Remove duplicated tests for net, port, and l3mdev.

---
  net/ipv4/inet_hashtables.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
net/ipv4/inet_hashtables.c +1 -1
index e41fdc38ce19..6edae3886885 100644
@@ -828,8 +828,14 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const
  #if IS_ENABLED(CONFIG_IPV6)
  	struct in6_addr addr_any = {};
 
-	if (sk->sk_family != tb->family)
+	if (sk->sk_family != tb->family) {

net/ipv4/inet_hashtables.c bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const · line 841

Quoted 10 lines
net/ipv4/inet_hashtables.c +6 -0
+		if (sk->sk_family == AF_INET)
+			return net_eq(ib2_net(tb), net) && tb->port == port &&
+				tb->l3mdev == l3mdev &&
+				ipv6_addr_equal(&tb->v6_rcv_saddr, &addr_any);
+
  		return false;
+	}
 
  	if (sk->sk_family == AF_INET6)
  		return net_eq(ib2_net(tb), net) && tb->port == port &&
Reviewed-by on v1 1/2
#8 lore raw

Re: [PATCH v1 net 1/2] tcp: Fix bind() conflict check for dual-stack wildcard address.

In reply to Kuniyuki Iwashima
Quoted 21 lines · Kuniyuki Iwashima

Paul Holzinger reported [0] that commit 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket") introduced a bind() regression. Paul also gave a nice repro that calls two types of bind() on the same port, both of which now succeed, but the second call should fail:

   bind(fd1, ::, port) + bind(fd2, 127.0.0.1, port)

The cited commit added address family tests in three functions to fix the uninit-value KMSAN report. [1] However, the test added to inet_bind2_bucket_match_addr_any() removed a necessary conflict check; the dual-stack wildcard address no longer conflicts with an IPv4 non-wildcard address.

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 dual-stack wildcard address.

Note that the IPv4 wildcard address does not conflict with IPv6 non-wildcard addresses.

Quoted 6 lines

[0]: https://lore.kernel.org/netdev/[email protected]/
[1]: https://lore.kernel.org/netdev/CAG_fn=Ud3zSW7AZWXc+asfMhZVL5ETnvuY44Pmyv4NPv-ijN-A@mail.gmail.com/

Fixes 5456262d2baa ("net: Fix incorrect address comparison when searching for a bind2 bucket")

Thanks for the fix.

#9 lore raw

PATCH 2/2 selftest: Add test for bind() conflicts.

In reply to Kuniyuki Iwashima

The test checks if (IPv4, IPv6) address pair properly conflict or not.

* IPv4
* 0.0.0.0
* 127.0.0.1

* IPv6
* ::
* ::1

If the IPv6 address is [::], the second bind() always fails.

---
 tools/testing/selftests/net/.gitignore      |   1 +
 tools/testing/selftests/net/Makefile        |   1 +
 tools/testing/selftests/net/bind_wildcard.c | 114 ++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 tools/testing/selftests/net/bind_wildcard.c
tools/testing/selftests/net/.gitignore +1 -0
index a6911cae368c..80f06aa62034 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 bind_bhash
 bind_timewait
+bind_wildcard
 csum
 cmsg_sender
 diag_uid
tools/testing/selftests/net/Makefile +1 -0
index 6cd8993454d7..80fbfe0330f6 100644
@@ -80,6 +80,7 @@ TEST_GEN_FILES += sctp_hello
 TEST_GEN_FILES += csum
 TEST_GEN_FILES += nat6to4.o
 TEST_GEN_FILES += ip_local_port_range
+TEST_GEN_FILES += bind_wildcard
 
 TEST_FILES := settings
 
tools/testing/selftests/net/bind_wildcard.c new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
2.30.2
#10 lore raw
In reply to Kuniyuki Iwashima
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Sat, 11 Mar 2023 19:19:02 -0800 you wrote:

The first patch fixes the regression reported in [0], and the second patch adds a test for similar cases to catch future regression.

[0]: https://lore.kernel.org/netdev/[email protected]/

Kuniyuki Iwashima (2):
tcp: Fix bind() conflict check for dual-stack wildcard address.
selftest: Add test for bind() conflicts.

[...]

Here is the summary with links:
- [v1,net,1/2] tcp: Fix bind() conflict check for dual-stack wildcard address.

    https://git.kernel.org/netdev/net/c/d9ba99342855
  - [v1,net,2/2] selftest: Add test for bind() conflicts.
    https://git.kernel.org/netdev/net/c/13715acf8ab5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html