mptcp: fix for ipv6-related oops
Subsystems (3)
Paolo Abeni
cover mptcp: fix for ipv6-related oops
We need to allocate a larger struct sock for mptcp v6 master sockets, otherwise inet6_sk() will access mptcp related data instead of struct ipv6_pinfo.
This should fix the crash reported by Matt.
The protocol.c code changes are split in 2 patches to simplify the squashing.
(yep, I know we somewhat agreed to big giant rebase, but this specific should be trivial).
Additionally adds some fixlet for the ipv6 tests
Paolo Abeni (3):
selftests: fixup for IPv6 tests
mptcp: use ipv6-specific proto struct
mptcp/ipv6: mptcp_v6_prot needs costom destroy.
net/mptcp/protocol.c | 17 ++++++++++-- .../selftests/net/mptcp/mptcp_connect.sh | 27 +++++++++---------- 2 files changed, 27 insertions(+), 17 deletions(-)
Signature · 1 line
2.21.0
Paolo Abeni
PATCH 1/3 selftests: fixup for IPv6 tests
Some distros still have the 'ping6' command, take care of that. Addiotnally, setting 'noadad' on ipv6 addresses will avoid explicit waits later
Squash-to: "mptcp: add basic kselftest for mptcp"
Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
--- .../selftests/net/mptcp/mptcp_connect.sh | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.sh +12 -15
@@ -17,6 +17,7 @@ ethtool_random_on=true tc_delay="$((RANDOM%400))" tc_loss=$((RANDOM%101)) tc_reorder="" +which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) if [ $tc_loss -eq 100 ];then tc_loss=1%
@@ -124,18 +125,18 @@ ip link add ns2eth3 netns "$ns2" type veth peer name ns3eth2 netns "$ns3" ip link add ns3eth4 netns "$ns3" type veth peer name ns4eth3 netns "$ns4" ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth2 -ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 +ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodad ip -net "$ns1" link set ns1eth2 up ip -net "$ns1" route add default via 10.0.1.2 ip -net "$ns1" route add default via dead:beef:1::2 ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1 -ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 +ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad ip -net "$ns2" link set ns2eth1 up ip -net "$ns2" addr add 10.0.2.1/24 dev ns2eth3 -ip -net "$ns2" addr add dead:beef:2::1/64 dev ns2eth3 +ip -net "$ns2" addr add dead:beef:2::1/64 dev ns2eth3 nodad ip -net "$ns2" link set ns2eth3 up ip -net "$ns2" route add default via 10.0.2.2 ip -net "$ns2" route add default via dead:beef:2::2
@@ -143,11 +144,11 @@ ip netns exec "$ns2" sysctl -q net.ipv4.ip_forward=1 ip netns exec "$ns2" sysctl -q net.ipv6.conf.all.forwarding=1 ip -net "$ns3" addr add 10.0.2.2/24 dev ns3eth2 -ip -net "$ns3" addr add dead:beef:2::2/64 dev ns3eth2 +ip -net "$ns3" addr add dead:beef:2::2/64 dev ns3eth2 nodad ip -net "$ns3" link set ns3eth2 up ip -net "$ns3" addr add 10.0.3.2/24 dev ns3eth4 -ip -net "$ns3" addr add dead:beef:3::2/64 dev ns3eth4 +ip -net "$ns3" addr add dead:beef:3::2/64 dev ns3eth4 nodad ip -net "$ns3" link set ns3eth4 up ip -net "$ns3" route add default via 10.0.2.1 ip -net "$ns3" route add default via dead:beef:2::1
@@ -155,7 +156,7 @@ ip netns exec "$ns3" sysctl -q net.ipv4.ip_forward=1 ip netns exec "$ns3" sysctl -q net.ipv6.conf.all.forwarding=1 ip -net "$ns4" addr add 10.0.3.1/24 dev ns4eth3 -ip -net "$ns4" addr add dead:beef:3::1/64 dev ns4eth3 +ip -net "$ns4" addr add dead:beef:3::1/64 dev ns4eth3 nodad ip -net "$ns4" link set ns4eth3 up ip -net "$ns4" route add default via 10.0.3.2 ip -net "$ns4" route add default via dead:beef:3::2
@@ -277,12 +278,14 @@ do_ping() local listener_ns="$1" local connector_ns="$2" local connect_addr="$3" + local ping_cmd=ping - if ! $ipv6 && is_v6 "${connect_addr}"; then - return 0 + if is_v6 "${connect_addr}"; then + $ipv6 || return 0 + ping_cmd=${ping6} fi - ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null + ip netns exec ${connector_ns} ${ping_cmd} -q -c 1 $connect_addr >/dev/null if [ $? -ne 0 ] ; then echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2 ret=1
@@ -493,12 +496,6 @@ show_all_ipv6() done } -# Allow DAD to finish -for dad in $(seq 20); do - show_all_ipv6 | grep -q -e tentative -e temporary || break - sleep 0.1 -done - echo "INFO: validating network environment with pings" for sender in "$ns1" "$ns2" "$ns3" "$ns4";do do_ping "$ns1" $sender 10.0.1.1
Signature · 1 line
2.21.0
Matthieu Baerts
[MPTCP] Re: [PATCH 1/3] selftests: fixup for IPv6 tests
Hi Paolo,
Quoted 15 lines · Paolo Abeni
Some distros still have the 'ping6' command, take care of that. Addiotnally, setting 'noadad' on ipv6 addresses will avoid explicit waits later
Squash-to: "mptcp: add basic kselftest for mptcp"
Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>--- .../selftests/net/mptcp/mptcp_connect.sh | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)tools/testing/selftests/net/mptcp/mptcp_connect.sh +0
-0
tools/testing/selftests/net/mptcp/mptcp_connect.sh ethtool_random_on=true · line 20
Quoted 4 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +1
-0@@ -17,6 +17,7 @@ ethtool_random_on=true tc_delay="$((RANDOM%400))" tc_loss=$((RANDOM%101)) tc_reorder="" +which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
Just out of curiosity: why is it not OK to use 'ping -6' on these distro?
Note that you can also use:
ping6=$(which ping6 || which ping)
(I don't think 'which' is supposed to print something if the program is not available)
tools/testing/selftests/net/mptcp/mptcp_connect.sh ip link add ns2eth3 netns "$ns2" type veth peer name ns3eth2 netns "$ns3" · line 128
Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +1
-1if [ $tc_loss -eq 100 ];then tc_loss=1%@@ -124,18 +125,18 @@ ip link add ns2eth3 netns "$ns2" type veth peer name ns3eth2 netns "$ns3" ip link add ns3eth4 netns "$ns3" type veth peer name ns4eth3 netns "$ns4" ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth2 -ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 +ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodad
What a sad option :'(
But good idea (Luke)!
[...]
tools/testing/selftests/net/mptcp/mptcp_connect.sh show_all_ipv6() · line 498
Quoted 7 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +0
-3@@ -493,12 +496,6 @@ show_all_ipv6() done } -# Allow DAD to finish -for dad in $(seq 20); do - show_all_ipv6 | grep -q -e tentative -e temporary || break
A detail but I guess we can also remove the show_all_ipv6() function declared just above that.
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Paolo Abeni
[MPTCP] Re: [PATCH 1/3] selftests: fixup for IPv6 tests
Quoted 25 lines · Matthieu Baerts
Hi Paolo,
Quoted 15 lines · Paolo Abeni
Some distros still have the 'ping6' command, take care of that. Addiotnally, setting 'noadad' on ipv6 addresses will avoid explicit waits later
Squash-to: "mptcp: add basic kselftest for mptcp"
Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>--- .../selftests/net/mptcp/mptcp_connect.sh | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)tools/testing/selftests/net/mptcp/mptcp_connect.sh +0
-0tools/testing/selftests/net/mptcp/mptcp_connect.sh ethtool_random_on=true · line 20
Quoted 4 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +1
-0@@ -17,6 +17,7 @@ ethtool_random_on=true tc_delay="$((RANDOM%400))" tc_loss=$((RANDOM%101)) tc_reorder="" +which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)Just out of curiosity: why is it not OK to use 'ping -6' on these distro?
Quoted 3 lines
Note that you can also use:
ping6=$(which ping6 || which ping)
I shamefully copied the existing code from other self-tests script to deal with that. I think adding '-6' for ipv6 address should work everywhere, let me try that.
Quoted 23 lines
(I don't think 'which' is supposed to print something if the program is not available)
tools/testing/selftests/net/mptcp/mptcp_connect.sh ip link add ns2eth3 netns "$ns2" type veth peer name ns3eth2 netns "$ns3" · line 128
Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +1
-1if [ $tc_loss -eq 100 ];then tc_loss=1%@@ -124,18 +125,18 @@ ip link add ns2eth3 netns "$ns2" type veth peer name ns3eth2 netns "$ns3" ip link add ns3eth4 netns "$ns3" type veth peer name ns4eth3 netns "$ns4" ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth2 -ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 +ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodadWhat a sad option :'(
But good idea (Luke)!
[...]
Quoted 4 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +0
-0@@ -493,12 +496,6 @@ show_all_ipv6() done }
Quoted 6 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh show_all_ipv6() · line 498
Quoted 3 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +0
-3-# Allow DAD to finish -for dad in $(seq 20); do - show_all_ipv6 | grep -q -e tentative -e temporary || breakA detail but I guess we can also remove the
show_all_ipv6()function declared just above that.
Yep, will drop in next iteration.
Thanks,
Paolo
Paolo Abeni
PATCH 2/3 mptcp: use ipv6-specific proto struct
In reply to Paolo AbeniBecause it needs a different (greater) obj_size.
Squash-to: "mptcp: Add MPTCP socket stubs"
Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
--- net/mptcp/protocol.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +8 -2
@@ -689,7 +689,7 @@ static struct proto mptcp_prot = { .unhash = inet_unhash, .get_port = mptcp_get_port, .obj_size = sizeof(struct mptcp_sock), - .no_autobind = 1, + .no_autobind = true, };static struct socket *mptcp_socket_create_get (struct mptcp_sock *msk)
@@ -972,11 +972,12 @@ void mptcp_proto_init(void)#if IS_ENABLED (CONFIG_MPTCP_IPV6 )static struct proto_ops mptcp_v6_stream_ops; +static struct proto mptcp_v6_prot;static struct inet_protosw mptcp_v6_protosw = { .type =SOCK_STREAM , .protocol =IPPROTO_MPTCP , - .prot = &mptcp_prot, + .prot = &mptcp_v6_prot, .ops = &mptcp_v6_stream_ops, .flags =INET_PROTOSW_ICSK , };
@@ -985,6 +986,11 @@ int mptcp_proto_v6_init(void) {int err; + mptcp_v6_prot = mptcp_prot; +strcpy (mptcp_v6_prot.name,"TCPv6" ); + mptcp_v6_prot.obj_size =sizeof (struct mptcp_sock ) + +sizeof (struct ipv6_pinfo ); + mptcp_v6_stream_ops = inet6_stream_ops; mptcp_v6_stream_ops.bind = mptcp_bind; mptcp_v6_stream_ops.connect = mptcp_stream_connect;
Signature · 1 line
2.21.0
Matthieu Baerts
[MPTCP] Re: [PATCH 2/3] mptcp: use ipv6-specific proto struct
Quoted 4 lines · Paolo Abeni
Because it needs a different (greater)
obj_size.Squash-to: "mptcp: Add MPTCP socket stubs"
Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
[...]
net/mptcp/protocol.c int mptcp_proto_v6_init(void) · line 990
Quoted 6 lines
net/mptcp/protocol.c +2
-0@@ -985,6 +986,11 @@ int mptcp_proto_v6_init(void) {int err; + mptcp_v6_prot = mptcp_prot; +strcpy (mptcp_v6_prot.name,"TCPv6" );
Should we call it "MPTCPv6" (mptcp_prot is called "MPTCP")
net/mptcp/protocol.c int mptcp_proto_v6_init(void) · line 992
Quoted 2 lines
net/mptcp/protocol.c +2
-0+ mptcp_v6_prot.obj_size =sizeof (struct mptcp_sock ) + +sizeof (struct ipv6_pinfo );
Very good catch!
Why did we not have the crash before?
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Paolo Abeni
[MPTCP] Re: [PATCH 2/3] mptcp: use ipv6-specific proto struct
Quoted 8 lines · Matthieu Baerts
Quoted 4 lines · Paolo Abeni
Because it needs a different (greater)
obj_size.Squash-to: "mptcp: Add MPTCP socket stubs"
Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>[...]
Quoted 8 lines
net/mptcp/protocol.c int mptcp_proto_v6_init(void) · line 990
Quoted 6 lines
net/mptcp/protocol.c +2
-0@@ -985,6 +986,11 @@ int mptcp_proto_v6_init(void) {int err; + mptcp_v6_prot = mptcp_prot; +strcpy (mptcp_v6_prot.name,"TCPv6" );Should we call it "MPTCPv6" (
mptcp_protis called "MPTCP")
Indeed! I rushed too much to assemble this patches, sorry.
Quoted 7 lines
net/mptcp/protocol.c int mptcp_proto_v6_init(void) · line 992
Quoted 3 lines
net/mptcp/protocol.c +2
-0+ mptcp_v6_prot.obj_size =sizeof (struct mptcp_sock ) + +sizeof (struct ipv6_pinfo );Very good catch!
Why did we not have the crash before?
Just a matter of luck !?! It depends on how the trailing part of mptcp_sock struct overlap with ipv6_pinfo. If we have NULL values at the 'correct' places, we can't observe the issue without setsockopt()
Possibly mptcp_struct layout changed a bit with the rebase (e.g. fields swapped)??? I haven't double checked that.
Will send v2 soon.
Paolo
p.s. we likely want to add some more self-tests doing [almost random] setsockopt on the mptcp socket before the transfer...
Paolo Abeni
PATCH 3/3 mptcp/ipv6: mptcp_v6_prot needs costom destroy.
In reply to Paolo AbeniOtherwise we can leak memory on close, if user space does some setsockopt before connectiong/accepting.
Note: the squash tag points to the commit currently introducing mptcp_destroy, but we likely want to move such function in another one - it's currently added as empty
Squash-to: "mptcp: Add key generation and token tree"
Signed-off-by: Paolo Abeni <pabeni(a)redhat.com>
--- net/mptcp/protocol.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/mptcp/protocol.c +7 -0
@@ -974,6 +974,12 @@ void mptcp_proto_init(void)static struct proto_ops mptcp_v6_stream_ops;static struct proto mptcp_v6_prot; +static void mptcp_v6_destroy (struct sock *sk) +{ +mptcp_destroy (sk); +inet6_destroy_sock (sk); +} +static struct inet_protosw mptcp_v6_protosw = { .type =SOCK_STREAM , .protocol =IPPROTO_MPTCP ,
@@ -988,6 +994,7 @@ int mptcp_proto_v6_init(void) mptcp_v6_prot = mptcp_prot;strcpy (mptcp_v6_prot.name,"TCPv6" ); + mptcp_v6_prot.destroy = mptcp_v6_destroy; mptcp_v6_prot.obj_size =sizeof (struct mptcp_sock ) +sizeof (struct ipv6_pinfo );
Signature · 1 line
2.21.0
Matthieu Baerts
Hi Paolo,
Quoted 5 lines · Paolo Abeni
We need to allocate a larger struct sock for mptcp v6 master sockets, otherwise
inet6_sk()will access mptcp related data instead of structipv6_pinfo.This should fix the crash reported by Matt.
Thank you for the quick fix!
Quoted 4 lines
The
protocol.ccode changes are split in 2 patches to simplify the squashing.
(yep, I know we somewhat agreed to big giant rebase, but this specific should be trivial).
That's a good idea because for the moment, the CI is notifying me each time that the kselftests are failing (when testing the commit introducing them)!
Quoted 1 line
Additionally adds some fixlet for the ipv6 tests
I have a few questions in the 2 first patches.
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium