From nobody Sun May 5 16:19:11 2024 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD29F813 for ; Sat, 10 Dec 2022 00:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670632099; x=1702168099; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N0y/i3Do5VdhnNWP0yR27HhYOVVlZRnZa+T/mnGs7dk=; b=Qpn4XWzKDWgjvoA0zwAf9F8ofUehhELs5nIGs85yS+Z7LhE3ZcneO00k MrPQikTnBRv3SF1zRvRxSItAasg9OgneaFmNyq61XBljaakj5/Q7iokvq SH/q9BN2SuX7I3QHLCt9oSkq+duRHhGeGW4K5CSu6seO7dxClA64WTgnI ftrsRR9eqzoh6HdFeJOK3+OVrSJr1Th3tb7b8GpQKr7kzHn/HNRu2nSFx aXRpfwpI6TLW81vHQegcPCkoHX2+gL6cYrvOBT+iiWABke8cuPVqSRSh9 gbY+z4LRn0EFKr6aGTskm0imcMy2BxOSsZOUCAIYDAq5P9Qo0gm6DoBCG w==; X-IronPort-AV: E=McAfee;i="6500,9779,10556"; a="381879114" X-IronPort-AV: E=Sophos;i="5.96,232,1665471600"; d="scan'208";a="381879114" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2022 16:28:17 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10556"; a="649728872" X-IronPort-AV: E=Sophos;i="5.96,232,1665471600"; d="scan'208";a="649728872" Received: from hthiagar-mobl1.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.212.231.121]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2022 16:28:17 -0800 From: Mat Martineau To: netdev@vger.kernel.org Cc: Wei Yongjun , davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, fw@strlen.de, kishen.maloor@intel.com, dcaratti@redhat.com, matthieu.baerts@tessares.net, mptcp@lists.linux.dev, stable@vger.kernel.org, Mat Martineau Subject: [PATCH net 1/4] mptcp: netlink: fix some error return code Date: Fri, 9 Dec 2022 16:28:07 -0800 Message-Id: <20221210002810.289674-2-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221210002810.289674-1-mathew.j.martineau@linux.intel.com> References: <20221210002810.289674-1-mathew.j.martineau@linux.intel.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wei Yongjun Fix to return negative error code -EINVAL from some error handling case instead of 0, as done elsewhere in those functions. Fixes: 9ab4807c84a4 ("mptcp: netlink: Add MPTCP_PM_CMD_ANNOUNCE") Fixes: 702c2f646d42 ("mptcp: netlink: allow userspace-driven subflow establ= ishment") Cc: stable@vger.kernel.org Reviewed-by: Matthieu Baerts Signed-off-by: Wei Yongjun Signed-off-by: Mat Martineau --- net/mptcp/pm_userspace.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 9e82250cbb70..0430415357ba 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -156,6 +156,7 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct g= enl_info *info) =20 if (addr_val.addr.id =3D=3D 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SI= GNAL)) { GENL_SET_ERR_MSG(info, "invalid addr id or flags"); + err =3D -EINVAL; goto announce_err; } =20 @@ -282,6 +283,7 @@ int mptcp_nl_cmd_sf_create(struct sk_buff *skb, struct = genl_info *info) =20 if (addr_l.id =3D=3D 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "missing local addr id"); + err =3D -EINVAL; goto create_err; } =20 @@ -395,11 +397,13 @@ int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, stru= ct genl_info *info) =20 if (addr_l.family !=3D addr_r.family) { GENL_SET_ERR_MSG(info, "address families do not match"); + err =3D -EINVAL; goto destroy_err; } =20 if (!addr_l.port || !addr_r.port) { GENL_SET_ERR_MSG(info, "missing local or remote port"); + err =3D -EINVAL; goto destroy_err; } =20 --=20 2.38.1 From nobody Sun May 5 16:19:11 2024 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42302A23 for ; Sat, 10 Dec 2022 00:28:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670632100; x=1702168100; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=392xy3qeqV/0GjxZ+l2BKrtd7OV9XUwT6YiWL1F55gU=; b=fltmsWGGTKpwhWwTwBKO58MB1w1VOa4rpWhRuboM6njNTVk2Ku8Fltnb 1bUrnZvOO59t5Ayd3iFCA4FmA1TYSsoayLT/gp86elfu5S1bSh5IttweM Wj0tlfqemMvaOoyno/SsPr7+s3F4pYRT7MGRBNvYcgA/S1QEg6m5Gz/P9 EdAtfBDwTUPHr5zmQD8ABwUB9QCr736g9a9PbZWEBBAGWo4VTh9hF1d/F 8reay0lG0kYyjPyAY+0lFXNYcw3KtoxLJwlTeOcOhvnPVNPyzTc4/8N5Y v3Sye14azTKb/THTL+uBYfqWc+oQff/pLc+0hfYy0rdoeDrgAAwPydeba Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10556"; a="381879124" X-IronPort-AV: E=Sophos;i="5.96,232,1665471600"; d="scan'208";a="381879124" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2022 16:28:18 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10556"; a="649728876" X-IronPort-AV: E=Sophos;i="5.96,232,1665471600"; d="scan'208";a="649728876" Received: from hthiagar-mobl1.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.212.231.121]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2022 16:28:17 -0800 From: Mat Martineau To: netdev@vger.kernel.org Cc: Matthieu Baerts , davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, fw@strlen.de, kishen.maloor@intel.com, dcaratti@redhat.com, mptcp@lists.linux.dev, Mat Martineau , stable@vger.kernel.org Subject: [PATCH net 2/4] mptcp: remove MPTCP 'ifdef' in TCP SYN cookies Date: Fri, 9 Dec 2022 16:28:08 -0800 Message-Id: <20221210002810.289674-3-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221210002810.289674-1-mathew.j.martineau@linux.intel.com> References: <20221210002810.289674-1-mathew.j.martineau@linux.intel.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Matthieu Baerts 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 Reviewed-by: Mat Martineau Cc: stable@vger.kernel.org Signed-off-by: Matthieu Baerts Signed-off-by: Mat Martineau --- 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.38.1 From nobody Sun May 5 16:19:11 2024 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 230757E0 for ; Sat, 10 Dec 2022 00:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670632101; x=1702168101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OzVW4qlkKrnZdTa3/VzFGvURvOKyxA+QBa1mp8cvpVo=; b=Oe1EcJGNZhlJ14y6wlTuT8aHP0icD0vRYvr+itC3nfSB+PSHbHsExlHO l7fCh82NqlW+iZwFcZ8T7nH+2ngvN5mvzrqym3xDCAucigirzY3/GiZyY Clnk0d3wHdpSjdHCArNxWURJBU93m348CeKTaXDWbqT8Z5H4rbCKY20zH a9RXHpNXHRxx0/ywnoQNXA8RzbsrFnzUPS4GxpbzkMAcnthGizny5KKQO EqbtBwRaQwGvkqpRKPQPQ1vaKzgokgWq2VUmPYtRAggOwAxt1CBYowND1 tZUzc6U37oSvm9eO2drfP1wLoPxJYG0F0Mbl897bfr97ffPudgPuJxSB4 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10556"; a="381879134" X-IronPort-AV: E=Sophos;i="5.96,232,1665471600"; d="scan'208";a="381879134" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2022 16:28:18 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10556"; a="649728880" X-IronPort-AV: E=Sophos;i="5.96,232,1665471600"; d="scan'208";a="649728880" Received: from hthiagar-mobl1.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.212.231.121]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2022 16:28:18 -0800 From: Mat Martineau To: netdev@vger.kernel.org Cc: Matthieu Baerts , davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, fw@strlen.de, kishen.maloor@intel.com, dcaratti@redhat.com, mptcp@lists.linux.dev, Mat Martineau , stable@vger.kernel.org Subject: [PATCH net 3/4] mptcp: dedicated request sock for subflow in v6 Date: Fri, 9 Dec 2022 16:28:09 -0800 Message-Id: <20221210002810.289674-4-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221210002810.289674-1-mathew.j.martineau@linux.intel.com> References: <20221210002810.289674-1-mathew.j.martineau@linux.intel.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Matthieu Baerts 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") Reviewed-by: Mat Martineau Cc: stable@vger.kernel.org Signed-off-by: Matthieu Baerts Signed-off-by: Mat Martineau --- Note: One original author of cec37a6e41aa is not cc'd due to inactive email address. --- 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.38.1 From nobody Sun May 5 16:19:11 2024 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A2F4A31 for ; Sat, 10 Dec 2022 00:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670632101; x=1702168101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qnTSysRNbAWtXozK6lTqUq/j/lCjWUE0xHsEdF/iWvg=; b=U/hktjv7n5Dh5+t6fLp96XLy7wuTRdCysq7/0/BFPa5sVhkprL5RoHI9 nzCyqpLmZZLaBY4JFu+Bp2BihFOmfyYicCyZwPXlgDKOWn0EdtM9lDMfv 6g8Ob0+pqpXQVTLizJoMjp5VlFoEq0DHZjtt3ph9QT70jGxzDwvkVPRD8 cQOyViCWTs1mPd0fFVBDvUegyYIoJQTlAHMDqiskTT6uAnUa1QhmqtGd5 QqD4Y3QYnxDQQWl0rgjvevz1dZ8Xzj60rhIy0826i0x6aa337QHg/OlVH IwC1HXUeOJyAobUY8T5qWGd/SNV79ChrR8mAM2vPA5IqytSAJDZgAqvXz Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10556"; a="381879143" X-IronPort-AV: E=Sophos;i="5.96,232,1665471600"; d="scan'208";a="381879143" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2022 16:28:18 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10556"; a="649728883" X-IronPort-AV: E=Sophos;i="5.96,232,1665471600"; d="scan'208";a="649728883" Received: from hthiagar-mobl1.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.212.231.121]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2022 16:28:18 -0800 From: Mat Martineau To: netdev@vger.kernel.org Cc: Matthieu Baerts , davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, fw@strlen.de, kishen.maloor@intel.com, dcaratti@redhat.com, mptcp@lists.linux.dev, Mat Martineau , stable@vger.kernel.org Subject: [PATCH net 4/4] mptcp: use proper req destructor for IPv6 Date: Fri, 9 Dec 2022 16:28:10 -0800 Message-Id: <20221210002810.289674-5-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221210002810.289674-1-mathew.j.martineau@linux.intel.com> References: <20221210002810.289674-1-mathew.j.martineau@linux.intel.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Matthieu Baerts Before, only the destructor from TCP request sock in IPv4 was called even if the subflow was IPv6. 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") Reviewed-by: Mat Martineau Cc: stable@vger.kernel.org Signed-off-by: Matthieu Baerts Signed-off-by: Mat Martineau --- Note: One original author of 79c0949e9a09 is not cc'd due to inactive email address. --- 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.38.1