Skip to content

Commit 6787b7e

Browse files
Jianguo Wudavem330
authored andcommitted
mptcp: avoid processing packet if a subflow reset
If check_fully_established() causes a subflow reset, it should not continue to process the packet in tcp_data_queue(). Add a return value to mptcp_incoming_options(), and return false if a subflow has been reset, else return true. Then drop the packet in tcp_data_queue()/tcp_rcv_state_process() if mptcp_incoming_options() return false. Fixes: d582484 ("mptcp: fix fallback for MP_JOIN subflows") Signed-off-by: Jianguo Wu <wujianguo@chinatelecom.cn> Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8547ea5 commit 6787b7e

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

include/net/mptcp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
105105
bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
106106
unsigned int *size, unsigned int remaining,
107107
struct mptcp_out_options *opts);
108-
void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
108+
bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
109109

110110
void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
111111
struct mptcp_out_options *opts);
@@ -227,9 +227,10 @@ static inline bool mptcp_established_options(struct sock *sk,
227227
return false;
228228
}
229229

230-
static inline void mptcp_incoming_options(struct sock *sk,
230+
static inline bool mptcp_incoming_options(struct sock *sk,
231231
struct sk_buff *skb)
232232
{
233+
return true;
233234
}
234235

235236
static inline void mptcp_skb_ext_move(struct sk_buff *to,

net/ipv4/tcp_input.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,6 +4247,9 @@ void tcp_reset(struct sock *sk, struct sk_buff *skb)
42474247
{
42484248
trace_tcp_receive_reset(sk);
42494249

4250+
/* mptcp can't tell us to ignore reset pkts,
4251+
* so just ignore the return value of mptcp_incoming_options().
4252+
*/
42504253
if (sk_is_mptcp(sk))
42514254
mptcp_incoming_options(sk, skb);
42524255

@@ -4941,8 +4944,13 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
49414944
bool fragstolen;
49424945
int eaten;
49434946

4944-
if (sk_is_mptcp(sk))
4945-
mptcp_incoming_options(sk, skb);
4947+
/* If a subflow has been reset, the packet should not continue
4948+
* to be processed, drop the packet.
4949+
*/
4950+
if (sk_is_mptcp(sk) && !mptcp_incoming_options(sk, skb)) {
4951+
__kfree_skb(skb);
4952+
return;
4953+
}
49464954

49474955
if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
49484956
__kfree_skb(skb);
@@ -6523,8 +6531,11 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
65236531
case TCP_CLOSING:
65246532
case TCP_LAST_ACK:
65256533
if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) {
6526-
if (sk_is_mptcp(sk))
6527-
mptcp_incoming_options(sk, skb);
6534+
/* If a subflow has been reset, the packet should not
6535+
* continue to be processed, drop the packet.
6536+
*/
6537+
if (sk_is_mptcp(sk) && !mptcp_incoming_options(sk, skb))
6538+
goto discard;
65286539
break;
65296540
}
65306541
fallthrough;

net/mptcp/options.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,8 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,
10351035
return hmac == mp_opt->ahmac;
10361036
}
10371037

1038-
void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
1038+
/* Return false if a subflow has been reset, else return true */
1039+
bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
10391040
{
10401041
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
10411042
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
@@ -1053,12 +1054,16 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
10531054
__mptcp_check_push(subflow->conn, sk);
10541055
__mptcp_data_acked(subflow->conn);
10551056
mptcp_data_unlock(subflow->conn);
1056-
return;
1057+
return true;
10571058
}
10581059

10591060
mptcp_get_options(sk, skb, &mp_opt);
1061+
1062+
/* The subflow can be in close state only if check_fully_established()
1063+
* just sent a reset. If so, tell the caller to ignore the current packet.
1064+
*/
10601065
if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
1061-
return;
1066+
return sk->sk_state != TCP_CLOSE;
10621067

10631068
if (mp_opt.fastclose &&
10641069
msk->local_key == mp_opt.rcvr_key) {
@@ -1100,7 +1105,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
11001105
}
11011106

11021107
if (!mp_opt.dss)
1103-
return;
1108+
return true;
11041109

11051110
/* we can't wait for recvmsg() to update the ack_seq, otherwise
11061111
* monodirectional flows will stuck
@@ -1119,12 +1124,12 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
11191124
schedule_work(&msk->work))
11201125
sock_hold(subflow->conn);
11211126

1122-
return;
1127+
return true;
11231128
}
11241129

11251130
mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
11261131
if (!mpext)
1127-
return;
1132+
return true;
11281133

11291134
memset(mpext, 0, sizeof(*mpext));
11301135

@@ -1153,6 +1158,8 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
11531158
if (mpext->csum_reqd)
11541159
mpext->csum = mp_opt.csum;
11551160
}
1161+
1162+
return true;
11561163
}
11571164

11581165
static void mptcp_set_rwin(const struct tcp_sock *tp)

0 commit comments

Comments
 (0)