mptcp: Stable backports for MPTCP request sock fixes
Subsystems (4)
cover mptcp: Stable backports for MPTCP request sock fixes
Greg -
Here are backports of the MPTCP patches, and one prerequisite, that recently failed to apply to the 5.10 stable tree. They prevent IPv6 memory leaks with MPTCP.
Thanks!
Florian Westphal (1):
mptcp: mark ops structures as ro_after_init
Matthieu Baerts (3):
mptcp: remove MPTCP 'ifdef' in TCP SYN cookies
mptcp: dedicated request sock for subflow in v6
mptcp: use proper req destructor for IPv6
include/net/mptcp.h | 12 +++++-- net/ipv4/syncookies.c | 7 ++-- net/mptcp/subflow.c | 76 +++++++++++++++++++++++++++++++++---------- 3 files changed, 71 insertions(+), 24 deletions(-)
Signature · 1 line
2.39.0
PATCH 1/4 mptcp: mark ops structures as ro_after_init
From: Florian Westphal <[email protected]>
commit 51fa7f8ebf0e25c7a9039fa3988a623d5f3855aa upstream.
These structures are initialised from the init hooks, so we can't make them 'const'. But no writes occur afterwards, so we can use ro_after_init.
Also, remove bogus EXPORT_SYMBOL, the only access comes from ip stack, not from kernel modules.
--- net/mptcp/subflow.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
net/mptcp/subflow.c +7 -8
@@ -360,8 +360,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) }struct request_sock_ops mptcp_subflow_request_sock_ops; -EXPORT_SYMBOL_GPL (mptcp_subflow_request_sock_ops); -static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops; +static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops__ro_after_init ;static int subflow_v4_conn_request (struct sock *sk,struct sk_buff *skb) {
@@ -382,9 +381,9 @@ static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb) }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops; -static struct inet_connection_sock_af_ops subflow_v6_specific; -static struct inet_connection_sock_af_ops subflow_v6m_specific; +static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops__ro_after_init ; +static struct inet_connection_sock_af_ops subflow_v6_specific__ro_after_init ; +static struct inet_connection_sock_af_ops subflow_v6m_specific__ro_after_init ;static int subflow_v6_conn_request (struct sock *sk,struct sk_buff *skb) {
@@ -636,7 +635,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,return child; } -static struct inet_connection_sock_af_ops subflow_specific; +static struct inet_connection_sock_af_ops subflow_specific__ro_after_init ;enum mapping_status {MAPPING_OK ,
@@ -1017,7 +1016,7 @@ static void subflow_write_space(struct sock *sk) } } -static struct inet_connection_sock_af_ops * +static const struct inet_connection_sock_af_ops *subflow_default_af_ops (struct sock *sk) {#if IS_ENABLED (CONFIG_MPTCP_IPV6 )
@@ -1032,7 +1031,7 @@ void mptcpv6_handle_mapped(struct sock *sk, bool mapped) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk);struct inet_connection_sock *icsk =inet_csk (sk); -struct inet_connection_sock_af_ops *target; +const struct inet_connection_sock_af_ops *target; target = mapped ? &subflow_v6m_specific :subflow_default_af_ops (sk);
Signature · 1 line
2.39.0
Patch "mptcp: mark ops structures as ro_after_init" has been added to the 5.10-stable tree
This is a note to let you know that I've just added the patch titled
mptcp: mark ops structures as ro_after_init
to the 5.10-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mptcp-mark-ops-structures-as-ro_after_init.patch
and it can be found in the queue-5.10 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Sat Jan 7 02:46:46 2023
From: Mat Martineau <[email protected]>
Date: Fri, 6 Jan 2023 17:46:28 -0800
Subject: mptcp: mark ops structures as ro_after_init
To: [email protected], [email protected]
Cc: Florian Westphal <[email protected]>, [email protected], [email protected], [email protected], Mat Martineau <[email protected]>, Jakub Kicinski <[email protected]>
Message-ID: <[email protected]>
From: Mat Martineau <[email protected]>
From: Florian Westphal <[email protected]>
commit 51fa7f8ebf0e25c7a9039fa3988a623d5f3855aa upstream.
These structures are initialised from the init hooks, so we can't make them 'const'. But no writes occur afterwards, so we can use ro_after_init.
Also, remove bogus EXPORT_SYMBOL, the only access comes from ip stack, not from kernel modules.
--- net/mptcp/subflow.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
net/mptcp/subflow.c +7 -8
@@ -360,8 +360,7 @@ do_reset: }struct request_sock_ops mptcp_subflow_request_sock_ops; -EXPORT_SYMBOL_GPL (mptcp_subflow_request_sock_ops); -static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops; +static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops__ro_after_init ;static int subflow_v4_conn_request (struct sock *sk,struct sk_buff *skb) {
@@ -382,9 +381,9 @@ drop: }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops; -static struct inet_connection_sock_af_ops subflow_v6_specific; -static struct inet_connection_sock_af_ops subflow_v6m_specific; +static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops__ro_after_init ; +static struct inet_connection_sock_af_ops subflow_v6_specific__ro_after_init ; +static struct inet_connection_sock_af_ops subflow_v6m_specific__ro_after_init ;static int subflow_v6_conn_request (struct sock *sk,struct sk_buff *skb) {
@@ -636,7 +635,7 @@ dispose_child:return child; } -static struct inet_connection_sock_af_ops subflow_specific; +static struct inet_connection_sock_af_ops subflow_specific__ro_after_init ;enum mapping_status {MAPPING_OK ,
@@ -1017,7 +1016,7 @@ static void subflow_write_space(struct s } } -static struct inet_connection_sock_af_ops * +static const struct inet_connection_sock_af_ops *subflow_default_af_ops (struct sock *sk) {#if IS_ENABLED (CONFIG_MPTCP_IPV6 )
@@ -1032,7 +1031,7 @@ void mptcpv6_handle_mapped(struct sock * {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk);struct inet_connection_sock *icsk =inet_csk (sk); -struct inet_connection_sock_af_ops *target; +const struct inet_connection_sock_af_ops *target; target = mapped ? &subflow_v6m_specific :subflow_default_af_ops (sk);
Patches currently in stable-queue which might be from [email protected] are
queue-5.10/mptcp-use-proper-req-destructor-for-ipv6.patch queue-5.10/mptcp-remove-mptcp-ifdef-in-tcp-syn-cookies.patch queue-5.10/mptcp-dedicated-request-sock-for-subflow-in-v6.patch queue-5.10/mptcp-mark-ops-structures-as-ro_after_init.patch
PATCH 2/4 mptcp: remove MPTCP 'ifdef' in TCP SYN cookies
In reply to Mat MartineauFrom: Matthieu Baerts <[email protected]>
commit 3fff88186f047627bb128d65155f42517f8e448f upstream.
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".
--- include/net/mptcp.h | 12 ++++++++++-- net/ipv4/syncookies.c | 7 +++---- net/mptcp/subflow.c | 12 +++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-)
include/net/mptcp.h +10 -2
@@ -58,8 +58,6 @@ struct mptcp_out_options { };#ifdef CONFIG_MPTCP -extern struct request_sock_ops mptcp_subflow_request_sock_ops; -void mptcp_init (void );static inline bool sk_is_mptcp (const struct sock *sk)
@@ -133,6 +131,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_ops *ops, +struct sock *sk_listener, +bool attach_listener);#else static inline void mptcp_init (void )
@@ -208,6 +209,13 @@ static inline int mptcp_subflow_init_cookie_req(struct request_sock *req, {return 0 ;/* TCP fallback */ } + +static inline struct request_sock *mptcp_subflow_reqsk_alloc (const struct request_sock_ops *ops, +struct sock *sk_listener, +bool attach_listener) +{ +return NULL ; +}#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
net/ipv4/syncookies.c +3 -4
@@ -290,12 +290,11 @@ struct request_sock *cookie_tcp_reqsk_alloc(const struct request_sock_ops *ops,struct tcp_request_sock *treq;struct request_sock *req; -#ifdef CONFIG_MPTCP if (sk_is_mptcp (sk)) - ops = &mptcp_subflow_request_sock_ops; -#endif + req =mptcp_subflow_reqsk_alloc (ops, sk, false); +else + req =inet_reqsk_alloc (ops, sk, false); - req =inet_reqsk_alloc (ops, sk, false);if (!req)return NULL ;
net/mptcp/subflow.c +11 -1
@@ -359,7 +359,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)mptcp_subflow_reset (sk); } -struct request_sock_ops mptcp_subflow_request_sock_ops; +static struct request_sock_ops mptcp_subflow_request_sock_ops__ro_after_init ;static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops__ro_after_init ;static int subflow_v4_conn_request (struct sock *sk,struct sk_buff *skb)
@@ -411,6 +411,16 @@ static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb) }#endif +struct request_sock *mptcp_subflow_reqsk_alloc (const struct request_sock_ops *ops, +struct sock *sk_listener, +bool attach_listener) +{ + ops = &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)
Signature · 1 line
2.39.0
Patch "mptcp: remove MPTCP 'ifdef' in TCP SYN cookies" has been added to the 5.10-stable tree
This is a note to let you know that I've just added the patch titled
mptcp: remove MPTCP 'ifdef' in TCP SYN cookies
to the 5.10-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mptcp-remove-mptcp-ifdef-in-tcp-syn-cookies.patch
and it can be found in the queue-5.10 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Sat Jan 7 02:46:48 2023
From: Mat Martineau <[email protected]>
Date: Fri, 6 Jan 2023 17:46:29 -0800
Subject: mptcp: remove MPTCP 'ifdef' in TCP SYN cookies
To: [email protected], [email protected]
Cc: Matthieu Baerts <[email protected]>, [email protected], [email protected], Mat Martineau <[email protected]>, Jakub Kicinski <[email protected]>
Message-ID: <[email protected]>
From: Mat Martineau <[email protected]>
From: Matthieu Baerts <[email protected]>
commit 3fff88186f047627bb128d65155f42517f8e448f upstream.
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".
--- include/net/mptcp.h | 12 ++++++++++-- net/ipv4/syncookies.c | 7 +++---- net/mptcp/subflow.c | 12 +++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-)
include/net/mptcp.h +10 -2
@@ -58,8 +58,6 @@ struct mptcp_out_options { };#ifdef CONFIG_MPTCP -extern struct request_sock_ops mptcp_subflow_request_sock_ops; -void mptcp_init (void );static inline bool sk_is_mptcp (const struct sock *sk)
@@ -133,6 +131,9 @@ void mptcp_seq_show(struct seq_file *seqint 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_ops *ops, +struct sock *sk_listener, +bool attach_listener);#else static inline void mptcp_init (void )
@@ -208,6 +209,13 @@ static inline int mptcp_subflow_init_coo {return 0 ;/* TCP fallback */ } + +static inline struct request_sock *mptcp_subflow_reqsk_alloc (const struct request_sock_ops *ops, +struct sock *sk_listener, +bool attach_listener) +{ +return NULL ; +}#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
net/ipv4/syncookies.c +3 -4
@@ -290,12 +290,11 @@ struct request_sock *cookie_tcp_reqsk_alstruct tcp_request_sock *treq;struct request_sock *req; -#ifdef CONFIG_MPTCP if (sk_is_mptcp (sk)) - ops = &mptcp_subflow_request_sock_ops; -#endif + req =mptcp_subflow_reqsk_alloc (ops, sk, false); +else + req =inet_reqsk_alloc (ops, sk, false); - req =inet_reqsk_alloc (ops, sk, false);if (!req)return NULL ;
net/mptcp/subflow.c +11 -1
@@ -359,7 +359,7 @@ do_reset:mptcp_subflow_reset (sk); } -struct request_sock_ops mptcp_subflow_request_sock_ops; +static struct request_sock_ops mptcp_subflow_request_sock_ops__ro_after_init ;static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops__ro_after_init ;static int subflow_v4_conn_request (struct sock *sk,struct sk_buff *skb)
@@ -411,6 +411,16 @@ drop: }#endif +struct request_sock *mptcp_subflow_reqsk_alloc (const struct request_sock_ops *ops, +struct sock *sk_listener, +bool attach_listener) +{ + ops = &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)
Patches currently in stable-queue which might be from [email protected] are
queue-5.10/mptcp-use-proper-req-destructor-for-ipv6.patch queue-5.10/mptcp-remove-mptcp-ifdef-in-tcp-syn-cookies.patch queue-5.10/mptcp-dedicated-request-sock-for-subflow-in-v6.patch queue-5.10/mptcp-mark-ops-structures-as-ro_after_init.patch
PATCH 3/4 mptcp: dedicated request sock for subflow in v6
In reply to Mat MartineauFrom: Matthieu Baerts <[email protected]>
commit 34b21d1ddc8ace77a8fa35c1b1e06377209e0dae upstream.
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.
--- net/mptcp/subflow.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
net/mptcp/subflow.c +26 -8
@@ -359,7 +359,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)mptcp_subflow_reset (sk); } -static struct request_sock_ops mptcp_subflow_request_sock_ops__ro_after_init ; +static struct request_sock_ops mptcp_subflow_v4_request_sock_ops__ro_after_init ;static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops__ro_after_init ;static int subflow_v4_conn_request (struct sock *sk,struct sk_buff *skb)
@@ -372,7 +372,7 @@ static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb)if (skb_rtable (skb)->rt_flags & (RTCF_BROADCAST |RTCF_MULTICAST )) goto drop; -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:
@@ -381,6 +381,7 @@ static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb) }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) +static struct request_sock_ops mptcp_subflow_v6_request_sock_ops__ro_after_init ;static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops__ro_after_init ;static struct inet_connection_sock_af_ops subflow_v6_specific__ro_after_init ;static struct inet_connection_sock_af_ops subflow_v6m_specific__ro_after_init ;
@@ -402,7 +403,7 @@ static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb)return 0 ; } -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); drop:
@@ -415,7 +416,12 @@ struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *op struct sock *sk_listener, bool attach_listener) { - ops = &mptcp_subflow_request_sock_ops; +if (ops->family ==AF_INET ) + ops = &mptcp_subflow_v4_request_sock_ops; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else if (ops->family == AF_INET6) + ops = &mptcp_subflow_v6_request_sock_ops; +#endif return inet_reqsk_alloc (ops, sk_listener, attach_listener); }
@@ -1386,7 +1392,6 @@ static struct tcp_ulp_ops subflow_ulp_ops __read_mostly = {static int subflow_ops_init (struct request_sock_ops *subflow_ops) { subflow_ops->obj_size =sizeof (struct mptcp_subflow_request_sock ); - subflow_ops->slab_name ="request_sock_subflow" ; subflow_ops->slab = kmem_cache_create(subflow_ops->slab_name, subflow_ops->obj_size, 0,
@@ -1403,9 +1408,10 @@ static int subflow_ops_init(struct request_sock_ops *subflow_ops)void __init mptcp_subflow_init (void ) { - mptcp_subflow_request_sock_ops = tcp_request_sock_ops; -if (subflow_ops_init (&mptcp_subflow_request_sock_ops) !=0 ) -panic ("MPTCP: failed to init subflow request sock ops\n" ); + mptcp_subflow_v4_request_sock_ops = tcp_request_sock_ops; + mptcp_subflow_v4_request_sock_ops.slab_name ="request_sock_subflow_v4" ; +if (subflow_ops_init (&mptcp_subflow_v4_request_sock_ops) !=0 ) +panic ("MPTCP: failed to init subflow v4 request sock ops\n" ); subflow_request_sock_ipv4_ops = tcp_request_sock_ipv4_ops; subflow_request_sock_ipv4_ops.init_req = subflow_v4_init_req;
@@ -1416,6 +1422,18 @@ void __init mptcp_subflow_init(void) subflow_specific.sk_rx_dst_set = subflow_finish_connect;#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 ) !=sizeof (struct tcp6_request_sock )); + + mptcp_subflow_v6_request_sock_ops = tcp6_request_sock_ops; + mptcp_subflow_v6_request_sock_ops.slab_name ="request_sock_subflow_v6" ; +if (subflow_ops_init (&mptcp_subflow_v6_request_sock_ops) !=0 ) +panic ("MPTCP: failed to init subflow v6 request sock ops\n" ); + subflow_request_sock_ipv6_ops = tcp_request_sock_ipv6_ops; subflow_request_sock_ipv6_ops.init_req = subflow_v6_init_req;
Signature · 1 line
2.39.0
Patch "mptcp: dedicated request sock for subflow in v6" has been added to the 5.10-stable tree
This is a note to let you know that I've just added the patch titled
mptcp: dedicated request sock for subflow in v6
to the 5.10-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mptcp-dedicated-request-sock-for-subflow-in-v6.patch
and it can be found in the queue-5.10 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Sat Jan 7 02:46:49 2023
From: Mat Martineau <[email protected]>
Date: Fri, 6 Jan 2023 17:46:30 -0800
Subject: mptcp: dedicated request sock for subflow in v6
To: [email protected], [email protected]
Cc: Matthieu Baerts <[email protected]>, [email protected], [email protected], Mat Martineau <[email protected]>, Jakub Kicinski <[email protected]>
Message-ID: <[email protected]>
From: Mat Martineau <[email protected]>
From: Matthieu Baerts <[email protected]>
commit 34b21d1ddc8ace77a8fa35c1b1e06377209e0dae upstream.
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.
--- net/mptcp/subflow.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
net/mptcp/subflow.c +26 -8
@@ -359,7 +359,7 @@ do_reset:mptcp_subflow_reset (sk); } -static struct request_sock_ops mptcp_subflow_request_sock_ops__ro_after_init ; +static struct request_sock_ops mptcp_subflow_v4_request_sock_ops__ro_after_init ;static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops__ro_after_init ;static int subflow_v4_conn_request (struct sock *sk,struct sk_buff *skb)
@@ -372,7 +372,7 @@ static int subflow_v4_conn_request(strucif (skb_rtable (skb)->rt_flags & (RTCF_BROADCAST |RTCF_MULTICAST )) goto drop; -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:
@@ -381,6 +381,7 @@ drop: }#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) +static struct request_sock_ops mptcp_subflow_v6_request_sock_ops__ro_after_init ;static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops__ro_after_init ;static struct inet_connection_sock_af_ops subflow_v6_specific__ro_after_init ;static struct inet_connection_sock_af_ops subflow_v6m_specific__ro_after_init ;
@@ -402,7 +403,7 @@ static int subflow_v6_conn_request(strucreturn 0 ; } -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); drop:
@@ -415,7 +416,12 @@ struct request_sock *mptcp_subflow_reqsk struct sock *sk_listener, bool attach_listener) { - ops = &mptcp_subflow_request_sock_ops; +if (ops->family ==AF_INET ) + ops = &mptcp_subflow_v4_request_sock_ops; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else if (ops->family == AF_INET6) + ops = &mptcp_subflow_v6_request_sock_ops; +#endif return inet_reqsk_alloc (ops, sk_listener, attach_listener); }
@@ -1386,7 +1392,6 @@ static struct tcp_ulp_ops subflow_ulp_opstatic int subflow_ops_init (struct request_sock_ops *subflow_ops) { subflow_ops->obj_size =sizeof (struct mptcp_subflow_request_sock ); - subflow_ops->slab_name ="request_sock_subflow" ; subflow_ops->slab = kmem_cache_create(subflow_ops->slab_name, subflow_ops->obj_size, 0,
@@ -1403,9 +1408,10 @@ static int subflow_ops_init(struct requevoid __init mptcp_subflow_init (void ) { - mptcp_subflow_request_sock_ops = tcp_request_sock_ops; -if (subflow_ops_init (&mptcp_subflow_request_sock_ops) !=0 ) -panic ("MPTCP: failed to init subflow request sock ops\n" ); + mptcp_subflow_v4_request_sock_ops = tcp_request_sock_ops; + mptcp_subflow_v4_request_sock_ops.slab_name ="request_sock_subflow_v4" ; +if (subflow_ops_init (&mptcp_subflow_v4_request_sock_ops) !=0 ) +panic ("MPTCP: failed to init subflow v4 request sock ops\n" ); subflow_request_sock_ipv4_ops = tcp_request_sock_ipv4_ops; subflow_request_sock_ipv4_ops.init_req = subflow_v4_init_req;
@@ -1416,6 +1422,18 @@ void __init mptcp_subflow_init(void) subflow_specific.sk_rx_dst_set = subflow_finish_connect;#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 ) !=sizeof (struct tcp6_request_sock )); + + mptcp_subflow_v6_request_sock_ops = tcp6_request_sock_ops; + mptcp_subflow_v6_request_sock_ops.slab_name ="request_sock_subflow_v6" ; +if (subflow_ops_init (&mptcp_subflow_v6_request_sock_ops) !=0 ) +panic ("MPTCP: failed to init subflow v6 request sock ops\n" ); + subflow_request_sock_ipv6_ops = tcp_request_sock_ipv6_ops; subflow_request_sock_ipv6_ops.init_req = subflow_v6_init_req;
Patches currently in stable-queue which might be from [email protected] are
queue-5.10/mptcp-use-proper-req-destructor-for-ipv6.patch queue-5.10/mptcp-remove-mptcp-ifdef-in-tcp-syn-cookies.patch queue-5.10/mptcp-dedicated-request-sock-for-subflow-in-v6.patch queue-5.10/mptcp-mark-ops-structures-as-ro_after_init.patch
PATCH 4/4 mptcp: use proper req destructor for IPv6
In reply to Mat MartineauFrom: Matthieu Baerts <[email protected]>
commit d3295fee3c756ece33ac0d935e172e68c0a4161b upstream.
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.
--- net/mptcp/subflow.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
net/mptcp/subflow.c +16 -3
@@ -40,7 +40,6 @@ static void subflow_req_destructor(struct request_sock *req)sock_put ((struct sock *)subflow_req->msk);mptcp_token_destroy_request (req); - tcp_request_sock_ops.destructor (req); } static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
@@ -380,6 +379,12 @@ static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb)return 0 ; } +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_after_init ;static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops__ro_after_init ;
@@ -410,6 +415,12 @@ static int subflow_v6_conn_request(struct sock *sk, struct 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 struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *ops,
@@ -1401,8 +1412,6 @@ static int subflow_ops_init(struct request_sock_ops *subflow_ops)if (!subflow_ops->slab)return -ENOMEM ; - subflow_ops->destructor = subflow_req_destructor; -return 0 ; }
@@ -1410,6 +1419,8 @@ void __init mptcp_subflow_init(void) { mptcp_subflow_v4_request_sock_ops = tcp_request_sock_ops; mptcp_subflow_v4_request_sock_ops.slab_name ="request_sock_subflow_v4" ; + mptcp_subflow_v4_request_sock_ops.destructor = subflow_v4_req_destructor; +if (subflow_ops_init (&mptcp_subflow_v4_request_sock_ops) !=0 )panic ("MPTCP: failed to init subflow v4 request sock ops\n" );
@@ -1431,6 +1442,8 @@ void __init mptcp_subflow_init(void) mptcp_subflow_v6_request_sock_ops = tcp6_request_sock_ops; mptcp_subflow_v6_request_sock_ops.slab_name ="request_sock_subflow_v6" ; + mptcp_subflow_v6_request_sock_ops.destructor = subflow_v6_req_destructor; +if (subflow_ops_init (&mptcp_subflow_v6_request_sock_ops) !=0 )panic ("MPTCP: failed to init subflow v6 request sock ops\n" );
Signature · 1 line
2.39.0
Patch "mptcp: use proper req destructor for IPv6" has been added to the 5.10-stable tree
This is a note to let you know that I've just added the patch titled
mptcp: use proper req destructor for IPv6
to the 5.10-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mptcp-use-proper-req-destructor-for-ipv6.patch
and it can be found in the queue-5.10 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Sat Jan 7 02:46:50 2023
From: Mat Martineau <[email protected]>
Date: Fri, 6 Jan 2023 17:46:31 -0800
Subject: mptcp: use proper req destructor for IPv6
To: [email protected], [email protected]
Cc: Matthieu Baerts <[email protected]>, [email protected], [email protected], Mat Martineau <[email protected]>, Jakub Kicinski <[email protected]>
Message-ID: <[email protected]>
From: Mat Martineau <[email protected]>
From: Matthieu Baerts <[email protected]>
commit d3295fee3c756ece33ac0d935e172e68c0a4161b upstream.
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.
--- net/mptcp/subflow.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
net/mptcp/subflow.c +16 -3
@@ -40,7 +40,6 @@ static void subflow_req_destructor(strucsock_put ((struct sock *)subflow_req->msk);mptcp_token_destroy_request (req); - tcp_request_sock_ops.destructor (req); } static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
@@ -380,6 +379,12 @@ drop:return 0 ; } +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_after_init ;static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops__ro_after_init ;
@@ -410,6 +415,12 @@ drop: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 struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *ops,
@@ -1401,8 +1412,6 @@ static int subflow_ops_init(struct requeif (!subflow_ops->slab)return -ENOMEM ; - subflow_ops->destructor = subflow_req_destructor; -return 0 ; }
@@ -1410,6 +1419,8 @@ void __init mptcp_subflow_init(void) { mptcp_subflow_v4_request_sock_ops = tcp_request_sock_ops; mptcp_subflow_v4_request_sock_ops.slab_name ="request_sock_subflow_v4" ; + mptcp_subflow_v4_request_sock_ops.destructor = subflow_v4_req_destructor; +if (subflow_ops_init (&mptcp_subflow_v4_request_sock_ops) !=0 )panic ("MPTCP: failed to init subflow v4 request sock ops\n" );
@@ -1431,6 +1442,8 @@ void __init mptcp_subflow_init(void) mptcp_subflow_v6_request_sock_ops = tcp6_request_sock_ops; mptcp_subflow_v6_request_sock_ops.slab_name ="request_sock_subflow_v6" ; + mptcp_subflow_v6_request_sock_ops.destructor = subflow_v6_req_destructor; +if (subflow_ops_init (&mptcp_subflow_v6_request_sock_ops) !=0 )panic ("MPTCP: failed to init subflow v6 request sock ops\n" );
Patches currently in stable-queue which might be from [email protected] are
queue-5.10/mptcp-use-proper-req-destructor-for-ipv6.patch queue-5.10/mptcp-remove-mptcp-ifdef-in-tcp-syn-cookies.patch queue-5.10/mptcp-dedicated-request-sock-for-subflow-in-v6.patch queue-5.10/mptcp-mark-ops-structures-as-ro_after_init.patch
Greg KH
maintainerQuoted 5 lines · Mat Martineau
Greg -
Here are backports of the MPTCP patches, and one prerequisite, that recently failed to apply to the 5.10 stable tree. They prevent IPv6 memory leaks with MPTCP.
All now queued up, thanks.
greg k-h