[RFC PATCH mptcp-next v7 05/11] Initiator: add locks() to mptcp_sendmsg_fastopen.

Dmytro Shytyi posted 11 patches 3 years, 4 months ago
There is a newer version of this series
[RFC PATCH mptcp-next v7 05/11] Initiator: add locks() to mptcp_sendmsg_fastopen.
Posted by Dmytro Shytyi 3 years, 4 months ago
Suggestion of @mmartineau : 'add locks' is implemented in this patch

Signed-off-by: Dmytro Shytyi <dmytro@shytyi.net>
---
 net/mptcp/fastopen.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c
index 9974508e0f4c..50b5c3376672 100644
--- a/net/mptcp/fastopen.c
+++ b/net/mptcp/fastopen.c
@@ -16,6 +16,7 @@ int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
 	struct socket *ssk;
 	int ret;
 
+	lock_sock((struct sock *)msk);
 	ssk = __mptcp_nmpc_socket(msk);
 	if (unlikely(!ssk))
 		goto out_EFAULT;
@@ -30,26 +31,35 @@ int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
 		goto out_EFAULT;
 	uaddr = msg->msg_name;
 
+	lock_sock(ssk->sk);
+
 	tp = tcp_sk(ssk->sk);
 	if (unlikely(!tp))
-		goto out_EFAULT;
+		goto out_lock_EFAULT;
 	if (!tp->fastopen_req)
 		tp->fastopen_req = kzalloc(sizeof(*tp->fastopen_req),
 					   ssk->sk->sk_allocation);
 
 	if (unlikely(!tp->fastopen_req))
-		goto out_EFAULT;
+		goto out_lock_EFAULT;
 	tp->fastopen_req->data = msg;
 	tp->fastopen_req->size = len;
 	tp->fastopen_req->uarg = uarg;
 
+	release_sock(ssk->sk);
+	release_sock((struct sock *)msk);
+
 	/* requests a cookie */
 	ret = mptcp_stream_connect(sk->sk_socket, uaddr,
 				   msg->msg_namelen, msg->msg_flags);
 	if (!ret)
 		*copied = len;
 	return ret;
+
+out_lock_EFAULT:
+	release_sock(ssk->sk);
 out_EFAULT:
+	release_sock((struct sock *)msk);
 	ret = -EFAULT;
 	return ret;
 }
-- 
2.25.1



Re: [RFC PATCH mptcp-next v7 05/11] Initiator: add locks() to mptcp_sendmsg_fastopen.
Posted by Paolo Abeni 3 years, 4 months ago
On Sun, 2022-09-18 at 00:28 +0200, Dmytro Shytyi wrote:
> Suggestion of @mmartineau : 'add locks' is implemented in this patch
> 
> Signed-off-by: Dmytro Shytyi <dmytro@shytyi.net>

This should be likely squashed into patch 3/11. It's better to avoid
leaving broken code in the middle of the series. Incomplete
functionalitly would be ok for a mid-series patch, but not corrupting
the internal sock state.

Cheers,

Paolo
Re: [RFC PATCH mptcp-next v7 05/11] Initiator: add locks() to mptcp_sendmsg_fastopen.
Posted by Dmytro Shytyi 3 years, 4 months ago
Hello Paolo,

In v8 this is avoided.

Best,
Dmytro

On 9/19/2022 12:46 PM, Paolo Abeni wrote:
> On Sun, 2022-09-18 at 00:28 +0200, Dmytro Shytyi wrote:
>> Suggestion of @mmartineau : 'add locks' is implemented in this patch
>>
>> Signed-off-by: Dmytro Shytyi <dmytro@shytyi.net>
> This should be likely squashed into patch 3/11. It's better to avoid
> leaving broken code in the middle of the series. Incomplete
> functionalitly would be ok for a mid-series patch, but not corrupting
> the internal sock state.
>
> Cheers,
>
> Paolo
>