Skip to content

Commit e5bcf0e

Browse files
committed
Merge branch 'mptcp-a-bunch-of-fixes'
Paolo Abeni says: ==================== mptcp: a bunch of fixes This series bundle a few MPTCP fixes for the current net tree. They have been detected via syzkaller and packetdrill Patch 1 fixes a slow close for orphaned sockets Patch 2 fixes another hangup at close time, when no data was actually transmitted before close Patch 3 fixes a memory leak with unusual sockopts Patch 4 fixes stray wake-ups on listener sockets ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 94ead4c + 52557db commit e5bcf0e

File tree

3 files changed

+77
-16
lines changed

3 files changed

+77
-16
lines changed

net/mptcp/options.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ static void clear_3rdack_retransmission(struct sock *sk)
411411
}
412412

413413
static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
414+
bool snd_data_fin_enable,
414415
unsigned int *size,
415416
unsigned int remaining,
416417
struct mptcp_out_options *opts)
@@ -428,9 +429,10 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
428429
if (!skb)
429430
return false;
430431

431-
/* MPC/MPJ needed only on 3rd ack packet */
432-
if (subflow->fully_established ||
433-
subflow->snd_isn != TCP_SKB_CB(skb)->seq)
432+
/* MPC/MPJ needed only on 3rd ack packet, DATA_FIN and TCP shutdown take precedence */
433+
if (subflow->fully_established || snd_data_fin_enable ||
434+
subflow->snd_isn != TCP_SKB_CB(skb)->seq ||
435+
sk->sk_state != TCP_ESTABLISHED)
434436
return false;
435437

436438
if (subflow->mp_capable) {
@@ -502,20 +504,20 @@ static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow,
502504
}
503505

504506
static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
507+
bool snd_data_fin_enable,
505508
unsigned int *size,
506509
unsigned int remaining,
507510
struct mptcp_out_options *opts)
508511
{
509512
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
510513
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
511-
u64 snd_data_fin_enable, ack_seq;
512514
unsigned int dss_size = 0;
513515
struct mptcp_ext *mpext;
514516
unsigned int ack_size;
515517
bool ret = false;
518+
u64 ack_seq;
516519

517520
mpext = skb ? mptcp_get_ext(skb) : NULL;
518-
snd_data_fin_enable = mptcp_data_fin_enabled(msk);
519521

520522
if (!skb || (mpext && mpext->use_map) || snd_data_fin_enable) {
521523
unsigned int map_size;
@@ -717,12 +719,15 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
717719
unsigned int *size, unsigned int remaining,
718720
struct mptcp_out_options *opts)
719721
{
722+
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
723+
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
720724
unsigned int opt_size = 0;
725+
bool snd_data_fin;
721726
bool ret = false;
722727

723728
opts->suboptions = 0;
724729

725-
if (unlikely(mptcp_check_fallback(sk)))
730+
if (unlikely(__mptcp_check_fallback(msk)))
726731
return false;
727732

728733
/* prevent adding of any MPTCP related options on reset packet
@@ -731,10 +736,10 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
731736
if (unlikely(skb && TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST))
732737
return false;
733738

734-
if (mptcp_established_options_mp(sk, skb, &opt_size, remaining, opts))
739+
snd_data_fin = mptcp_data_fin_enabled(msk);
740+
if (mptcp_established_options_mp(sk, skb, snd_data_fin, &opt_size, remaining, opts))
735741
ret = true;
736-
else if (mptcp_established_options_dss(sk, skb, &opt_size, remaining,
737-
opts))
742+
else if (mptcp_established_options_dss(sk, skb, snd_data_fin, &opt_size, remaining, opts))
738743
ret = true;
739744

740745
/* we reserved enough space for the above options, and exceeding the

net/mptcp/protocol.c

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/netdevice.h>
1212
#include <linux/sched/signal.h>
1313
#include <linux/atomic.h>
14+
#include <linux/igmp.h>
1415
#include <net/sock.h>
1516
#include <net/inet_common.h>
1617
#include <net/inet_hashtables.h>
@@ -19,6 +20,7 @@
1920
#include <net/tcp_states.h>
2021
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
2122
#include <net/transp_v6.h>
23+
#include <net/addrconf.h>
2224
#endif
2325
#include <net/mptcp.h>
2426
#include <net/xfrm.h>
@@ -2264,13 +2266,12 @@ static void mptcp_worker(struct work_struct *work)
22642266
__mptcp_check_send_data_fin(sk);
22652267
mptcp_check_data_fin(sk);
22662268

2267-
/* if the msk data is completely acked, or the socket timedout,
2268-
* there is no point in keeping around an orphaned sk
2269+
/* There is no point in keeping around an orphaned sk timedout or
2270+
* closed, but we need the msk around to reply to incoming DATA_FIN,
2271+
* even if it is orphaned and in FIN_WAIT2 state
22692272
*/
22702273
if (sock_flag(sk, SOCK_DEAD) &&
2271-
(mptcp_check_close_timeout(sk) ||
2272-
(state != sk->sk_state &&
2273-
((1 << inet_sk_state_load(sk)) & (TCPF_CLOSE | TCPF_FIN_WAIT2))))) {
2274+
(mptcp_check_close_timeout(sk) || sk->sk_state == TCP_CLOSE)) {
22742275
inet_sk_state_store(sk, TCP_CLOSE);
22752276
__mptcp_destroy_sock(sk);
22762277
goto unlock;
@@ -3375,10 +3376,34 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
33753376
return mask;
33763377
}
33773378

3379+
static int mptcp_release(struct socket *sock)
3380+
{
3381+
struct mptcp_subflow_context *subflow;
3382+
struct sock *sk = sock->sk;
3383+
struct mptcp_sock *msk;
3384+
3385+
if (!sk)
3386+
return 0;
3387+
3388+
lock_sock(sk);
3389+
3390+
msk = mptcp_sk(sk);
3391+
3392+
mptcp_for_each_subflow(msk, subflow) {
3393+
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
3394+
3395+
ip_mc_drop_socket(ssk);
3396+
}
3397+
3398+
release_sock(sk);
3399+
3400+
return inet_release(sock);
3401+
}
3402+
33783403
static const struct proto_ops mptcp_stream_ops = {
33793404
.family = PF_INET,
33803405
.owner = THIS_MODULE,
3381-
.release = inet_release,
3406+
.release = mptcp_release,
33823407
.bind = mptcp_bind,
33833408
.connect = mptcp_stream_connect,
33843409
.socketpair = sock_no_socketpair,
@@ -3470,10 +3495,35 @@ void __init mptcp_proto_init(void)
34703495
}
34713496

34723497
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
3498+
static int mptcp6_release(struct socket *sock)
3499+
{
3500+
struct mptcp_subflow_context *subflow;
3501+
struct mptcp_sock *msk;
3502+
struct sock *sk = sock->sk;
3503+
3504+
if (!sk)
3505+
return 0;
3506+
3507+
lock_sock(sk);
3508+
3509+
msk = mptcp_sk(sk);
3510+
3511+
mptcp_for_each_subflow(msk, subflow) {
3512+
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
3513+
3514+
ip_mc_drop_socket(ssk);
3515+
ipv6_sock_mc_close(ssk);
3516+
ipv6_sock_ac_close(ssk);
3517+
}
3518+
3519+
release_sock(sk);
3520+
return inet6_release(sock);
3521+
}
3522+
34733523
static const struct proto_ops mptcp_v6_stream_ops = {
34743524
.family = PF_INET6,
34753525
.owner = THIS_MODULE,
3476-
.release = inet6_release,
3526+
.release = mptcp6_release,
34773527
.bind = mptcp_bind,
34783528
.connect = mptcp_stream_connect,
34793529
.socketpair = sock_no_socketpair,

net/mptcp/subflow.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,12 @@ static void subflow_data_ready(struct sock *sk)
10961096

10971097
msk = mptcp_sk(parent);
10981098
if (state & TCPF_LISTEN) {
1099+
/* MPJ subflow are removed from accept queue before reaching here,
1100+
* avoid stray wakeups
1101+
*/
1102+
if (reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue))
1103+
return;
1104+
10991105
set_bit(MPTCP_DATA_READY, &msk->flags);
11001106
parent->sk_data_ready(parent);
11011107
return;

0 commit comments

Comments
 (0)