mptcp: don't orphan ssk in mptcp_close()
Subsystems (2)
PATCH 1/1 mptcp: don't orphan ssk in mptcp_close()
From: Menglong Dong <[email protected]>
All of the subflows of a msk will be orphaned in mptcp_close(), which means the subflows are in DEAD state. After then, DATA_FIN will be sent, and the other side will response with a DATA_ACK for this DATA_FIN.
However, if the other side still has pending data, the data that received on these subflows will not be passed to the msk, as they are DEAD and subflow_data_ready() will not be called in tcp_data_ready(). Therefore, these data can't be acked, and they will be retransmitted again and again, until timeout.
Fix this by not orphaning the subflows in mptcp_close(). I think that's ok, as they can still be orphaned in __mptcp_close_ssk(). Maybe we can also fix this in mptcp_incoming_options() by check the status of ssk and msk?
--- net/mptcp/protocol.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/mptcp/protocol.c +1 -2
@@ -815,7 +815,7 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)/* Wake-up the reader only for in-sequence data */ mptcp_data_lock (sk); -if (move_skbs_to_msk (msk, ssk)) +if (move_skbs_to_msk (msk, ssk) && !sock_flag (sk,SOCK_DEAD )) sk->sk_data_ready (sk);mptcp_data_unlock (sk);
@@ -2940,7 +2940,6 @@ bool __mptcp_close(struct sock *sk, long timeout)if (ssk == msk->first) subflow->fail_tout =0 ; -sock_orphan (ssk);unlock_sock_fast (ssk, slow); }sock_orphan (sk);
Signature · 1 line
2.37.2
Re: mptcp: don't orphan ssk in mptcp_close(): Tests Results
Hi Menglong,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal:
- Success! ✅:
- Task: https://cirrus-ci.com/task/4892156595273728
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4892156595273728/summary/summary.txt
- KVM Validation: debug:
- Unstable: 1 failed test(s): packetdrill_add_addr - Critical: 1 Call Trace(s) ❌:
- Task: https://cirrus-ci.com/task/6018056502116352
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6018056502116352/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/0061c26274eb
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-debugFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)
Hi Menglong,
Quoted 11 lines · On 18/11/2022 08:20, [email protected] wrote:
From: Menglong Dong <[email protected]>
All of the subflows of a msk will be orphaned in
mptcp_close(), which means the subflows are in DEAD state. After then,DATA_FINwill be sent, and the other side will response with aDATA_ACKfor thisDATA_FIN.However, if the other side still has pending data, the data that received on these subflows will not be passed to the msk, as they are DEAD and
subflow_data_ready()will not be called intcp_data_ready(). Therefore, these data can't be acked, and they will be retransmitted again and again, until timeout.
Thank you for the patch.
I don't know if you noticed but the CI found an issue with it:
- KVM Validation: debug:
- Unstable: 1 failed test(s): packetdrill_add_addr - Critical: 1 Call
Trace(s) ❌:
- Task: https://cirrus-ci.com/task/6018056502116352
- Summary:
https://api.cirrus-ci.com/v1/artifact/task/6018056502116352/summary/summary.txt
Do you mind looking at that please?
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Quoted 19 lines · Matthieu Baerts
Hi Menglong,
Quoted 11 lines · On 18/11/2022 08:20, [email protected] wrote:
From: Menglong Dong <[email protected]>
All of the subflows of a msk will be orphaned in
mptcp_close(), which means the subflows are in DEAD state. After then,DATA_FINwill be sent, and the other side will response with aDATA_ACKfor thisDATA_FIN.However, if the other side still has pending data, the data that received on these subflows will not be passed to the msk, as they are DEAD and
subflow_data_ready()will not be called intcp_data_ready(). Therefore, these data can't be acked, and they will be retransmitted again and again, until timeout.Thank you for the patch.
I don't know if you noticed but the CI found an issue with it:
Quoted 9 lines
- KVM Validation: debug:
- Unstable: 1 failed test(s):packetdrill_add_addr- Critical: 1 Call
Trace(s) ❌:
- Task: https://cirrus-ci.com/task/6018056502116352
- Summary:
https://api.cirrus-ci.com/v1/artifact/task/6018056502116352/summary/summary.txtDo you mind looking at that please?
Yeah, I noticed it. Seems the ssk is using msk->sk_socket, which will be freed after mptcp_close(). I'm still thinking :/
Thanks!
Menglong Dong
Quoted 5 lines
Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Paolo Abeni
maintainerHello,
Quoted 12 lines · On Fri, 2022-11-18 at 15:20 +0800, [email protected] wrote:
From: Menglong Dong <[email protected]>
All of the subflows of a msk will be orphaned in
mptcp_close(), which means the subflows are in DEAD state. After then,DATA_FINwill be sent, and the other side will response with aDATA_ACKfor thisDATA_FIN.However, if the other side still has pending data, the data that received on these subflows will not be passed to the msk, as they are DEAD and
subflow_data_ready()will not be called intcp_data_ready(). Therefore, these data can't be acked, and they will be retransmitted again and again, until timeout.
Quoted 4 lines
Fix this by not orphaning the subflows in
mptcp_close(). I think that's ok, as they can still be orphaned in__mptcp_close_ssk(). Maybe we can also fix this inmptcp_incoming_options()by check the status of ssk and msk?
Thank you for clearly debugging this scenario!
As noted by the CI, this fix causes an UaF, as mptcp_close() frees the msk->sk_socket struct, which is also referenced by ssk->sk_socket.
Without orphaning the subflows, later tcp code will use ssk->sk_socket, causing the reported splat. Note that there is the same risk with ssk-
Quoted 1 line
sk_wq.
Since:
* all the network code carefully checks for not NULL value of ssk-
Quoted 1 line
sk_socketbefore accessing it
* access it directly in context where it can't be NULL
* uses the same policies to access 'sk_wq'
* it looks like the SOCK_DONE flag can be set independently from the sock_orphan()
I think mptcp_close() could instead directly clearing ssk->sk_socket and ssk->sk_wq - just ' = NULL', no sock_orphan() call - and __mptcp_close_ssk() could be changed accordingly:
net/mptcp/protocol.c +0 -0
@@ -2340,11 +2340,7 @@ static void __mptcp_close_ssk(struct sock *sk,
struct sock *ssk,
goto out;
}- /* if we are invoked by the msk cleanup code, the subflow is
- * already orphaned
- */
- if (ssk->sk_socket)
- sock_orphan(ssk);
+ sock_orphan(ssk);
subflow->disposable = 1;
Quoted 12 lines
Reviewed-by Biao Jiang <[email protected]>Reviewed-by Mengen Sun <[email protected]>Signed-off-by Menglong Dong <[email protected]>--- net/mptcp/protocol.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/mptcp/protocol.c +0
-0
net/mptcp/protocol.c void mptcp_data_ready(struct sock *sk, struct sock *ssk) · line 819
Quoted 6 lines
net/mptcp/protocol.c +1
-1@@ -815,7 +815,7 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)/* Wake-up the reader only for in-sequence data */ mptcp_data_lock (sk); -if (move_skbs_to_msk (msk, ssk)) +if (move_skbs_to_msk (msk, ssk) && !sock_flag (sk,SOCK_DEAD )) sk->sk_data_ready (sk);
I think this is not need right? sk_data_ready == sock_def_readable, will check carefully sk->sk_wq which should be NULL after close.
Thank!
Paolo
Paolo Abeni
maintainerQuoted 2 lines · Paolo Abeni
As noted by the CI, this fix causes an UaF, as
mptcp_close()frees themsk->sk_socketstruct, which is also referenced byssk->sk_socket.
I almost forgot: see mptcp_sock_graft()
Quoted 6 lines
Without orphaning the subflows, later tcp code will use
ssk->sk_socket, causing the reported splat. Note that there is the same risk with ssk-Quoted 1 line
sk_wq.Since:
* all the network code carefully checks for not NULL value of ssk-
Quoted 8 lines
Quoted 1 line
sk_socketbefore accessing it* access it directly in context where it can't be NULL
* uses the same policies to access 'sk_wq'
* it looks like theSOCK_DONEflag can be set independently from thesock_orphan()I think
mptcp_close()could instead directly clearingssk->sk_socketandssk->sk_wq- just ' = NULL', nosock_orphan()call
To be explicit, I mean something alike:
net/mptcp/protocol.c +5 -1
@@ -2938,7 +2938,11 @@ bool __mptcp_close(struct sock *sk, long timeout)if (ssk == msk->first) subflow->fail_tout =0 ; -sock_orphan (ssk); +/* detach from the parent socket, but allow data_ready to +* push incoming date into the mptcp stack, to properly ack it +*/ + ssk->sk_socket =NULL ; + ssk->sk_wq =NULL ;unlock_sock_fast (ssk, slow); }sock_orphan (sk);
Cheers,
Paolo
Hello,
Quoted 1 line · Paolo Abeni
[......]
Quoted 30 lines
Thank you for clearly debugging this scenario!
As noted by the CI, this fix causes an UaF, as
mptcp_close()frees themsk->sk_socketstruct, which is also referenced byssk->sk_socket.Without orphaning the subflows, later tcp code will use
ssk->sk_socket, causing the reported splat. Note that there is the same risk with ssk-Quoted 1 line
sk_wq.Since:
* all the network code carefully checks for not NULL value of ssk-Quoted 1 line
sk_socketbefore accessing it* access it directly in context where it can't be NULL
* uses the same policies to access 'sk_wq'
* it looks like theSOCK_DONEflag can be set independently from thesock_orphan()I think
mptcp_close()could instead directly clearingssk->sk_socketandssk->sk_wq- just ' = NULL', nosock_orphan()call - and__mptcp_close_ssk()could be changed accordingly:net/mptcp/protocol.c +0
-0@@ -2340,11 +2340,7 @@ static void __mptcp_close_ssk(struct sock *sk,struct sock *ssk, goto out;
net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, · line 2346
Quoted 10 lines
net/mptcp/protocol.c +1
-5} -/* if we are invoked by the msk cleanup code, the subflow is -* already orphaned -*/ -if (ssk->sk_socket) -sock_orphan (ssk); +sock_orphan (ssk); subflow->disposable =1 ;
Thanks for your detailed explanation, and I'll send the V2 according to it!
Quoted 13 lines
Quoted 13 lines
Reviewed-by Biao Jiang <[email protected]>Reviewed-by Mengen Sun <[email protected]>Signed-off-by Menglong Dong <[email protected]>--- net/mptcp/protocol.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/mptcp/protocol.c +0
-0@@ -815,7 +815,7 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)
Quoted 9 lines
net/mptcp/protocol.c void mptcp_data_ready(struct sock *sk, struct sock *ssk) · line 819
Quoted 5 lines
net/mptcp/protocol.c +1
-1/* Wake-up the reader only for in-sequence data */ mptcp_data_lock (sk); -if (move_skbs_to_msk (msk, ssk)) +if (move_skbs_to_msk (msk, ssk) && !sock_flag (sk,SOCK_DEAD )) sk->sk_data_ready (sk);I think this is not need right?
sk_data_ready==sock_def_readable, will check carefullysk->sk_wqwhich should be NULL after close.
Yeah, this check seems unnecessary, I'll remove it.
Quoted 4 lines
Thank!
Paolo