* [PATCH net-next v1] mptcp: fix incorrect IPv4/IPv6 check
@ 2025-10-14 12:26 Jiayuan Chen
2025-10-14 15:27 ` Matthieu Baerts
0 siblings, 1 reply; 4+ messages in thread
From: Jiayuan Chen @ 2025-10-14 12:26 UTC (permalink / raw)
To: mptcp, linux-kernel
Cc: Jiayuan Chen, Matthieu Baerts, Mat Martineau, Geliang Tang,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Davide Caratti, netdev
When MPTCP falls back to normal TCP, it needs to reset proto_ops. However,
for sockmap and TLS, they have their own custom proto_ops, so simply
checking sk->sk_prot is insufficient.
For example, an IPv6 request might incorrectly follow the IPv4 code path,
leading to kernel panic.
Note that Golang has enabled MPTCP by default [1]
[1] https://go-review.googlesource.com/c/go/+/607715
Fixes: 8e2b8a9fa512 ("mptcp: don't overwrite sock_ops in mptcp_is_tcpsk()")
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
net/mptcp/protocol.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 0292162a14ee..efcdaeff91f8 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -62,10 +62,10 @@ static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
static const struct proto_ops *mptcp_fallback_tcp_ops(const struct sock *sk)
{
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
- if (sk->sk_prot == &tcpv6_prot)
+ if (sk->sk_family == AF_INET6)
return &inet6_stream_ops;
#endif
- WARN_ON_ONCE(sk->sk_prot != &tcp_prot);
+ WARN_ON(sk->sk_family != AF_INET);
return &inet_stream_ops;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v1] mptcp: fix incorrect IPv4/IPv6 check
2025-10-14 12:26 [PATCH net-next v1] mptcp: fix incorrect IPv4/IPv6 check Jiayuan Chen
@ 2025-10-14 15:27 ` Matthieu Baerts
2025-10-15 14:16 ` Jiayuan Chen
0 siblings, 1 reply; 4+ messages in thread
From: Matthieu Baerts @ 2025-10-14 15:27 UTC (permalink / raw)
To: Jiayuan Chen
Cc: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Davide Caratti, netdev,
mptcp, linux-kernel
Hi Jiayuan,
Thank you for sharing this patch!
On 14/10/2025 14:26, Jiayuan Chen wrote:
> When MPTCP falls back to normal TCP, it needs to reset proto_ops. However,
> for sockmap and TLS, they have their own custom proto_ops, so simply
> checking sk->sk_prot is insufficient.
>
> For example, an IPv6 request might incorrectly follow the IPv4 code path,
> leading to kernel panic.
Did you experiment issues, or is it a supposition? If yes, do you have
traces containing such panics (or just a WARN()?), and ideally the
userspace code that was leading to this?
What is unclear to me is how you got an MPTCP + TLS + sockmap socket.
And if yes, can we set sk_socket->ops to inet(6)_stream_ops and nothing
else without having any other issues?
And do we maybe have to update some code in subflow.c also looking at
sk->sk_prot? I guess no because there, the socket is created by MPTCP,
and it should be set to tcp(v6)_prot. Except if there is some BPF code
that can change that?
> Note that Golang has enabled MPTCP by default [1]
>
> [1] https://go-review.googlesource.com/c/go/+/607715
>
> Fixes: 8e2b8a9fa512 ("mptcp: don't overwrite sock_ops in mptcp_is_tcpsk()")
If I understand the issue correctly, was it not present from the
beginning, before the mentioned commit?
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> net/mptcp/protocol.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 0292162a14ee..efcdaeff91f8 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -62,10 +62,10 @@ static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
> static const struct proto_ops *mptcp_fallback_tcp_ops(const struct sock *sk)
> {
> #if IS_ENABLED(CONFIG_MPTCP_IPV6)
> - if (sk->sk_prot == &tcpv6_prot)
> + if (sk->sk_family == AF_INET6)
sk_prot was proving it was a TCP + IPv4/6 socket, and then that's OK to
set inet(6)_stream_ops. I guess we could only check the family, but, can
we always return inet(6)_stream_ops no matter what sk->sk_prot is?
If the protocol has been modified, the stream one has maybe been
modified too, no?
> return &inet6_stream_ops;
> #endif
> - WARN_ON_ONCE(sk->sk_prot != &tcp_prot);
> + WARN_ON(sk->sk_family != AF_INET);
Please keep the WARN_ON_ONCE().
Maybe we should not return inet_stream_ops in case the previous
condition was wrong, and not change sk_socket->ops.
> return &inet_stream_ops;
> }
Note about the subject: if it is a fix for an older commit, it should
target 'net', not 'net-next' (+ cc stable). Can you also have a clearer
subject mentioning 'proto' and 'fallback' please?
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v1] mptcp: fix incorrect IPv4/IPv6 check
2025-10-14 15:27 ` Matthieu Baerts
@ 2025-10-15 14:16 ` Jiayuan Chen
2025-10-23 14:00 ` Matthieu Baerts
0 siblings, 1 reply; 4+ messages in thread
From: Jiayuan Chen @ 2025-10-15 14:16 UTC (permalink / raw)
To: Matthieu Baerts
Cc: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Davide Caratti, netdev,
mptcp, linux-kernel
October 14, 2025 at 23:27, "Matthieu Baerts" <matttbe@kernel.org mailto:matttbe@kernel.org?to=%22Matthieu%20Baerts%22%20%3Cmatttbe%40kernel.org%3E > wrote:
>
> Hi Jiayuan,
>
> Thank you for sharing this patch!
>
> On 14/10/2025 14:26, Jiayuan Chen wrote:
>
> >
> > When MPTCP falls back to normal TCP, it needs to reset proto_ops. However,
> > for sockmap and TLS, they have their own custom proto_ops, so simply
> > checking sk->sk_prot is insufficient.
> >
> > For example, an IPv6 request might incorrectly follow the IPv4 code path,
> > leading to kernel panic.
> >
> Did you experiment issues, or is it a supposition? If yes, do you have
> traces containing such panics (or just a WARN()?), and ideally the
> userspace code that was leading to this?
>
Thank you, Matthieu, for your suggestions. I spent some time revisiting the MPTCP logic.
Now I need to describe how sockmap/skmsg works to explain its conflict with MPTCP:
1. skmsg works by replacing sk_data_ready, recvmsg, sendmsg operations and implementing
fast socket-level forwarding logic
2. Users can obtain file descriptors through userspace socket()/accept() interfaces, then
call BPF syscall to perform these replacements.
3. Users can also use the bpf_sock_hash_update helper (in sockops programs) to replace
handlers when TCP connections enter ESTABLISHED state (BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB or BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB)
For MPTCP to work with sockmap, I believe we need to address the following points
(please correct me if I have any conceptual misunderstandings about MPTCP):
1. From client perspective: When a user connects to a server via socket(), the kernel
creates one master sk and at least two subflow sk's. Since the master sk doesn't participate
in the three-way handshake, in the sockops flow we can only access the subflow sk's.
In this case, we need to replace the handlers of mptcp_subflow_ctx(sk)->conn rather
than the subflow sk itself.
2. From server perspective: In BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, the sk is the MP_CAPABLE
subflow sk, so similar to the client perspective, we need to replace the handlers of
mptcp_subflow_ctx(sk)->conn.
If the above description is correct, then my current patch is incorrect. I should focus on
handling the sockmap handler replacement flow properly instead.
Of course, this would require comprehensive selftests to validate.
Returning to the initial issue, the panic occurred on kernel 6.1, but when I tested with the
latest upstream test environment, it only triggered a WARN().
I suspect there have been significant changes in MPTCP during this period.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v1] mptcp: fix incorrect IPv4/IPv6 check
2025-10-15 14:16 ` Jiayuan Chen
@ 2025-10-23 14:00 ` Matthieu Baerts
0 siblings, 0 replies; 4+ messages in thread
From: Matthieu Baerts @ 2025-10-23 14:00 UTC (permalink / raw)
To: Jiayuan Chen
Cc: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Davide Caratti, netdev,
mptcp, linux-kernel
Hi Jiayuan,
Thank you for your reply (and sorry for the delay, I was unavailable for
a few days).
On 15/10/2025 16:16, Jiayuan Chen wrote:
> October 14, 2025 at 23:27, "Matthieu Baerts" <matttbe@kernel.org> wrote:
>> On 14/10/2025 14:26, Jiayuan Chen wrote:
>>
>>>
>>> When MPTCP falls back to normal TCP, it needs to reset proto_ops. However,
>>> for sockmap and TLS, they have their own custom proto_ops, so simply
>>> checking sk->sk_prot is insufficient.
>>>
>>> For example, an IPv6 request might incorrectly follow the IPv4 code path,
>>> leading to kernel panic.
>>>
>> Did you experiment issues, or is it a supposition? If yes, do you have
>> traces containing such panics (or just a WARN()?), and ideally the
>> userspace code that was leading to this?
>>
>
>
> Thank you, Matthieu, for your suggestions. I spent some time revisiting the MPTCP logic.
>
>
> Now I need to describe how sockmap/skmsg works to explain its conflict with MPTCP:
OK, so the issue is only with sockmap, not TLS, right?
> 1. skmsg works by replacing sk_data_ready, recvmsg, sendmsg operations and implementing
> fast socket-level forwarding logic
>
> 2. Users can obtain file descriptors through userspace socket()/accept() interfaces, then
> call BPF syscall to perform these replacements.
> 3. Users can also use the bpf_sock_hash_update helper (in sockops programs) to replace
> handlers when TCP connections enter ESTABLISHED state (BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB or BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB)
I appreciate these explanations. I will comment on the v3.
> For MPTCP to work with sockmap, I believe we need to address the following points
> (please correct me if I have any conceptual misunderstandings about MPTCP):
>
> 1. From client perspective: When a user connects to a server via socket(), the kernel
> creates one master sk and at least two subflow sk's. Since the master sk doesn't participate
> in the three-way handshake, in the sockops flow we can only access the subflow sk's.
To be a bit more precise, with MPTCP, you will deal with different
socket types:
- the userspace facing one: it is an MPTCP socket (IPPROTO_MPTCP)
- the in-kernel subflow(s) (= path): they are TCP sockets, but not
exposed to the userspace.
There is no "master sk" (I hope you didn't look at the previous fork
implementation that was using this name, before the upstreaming
process), but yes, you will have the MPTCP socket, and at least one TCP
socket for the subflow.
> In this case, we need to replace the handlers of mptcp_subflow_ctx(sk)->conn rather
> than the subflow sk itself.
>> 2. From server perspective: In BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB,
the sk is the MP_CAPABLE
> subflow sk, so similar to the client perspective, we need to replace the handlers of
> mptcp_subflow_ctx(sk)->conn.
On the userspace side, the socket after the 'accept()' is either an
MPTCP socket (IPPROTO_MPTCP) or a TCP one (IPPROTO_TCP) depending on the
request: if the SYN was containing the MP_CAPABLE option or not. If a
plain TCP socket is returned, it is not an MPTCP subflow any more, it is
a "classic" TCP connection.
To get MPTCP support with sockmap, I guess you will need to act at the
MPTCP level: you should never manipulate the data on the TCP subflows
directly, because you will only get a part of the data when multiple
paths are being used. Instead, you should wait for MPTCP to re-order the
data, etc.
> If the above description is correct, then my current patch is incorrect. I should focus on
> handling the sockmap handler replacement flow properly instead.
It would be really great to add MPTCP support in sockmap, but first, I
guess we need a way to prevent issues like the one you saw.
> Of course, this would require comprehensive selftests to validate.
>
> Returning to the initial issue, the panic occurred on kernel 6.1, but when I tested with the
> latest upstream test environment, it only triggered a WARN().
> I suspect there have been significant changes in MPTCP during this period.
Even if it was only triggering a WARN(), we will still need a fix for
v6.1. Once the series will be ready, do you mind checking what needs to
be done to have the solution working on v6.1? I guess the solution
should be very close to what we will have on v6.18.
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-23 14:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14 12:26 [PATCH net-next v1] mptcp: fix incorrect IPv4/IPv6 check Jiayuan Chen
2025-10-14 15:27 ` Matthieu Baerts
2025-10-15 14:16 ` Jiayuan Chen
2025-10-23 14:00 ` Matthieu Baerts
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).