From nobody Sat Apr 27 19:13:51 2024 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D25DA50 for ; Wed, 30 Nov 2022 09:45:03 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id ml11so15053957ejb.6 for ; Wed, 30 Nov 2022 01:45:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f6qIp98IdyNHtYmrmCJesqbBwp2qgAQB0hOzZtk0bcY=; b=u/pUw9LL7t3UKyqwANVp9gcH90Jg234ZxAyniwJyq2o3PueukTcoxw2I2X1tVf+ySt 7f6MJSSq8sfGu+mc1bFIdsakJL5GeEJOGxdWcCjUuP2OFWTDZUD2WKvDUNhXvHDvGH9L D6kImIdiqdQzOmFe41BXQv7i6fiqCH9T8lJvlSzoFbQw2QECYfVJ8PoGZe8fiFVou31Y ahuwNsfyfgv6gysM3lYcH2KIWQbejUmhuqt0u4RkC5B1fTR2qKgvEtwfFRuWnPO0ALxC dGX8vLol9Egfig/ZF2xN67AaaxTue20zhTD+Jr4rY3lV7iw5P2rsp7/cWVl1WTDHO5vT lwzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f6qIp98IdyNHtYmrmCJesqbBwp2qgAQB0hOzZtk0bcY=; b=Lfg6jeY48NVzu4b+5QD4LcjiLAs2XJfY+Dogn3NU9dVI73ETQoyplYVJPvDddlqWfx M9nUkPx1q8QMcO8R2gW9A30pjam7avYs/Q+mUrxWmDme9RGqOG+oFd+lXko3mMnizEFB zjq/6ZIdIRin3KOA2N5YwzQQqiQnGDRriMwaNLJkeGeEjnPq2LVcqHxCK3kVI+IsTcMr zT4Iq+v/lwljFNUyYvJJOOPgB5Mbg3VnwtkDMtprOUBIGIImt8RKattGpps4l2TqPzdl hgFv/tqrl9VC2fc4TeYmyMSAfxWYqiSOjmycbivow/ax63aFiV92skKZ15hAiwU10W70 7/Lw== X-Gm-Message-State: ANoB5plA+6KFAPROBcSWEqGpSTRKLO4QixXHEn1zFhgcOw3mnX7vL4oP lT1ILKu77ZDRPXBo5nJmeuixJkETF2f8jEzTrGI= X-Google-Smtp-Source: AA0mqf6QzmvVEh+J9BQUTCqjrTmyYcA3m4FFx+TYeR4TJqAgXkZLc12qubj4bvHJ7XbXfRqBb2i9eg== X-Received: by 2002:a17:906:ce49:b0:7bd:2800:9ac6 with SMTP id se9-20020a170906ce4900b007bd28009ac6mr20122161ejb.386.1669801501663; Wed, 30 Nov 2022 01:45:01 -0800 (PST) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id p26-20020a17090653da00b007417041fb2bsm440374ejo.116.2022.11.30.01.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 01:45:01 -0800 (PST) From: Matthieu Baerts To: mptcp@lists.linux.dev Cc: Matthieu Baerts , Paolo Abeni Subject: [PATCH mptcp-net v2 1/3] mptcp: remove MPTCP 'ifdef' in TCP SYN cookies Date: Wed, 30 Nov 2022 10:44:46 +0100 Message-Id: <20221130094448.4119946-2-matthieu.baerts@tessares.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221130094448.4119946-1-matthieu.baerts@tessares.net> References: <20221130094448.4119946-1-matthieu.baerts@tessares.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3839; i=matthieu.baerts@tessares.net; h=from:subject; bh=mh1QVBzeNkxTkcbdWyMlbsfTKJPR8xiIHKRtCGjFPj4=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBjhyYP0BFJPabc/OZrB9y8z6Nu9TSM8oGGkzWxbKl4 +rqJ362JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCY4cmDwAKCRD2t4JPQmmgc15hEA CaEy+Djj63EMKnx82bGQ8sB6ui1UClR8GP8Id8qclvDxnhIT1mHI4n3IFx8AWSJwH+vj5tz8A6pkad PUgpwR17YHtcE5aKJuknkkOaPSp1DBvoLNQ6Xa7zvjDwNzyc1QTqoImml65v4U0Fewb2c02PrPw5Kq l6qAfHt1izwPNbXxieoFo2daW6HkpK/RdAb5t1hE4u5KP7xIOQUoUFWOKWg3xPR6jTlh4saJKDK+S7 jUSoqY4efabYTjECahuKzH0e7meuqRR+2S+RHjAqPmJvYOHzs5YoLhBzTVW/l/H3K0dZWPk6mOn/JH x9ndyh+zhbxMFjQVNsVhqsMdztn8xhmbRgY3HGU6LTr035vU1vjeG1Z4pQO+xj7mT+MY9HzHFoNIL4 gtzqvk5uvbiVHuiw//jfdHF1a7dyEVhpnUBMoEJl78JlD0oBjEO55sJFLd4knaVuqL7IpRkFB/+z3a +Ovta/RFsieGPthh5wke38h2AlLJIkGxQmA5cSb3BWMzP/OM/0gnqo4QzNPH9bJ2oUqy7K2LRkxVa/ S1fsU+f3i6mNz0BeI7TZ+qlb90vmLBITbbyU3/8ZtbJXLQ31e5Wpvn2kTwFVaNSD42nOfMpC/zBWNk wHXe3zVg8q3+nZUYqjDO1FnD4PdL3T4Eb+ZDOQnq/FdgCLiAPElZMWqQ29eA== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To ease the maintenance, it is often recommended to avoid having #ifdef preprocessor conditions. Here the section related to CONFIG_MPTCP was quite short but the next commit needs to add more code around. It is then cleaner to move specific MPTCP code to functions located in net/mptcp directory. Now that mptcp_subflow_request_sock_ops structure can be static, it can also be marked as "read only after init". Suggested-by: Paolo Abeni Signed-off-by: Matthieu Baerts --- Notes: v2: - mark mptcp_subflow_request_sock_ops as static and __ro_after_init include/net/mptcp.h | 12 ++++++++++-- net/ipv4/syncookies.c | 7 +++---- net/mptcp/subflow.c | 12 +++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 412479ebf5ad..3c5c68618fcc 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -97,8 +97,6 @@ struct mptcp_out_options { }; =20 #ifdef CONFIG_MPTCP -extern struct request_sock_ops mptcp_subflow_request_sock_ops; - void mptcp_init(void); =20 static inline bool sk_is_mptcp(const struct sock *sk) @@ -188,6 +186,9 @@ void mptcp_seq_show(struct seq_file *seq); int mptcp_subflow_init_cookie_req(struct request_sock *req, const struct sock *sk_listener, struct sk_buff *skb); +struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_o= ps *ops, + struct sock *sk_listener, + bool attach_listener); =20 __be32 mptcp_get_reset_option(const struct sk_buff *skb); =20 @@ -274,6 +275,13 @@ static inline int mptcp_subflow_init_cookie_req(struct= request_sock *req, return 0; /* TCP fallback */ } =20 +static inline struct request_sock *mptcp_subflow_reqsk_alloc(const struct = request_sock_ops *ops, + struct sock *sk_listener, + bool attach_listener) +{ + return NULL; +} + static inline __be32 mptcp_reset_option(const struct sk_buff *skb) { retu= rn htonl(0u); } #endif /* CONFIG_MPTCP */ =20 diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 942d2dfa1115..26fb97d1d4d9 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -288,12 +288,11 @@ struct request_sock *cookie_tcp_reqsk_alloc(const str= uct request_sock_ops *ops, struct tcp_request_sock *treq; struct request_sock *req; =20 -#ifdef CONFIG_MPTCP if (sk_is_mptcp(sk)) - ops =3D &mptcp_subflow_request_sock_ops; -#endif + req =3D mptcp_subflow_reqsk_alloc(ops, sk, false); + else + req =3D inet_reqsk_alloc(ops, sk, false); =20 - req =3D inet_reqsk_alloc(ops, sk, false); if (!req) return NULL; =20 diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 2159b5f9988f..3f670f2d5c5c 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -529,7 +529,7 @@ static int subflow_v6_rebuild_header(struct sock *sk) } #endif =20 -struct request_sock_ops mptcp_subflow_request_sock_ops; +static struct request_sock_ops mptcp_subflow_request_sock_ops __ro_after_i= nit; static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops __ro_afte= r_init; =20 static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb) @@ -582,6 +582,16 @@ static int subflow_v6_conn_request(struct sock *sk, st= ruct sk_buff *skb) } #endif =20 +struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_o= ps *ops, + struct sock *sk_listener, + bool attach_listener) +{ + ops =3D &mptcp_subflow_request_sock_ops; + + return inet_reqsk_alloc(ops, sk_listener, attach_listener); +} +EXPORT_SYMBOL(mptcp_subflow_reqsk_alloc); + /* validate hmac received in third ACK */ static bool subflow_hmac_valid(const struct request_sock *req, const struct mptcp_options_received *mp_opt) --=20 2.37.2 From nobody Sat Apr 27 19:13:51 2024 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E83FBA53 for ; Wed, 30 Nov 2022 09:45:04 +0000 (UTC) Received: by mail-ej1-f41.google.com with SMTP id td2so25838697ejc.5 for ; Wed, 30 Nov 2022 01:45:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+OPzP72YVvsKNRova7w6dCkXRYl3zdDddxtmB9UpT/M=; b=VJilSHZtNi46jyg+58pTWW3bUc7rrWPfF1fozBH3gP0JSIq0byojWY83w365xMP78f KX3aM5REl1KsTdtwpNTx5QTWdlq68mTzwxp+2ecMoemmqVIOWIodB3jRZYrlblEamysI jSKNu3VXcBvIm+JZCJaqsDwlGwRBLTNIGJOUmLdQWj5Uc0kJW/CrSapIaxXijEjt7V87 Au0y/dJbjqxoqRDf0Hey9wdls7D7fEHeQN8nYKoR7S79YZ5wQQAZ0AEXHtdKjcVrPlrK wIZcxGjIjDOg3i2nyoLnBC1O1j4jt6Xg5X1IiwcM6a6tyHC5+RXZR7bLD0Pq96s03pvX 4lhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+OPzP72YVvsKNRova7w6dCkXRYl3zdDddxtmB9UpT/M=; b=7VMr7GAMXpb7EOObmxSuWioRsKtiO2r5E2u6IkByu0ILz/AX0ma+knAhottcCl2yFT q25H7ru5W/q0JW8ObOVnFk3+TiyP1WB1sRMGmuPu1XgV9iLdy3oCm3n7e9oydi4geauU eV5A2dtsebuFozpuEeewliCGf+OJHdXzEJE3VYccghinuSIjXebTuAlRHx4HYVY44RJJ yC/FFmuYzhY48r3did2JatsBk3nBMW6/vIZ64+xAdCwXv3e/hnEWqm8ePZgfhwzHc/sR mWmFvw3Dsjx7YSL2spdq8z1tP5nGsZSaHCdd2PHKiahuwQwQdZkYu/iVvosV7lJvfTST NYdQ== X-Gm-Message-State: ANoB5pmMhzVJk/fSCnhJv977KRvm/CEKPUlfJYsnLTdj2tGbpxkC7BFG 3Z8H/UZ92Re0BBz59Ez6fCA6UysOXqo1fBuFj4w= X-Google-Smtp-Source: AA0mqf7LGimQqqx38j4VKU8zFZ6z7sPRuIbjoxIR51bRfAQQbutATRFRart58SyW7xRoRFREtc+iSQ== X-Received: by 2002:a17:906:4f0b:b0:78d:aaf9:7b8c with SMTP id t11-20020a1709064f0b00b0078daaf97b8cmr52326545eju.229.1669801502719; Wed, 30 Nov 2022 01:45:02 -0800 (PST) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id p26-20020a17090653da00b007417041fb2bsm440374ejo.116.2022.11.30.01.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 01:45:02 -0800 (PST) From: Matthieu Baerts To: mptcp@lists.linux.dev Cc: Matthieu Baerts Subject: [PATCH mptcp-net v2 2/3] mptcp: dedicated request sock for subflow in v6 Date: Wed, 30 Nov 2022 10:44:47 +0100 Message-Id: <20221130094448.4119946-3-matthieu.baerts@tessares.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221130094448.4119946-1-matthieu.baerts@tessares.net> References: <20221130094448.4119946-1-matthieu.baerts@tessares.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5338; i=matthieu.baerts@tessares.net; h=from:subject; bh=nNvDKHN7jwhttWm6YkrluXFMyhdxMmvAI49u4wU70TU=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBjhyYQR9t8k39bRwqmo3rxD0G2Nj4AQvoxFwN30f9C 1GByZSiJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCY4cmEAAKCRD2t4JPQmmgc2p+EA Cp+d4yioDJehkc3muoibloa3i7yess4FDZv1Rge2+uW0GHljO6Jvby9q3cPlawrBLVbj0PmuLb/PHM imMsaaMNYX2naXCTi65x4mBqj4V4uKp4JVO5IUjW5+vJ+cA2NpUtcXvmd/EimGdpIgSjoQBgRx2EMH TiamdWsa2hwv+B6biXzVHSb4Zdd7hDBCYm8WuxWIlVJGcyoCEBcJzuXdKcq2bDA768WEnLyD7wVJ5X SlHkVtbqqsNnYBU4lLYOOYXGBYXmbuwizfQ0pmxPSSR4GYaoJxw5s4cynNFVpMLhfXfQp/QXOlNBDl 05fjzz3jW7kwz9XAx7nmYs2B4ulKVofgqxAUEhmzCT+C3HTABxMH2aFhYYqQTgsOWxZqQ6ag7UoKWD p81yXfA6UGRMUMoQvGLH2lvp7XujFodW/5W/zDTJPja+p7NVnkOOLYQWVX4YI+YMaFU144vsdBa/LM 1HnBOVXE+sR9TZ2F/nT7YAl5gm4pRfmQcSG8Xf9/o9oVpVSpGXQiykY5QJsHfaVk96AuDh2025W6Eh MxwJ/wMzjJGxAdDH6GqefOIv4juAkn9C8UXTDE9CPvbkzogF10Nu1lZQriUsJ3GFLBopeh8qiruYfG U9PpixcsCKsO0o21k+9i4mQGq3iNxOJoIrbExsjzd8VehTcbdvFERaVhFA8g== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" tcp_request_sock_ops structure is specific to IPv4. It should then not be used with MPTCP subflows on top of IPv6. For example, it contains the 'family' field, initialised to AF_INET. This 'family' field is used by TCP FastOpen code to generate the cookie but also by TCP Metrics, SELinux and SYN Cookies. Using the wrong family will not lead to crashes but displaying/using/checking wrong things. Note that 'send_reset' callback from request_sock_ops structure is used in some error paths. It is then also important to use the correct one for IPv4 or IPv6. The slab name can also be different in IPv4 and IPv6, it will be used when printing some log messages. The slab pointer will anyway be the same because the object size is the same for both v4 and v6. A BUILD_BUG_ON() has also been added to make sure this size is the same. Fixes: cec37a6e41aa ("mptcp: Handle MP_CAPABLE options for outgoing connect= ions") Signed-off-by: Matthieu Baerts --- net/mptcp/subflow.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 3f670f2d5c5c..30524dd7d0ec 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -529,7 +529,7 @@ static int subflow_v6_rebuild_header(struct sock *sk) } #endif =20 -static struct request_sock_ops mptcp_subflow_request_sock_ops __ro_after_i= nit; +static struct request_sock_ops mptcp_subflow_v4_request_sock_ops __ro_afte= r_init; static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops __ro_afte= r_init; =20 static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb) @@ -542,7 +542,7 @@ static int subflow_v4_conn_request(struct sock *sk, str= uct sk_buff *skb) if (skb_rtable(skb)->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) goto drop; =20 - return tcp_conn_request(&mptcp_subflow_request_sock_ops, + return tcp_conn_request(&mptcp_subflow_v4_request_sock_ops, &subflow_request_sock_ipv4_ops, sk, skb); drop: @@ -551,6 +551,7 @@ static int subflow_v4_conn_request(struct sock *sk, str= uct sk_buff *skb) } =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) +static struct request_sock_ops mptcp_subflow_v6_request_sock_ops __ro_afte= r_init; static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops __ro_afte= r_init; static struct inet_connection_sock_af_ops subflow_v6_specific __ro_after_i= nit; static struct inet_connection_sock_af_ops subflow_v6m_specific __ro_after_= init; @@ -573,7 +574,7 @@ static int subflow_v6_conn_request(struct sock *sk, str= uct sk_buff *skb) return 0; } =20 - return tcp_conn_request(&mptcp_subflow_request_sock_ops, + return tcp_conn_request(&mptcp_subflow_v6_request_sock_ops, &subflow_request_sock_ipv6_ops, sk, skb); =20 drop: @@ -586,7 +587,12 @@ struct request_sock *mptcp_subflow_reqsk_alloc(const s= truct request_sock_ops *op struct sock *sk_listener, bool attach_listener) { - ops =3D &mptcp_subflow_request_sock_ops; + if (ops->family =3D=3D AF_INET) + ops =3D &mptcp_subflow_v4_request_sock_ops; +#if IS_ENABLED(CONFIG_MPTCP_IPV6) + else if (ops->family =3D=3D AF_INET6) + ops =3D &mptcp_subflow_v6_request_sock_ops; +#endif =20 return inet_reqsk_alloc(ops, sk_listener, attach_listener); } @@ -1914,7 +1920,6 @@ static struct tcp_ulp_ops subflow_ulp_ops __read_most= ly =3D { static int subflow_ops_init(struct request_sock_ops *subflow_ops) { subflow_ops->obj_size =3D sizeof(struct mptcp_subflow_request_sock); - subflow_ops->slab_name =3D "request_sock_subflow"; =20 subflow_ops->slab =3D kmem_cache_create(subflow_ops->slab_name, subflow_ops->obj_size, 0, @@ -1931,9 +1936,10 @@ static int subflow_ops_init(struct request_sock_ops = *subflow_ops) =20 void __init mptcp_subflow_init(void) { - mptcp_subflow_request_sock_ops =3D tcp_request_sock_ops; - if (subflow_ops_init(&mptcp_subflow_request_sock_ops) !=3D 0) - panic("MPTCP: failed to init subflow request sock ops\n"); + mptcp_subflow_v4_request_sock_ops =3D tcp_request_sock_ops; + mptcp_subflow_v4_request_sock_ops.slab_name =3D "request_sock_subflow_v4"; + if (subflow_ops_init(&mptcp_subflow_v4_request_sock_ops) !=3D 0) + panic("MPTCP: failed to init subflow v4 request sock ops\n"); =20 subflow_request_sock_ipv4_ops =3D tcp_request_sock_ipv4_ops; subflow_request_sock_ipv4_ops.route_req =3D subflow_v4_route_req; @@ -1948,6 +1954,18 @@ void __init mptcp_subflow_init(void) tcp_prot_override.release_cb =3D tcp_release_cb_override; =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) + /* In struct mptcp_subflow_request_sock, we assume the TCP request sock + * structures for v4 and v6 have the same size. It should not changed in + * the future but better to make sure to be warned if it is no longer + * the case. + */ + BUILD_BUG_ON(sizeof(struct tcp_request_sock) !=3D sizeof(struct tcp6_requ= est_sock)); + + mptcp_subflow_v6_request_sock_ops =3D tcp6_request_sock_ops; + mptcp_subflow_v6_request_sock_ops.slab_name =3D "request_sock_subflow_v6"; + if (subflow_ops_init(&mptcp_subflow_v6_request_sock_ops) !=3D 0) + panic("MPTCP: failed to init subflow v6 request sock ops\n"); + subflow_request_sock_ipv6_ops =3D tcp_request_sock_ipv6_ops; subflow_request_sock_ipv6_ops.route_req =3D subflow_v6_route_req; =20 --=20 2.37.2 From nobody Sat Apr 27 19:13:51 2024 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E91BA50 for ; Wed, 30 Nov 2022 09:45:05 +0000 (UTC) Received: by mail-ej1-f48.google.com with SMTP id gu23so21739865ejb.10 for ; Wed, 30 Nov 2022 01:45:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mDtmQkx0EPenR7HCvKKtLgp6rEirI9Z8ixDkUQBw9gQ=; b=tlcUTp0hBxBqGWivTn/HEgFVUDqvvTJSLIjB5336UtIWGmGlL79gnmwqHmmpsxdDog Re4kWEaBs5pjkTpwrjjlxKTxpc0qSbiljqaVkenv1R5cD6eh5gFC8jBJSvLOtyVRuHp9 rXivfoG/WDgFBxqgKMGXidqofonLGUmfylXToWsKmnVi+kWY5yIeRAOKeKiU5iRoJTPR UwHfiyusyF+pJebiDYB2B1uN1B4VqLIkl9g6E3RPULBy5Sst3YBQBCtlGkUvXQzs894G iz0rF17xClVdgObwFoNQ2i7wuYjZpD4zMQlIICMsZZIj0KPudYtwPYnfQNoPz/8H+8R9 BBaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mDtmQkx0EPenR7HCvKKtLgp6rEirI9Z8ixDkUQBw9gQ=; b=zhCcnDA1Ef9iFzJUeHwPIFF93Ztzf+JYMq1B01UPBwKNXP02cUQPwPbykrbJusUhQT rCpiCzW6ei0OAS0huif1dLqrXRst7L4FiVef5Lbt0/+Dy2Wlj0lJbJVuUD7ctIE7MZTT qOdyNowU39hdOVyFoOCnVnxCnw7EckG21ZUUsdVQVI98ieCAK2CdzBm6Wby5jBmdWCE7 VFbPJKgANIdKqL5rUxsTIgw6leVauuXBNkpmT03y6DySdr5VuXBuFMYRofWagWTr4alY sP6esIadbKbPNhrLNPo1cLPx3y4VuX3fqJucNkYHR0LdBE4y6UjPWKkRq72LHEhfgp6I N7YA== X-Gm-Message-State: ANoB5pkIqgNHeAUKPvkDrmn6RvuMwRAjkkFmNPFpZsjxdvpQ92qUPYOW lJO4izYNNZyi8fny+VdQGXLyByyvTQwvgpIsL0Q= X-Google-Smtp-Source: AA0mqf5bcOdGMj4iqVg97yczQUWoMKpYgl2wkuaVwiyVuRPu1p5COpVKqTCI9SXXwS4njvPj8JbJDw== X-Received: by 2002:a17:907:9852:b0:7a8:a957:5b4e with SMTP id jj18-20020a170907985200b007a8a9575b4emr11121469ejc.305.1669801503842; Wed, 30 Nov 2022 01:45:03 -0800 (PST) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id p26-20020a17090653da00b007417041fb2bsm440374ejo.116.2022.11.30.01.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 01:45:03 -0800 (PST) From: Matthieu Baerts To: mptcp@lists.linux.dev Cc: Matthieu Baerts Subject: [PATCH mptcp-net v2 3/3] mptcp: use proper req destructor for IPv6 Date: Wed, 30 Nov 2022 10:44:48 +0100 Message-Id: <20221130094448.4119946-4-matthieu.baerts@tessares.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221130094448.4119946-1-matthieu.baerts@tessares.net> References: <20221130094448.4119946-1-matthieu.baerts@tessares.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2883; i=matthieu.baerts@tessares.net; h=from:subject; bh=nmePdAzT+1vjHcV8VvYMPUr5K9xnzFEYyhw2i69GLiQ=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBjhyYQyekmrcWdr/Ddj0RCAT53neewqOqC7HUFyNh/ yO63GUCJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCY4cmEAAKCRD2t4JPQmmgc1iSEA Dk+0QBEn0pgbNP4rgG/lDPRScs0MAWPBpkDx5dRzr55jXIfzrT6KqXj2ZKvSjnbUtV1YWeHM6kbzap NnYztDehO0PMKRtmuRImPscV3hht4GmyE2J90iPVxFbwYevpPFOWWj6+EuMwJwws6i58mG6sjDvd5L /3r+PuJzOBEEq5CjgL4u8AVZgSS5Lorwv6KjkN4ADo9KTza0NtWSaO7j7YEjN0Lsn6vCjLJZLV42gC Ly9AcfF/2cuuSaCoTJ/Fh+NXRDJkZDtVQg77PkDEkvL4zdT+JGPCoXjh5UrxWWoegXMGOUZhpbsgCb DE7Li7kQIKLLNkqoBLGkfgKNLcgRutDXDNfzMrvR8m2aUKCxbt00+GSwysF+Fwg3nNforOzCipg/Ca vy/NTIzB1J3KjS3ZEuZOTbx7qEwoFb6yNUrkyKsfi26Q9zc2QbdCbJjhSkKHYBMTq7o6xqx5S0y0lS xckF/Iwe+12viUG1oJGK12eyHXI3TjBjDfvZpEZ0zawTxFm/nz9iQHHha26U/5/v0mckLvm1dMkNzb 0VVDFPNW+TZM2Dbk5WKGXwYST6EjNwLCG70F0FKouOvxeQX/YpmOOleC6WGAu9SDNDfgFeMEQONSVA oNWlgDgt6Aj/DdN50BJemx9c1mOcWm8Cjm0mS1NSpNeMtL1p2f9HzjgVU1JQ== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Before, only the destructor from TCP request sock in IPv4 was called even if the subflow was in v4. It is important to use the right destructor to avoid memory leaks with some advanced IPv6 features, e.g. when the request socks contain specific IPv6 options. Fixes: 79c0949e9a09 ("mptcp: Add key generation and token tree") Signed-off-by: Matthieu Baerts Reviewed-by: Mat Martineau --- net/mptcp/subflow.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 30524dd7d0ec..613f515fedf0 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -45,7 +45,6 @@ static void subflow_req_destructor(struct request_sock *r= eq) sock_put((struct sock *)subflow_req->msk); =20 mptcp_token_destroy_request(req); - tcp_request_sock_ops.destructor(req); } =20 static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonc= e2, @@ -550,6 +549,12 @@ static int subflow_v4_conn_request(struct sock *sk, st= ruct sk_buff *skb) return 0; } =20 +static void subflow_v4_req_destructor(struct request_sock *req) +{ + subflow_req_destructor(req); + tcp_request_sock_ops.destructor(req); +} + #if IS_ENABLED(CONFIG_MPTCP_IPV6) static struct request_sock_ops mptcp_subflow_v6_request_sock_ops __ro_afte= r_init; static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops __ro_afte= r_init; @@ -581,6 +586,12 @@ static int subflow_v6_conn_request(struct sock *sk, st= ruct sk_buff *skb) tcp_listendrop(sk); return 0; /* don't send reset */ } + +static void subflow_v6_req_destructor(struct request_sock *req) +{ + subflow_req_destructor(req); + tcp6_request_sock_ops.destructor(req); +} #endif =20 struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_o= ps *ops, @@ -1929,8 +1940,6 @@ static int subflow_ops_init(struct request_sock_ops *= subflow_ops) if (!subflow_ops->slab) return -ENOMEM; =20 - subflow_ops->destructor =3D subflow_req_destructor; - return 0; } =20 @@ -1938,6 +1947,8 @@ void __init mptcp_subflow_init(void) { mptcp_subflow_v4_request_sock_ops =3D tcp_request_sock_ops; mptcp_subflow_v4_request_sock_ops.slab_name =3D "request_sock_subflow_v4"; + mptcp_subflow_v4_request_sock_ops.destructor =3D subflow_v4_req_destructo= r; + if (subflow_ops_init(&mptcp_subflow_v4_request_sock_ops) !=3D 0) panic("MPTCP: failed to init subflow v4 request sock ops\n"); =20 @@ -1963,6 +1974,8 @@ void __init mptcp_subflow_init(void) =20 mptcp_subflow_v6_request_sock_ops =3D tcp6_request_sock_ops; mptcp_subflow_v6_request_sock_ops.slab_name =3D "request_sock_subflow_v6"; + mptcp_subflow_v6_request_sock_ops.destructor =3D subflow_v6_req_destructo= r; + if (subflow_ops_init(&mptcp_subflow_v6_request_sock_ops) !=3D 0) panic("MPTCP: failed to init subflow v6 request sock ops\n"); =20 --=20 2.37.2