diff mbox series

[mptcp-net] mptcp: init mptcp request socket earlier

Message ID f512d230984510ab2ccbc4e778da4474bd2e1078.1612367293.git.pabeni@redhat.com
State Superseded, archived
Delegated to: Mat Martineau
Headers show
Series [mptcp-net] mptcp: init mptcp request socket earlier | expand

Commit Message

Paolo Abeni Feb. 3, 2021, 4:28 p.m. UTC
The mptcp subflow route_req() callback performs the subflow
req initialization after the route_req() check. If the latter
fails, mptcp-specific bits of the current request sockets
are left uninitialized.

The above causes bad things at req socket disposal time, when
the mptcp resources are cleared.

This change addresses the issue by splitting subflow_init_req()
into the actual initialization and the mptcp-specific checks.
The initialization is moved before any possibly failing check.

Reported-by: Christoph Paasch <cpaasch@apple.com>
Fixes: 7ea851d19b23 ("tcp: merge 'init_req' and 'route_req' functions")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
Should fix issues/125 && 130. Even syzkaller would proof the
opposite, the problem described above looks real.
@Christoph: could you please... ? (additional free coffee for your
upcoming holiday in Tuscany ;)
---
 net/mptcp/subflow.c | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

Comments

Christoph Paasch Feb. 3, 2021, 5:26 p.m. UTC | #1
On 02/03/21 - 17:28, Paolo Abeni wrote:
> The mptcp subflow route_req() callback performs the subflow
> req initialization after the route_req() check. If the latter
> fails, mptcp-specific bits of the current request sockets
> are left uninitialized.
> 
> The above causes bad things at req socket disposal time, when
> the mptcp resources are cleared.
> 
> This change addresses the issue by splitting subflow_init_req()
> into the actual initialization and the mptcp-specific checks.
> The initialization is moved before any possibly failing check.
> 
> Reported-by: Christoph Paasch <cpaasch@apple.com>
> Fixes: 7ea851d19b23 ("tcp: merge 'init_req' and 'route_req' functions")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
> Should fix issues/125 && 130. Even syzkaller would proof the
> opposite, the problem described above looks real.
> @Christoph: could you please... ? (additional free coffee for your
> upcoming holiday in Tuscany ;)

Looking forward to the coffee!!! :-) I hope coffee translates to red wine
later in the day!


Christoph
diff mbox series

Patch

diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 7a5518f751105..26129172f5acd 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -100,7 +100,7 @@  static struct mptcp_sock *subflow_token_join_request(struct request_sock *req)
 	return msk;
 }
 
-static int __subflow_init_req(struct request_sock *req, const struct sock *sk_listener)
+static void subflow_init_req(struct request_sock *req, const struct sock *sk_listener)
 {
 	struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
 
@@ -108,16 +108,6 @@  static int __subflow_init_req(struct request_sock *req, const struct sock *sk_li
 	subflow_req->mp_join = 0;
 	subflow_req->msk = NULL;
 	mptcp_token_init_request(req);
-
-#ifdef CONFIG_TCP_MD5SIG
-	/* no MPTCP if MD5SIG is enabled on this socket or we may run out of
-	 * TCP option space.
-	 */
-	if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info))
-		return -EINVAL;
-#endif
-
-	return 0;
 }
 
 static bool subflow_use_different_sport(struct mptcp_sock *msk, const struct sock *sk)
@@ -130,9 +120,9 @@  static bool subflow_use_different_sport(struct mptcp_sock *msk, const struct soc
  * Returns an error code if a JOIN has failed and a TCP reset
  * should be sent.
  */
-static int subflow_init_req(struct request_sock *req,
-			    const struct sock *sk_listener,
-			    struct sk_buff *skb)
+static int subflow_check_req(struct request_sock *req,
+			     const struct sock *sk_listener,
+			     struct sk_buff *skb)
 {
 	struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk_listener);
 	struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
@@ -141,9 +131,13 @@  static int subflow_init_req(struct request_sock *req,
 
 	pr_debug("subflow_req=%p, listener=%p", subflow_req, listener);
 
-	ret = __subflow_init_req(req, sk_listener);
-	if (ret)
-		return 0;
+#ifdef CONFIG_TCP_MD5SIG
+	/* no MPTCP if MD5SIG is enabled on this socket or we may run out of
+	 * TCP option space.
+	 */
+	if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info))
+		return -EINVAL;
+#endif
 
 	mptcp_get_options(skb, &mp_opt);
 
@@ -236,10 +230,7 @@  int mptcp_subflow_init_cookie_req(struct request_sock *req,
 	struct mptcp_options_received mp_opt;
 	int err;
 
-	err = __subflow_init_req(req, sk_listener);
-	if (err)
-		return err;
-
+	subflow_init_req(req, sk_listener);
 	mptcp_get_options(skb, &mp_opt);
 
 	if (mp_opt.mp_capable && mp_opt.mp_join)
@@ -279,12 +270,13 @@  static struct dst_entry *subflow_v4_route_req(const struct sock *sk,
 	int err;
 
 	tcp_rsk(req)->is_mptcp = 1;
+	subflow_init_req(req, sk);
 
 	dst = tcp_request_sock_ipv4_ops.route_req(sk, skb, fl, req);
 	if (!dst)
 		return NULL;
 
-	err = subflow_init_req(req, sk, skb);
+	err = subflow_check_req(req, sk, skb);
 	if (err == 0)
 		return dst;
 
@@ -304,12 +296,13 @@  static struct dst_entry *subflow_v6_route_req(const struct sock *sk,
 	int err;
 
 	tcp_rsk(req)->is_mptcp = 1;
+	subflow_init_req(req, sk);
 
 	dst = tcp_request_sock_ipv6_ops.route_req(sk, skb, fl, req);
 	if (!dst)
 		return NULL;
 
-	err = subflow_init_req(req, sk, skb);
+	err = subflow_check_req(req, sk, skb);
 	if (err == 0)
 		return dst;