@@ -69,6 +69,9 @@ static void subflow_req_destructor(struct request_sock *req)
69
69
70
70
pr_debug ("subflow_req=%p" , subflow_req );
71
71
72
+ if (subflow_req -> msk )
73
+ sock_put ((struct sock * )subflow_req -> msk );
74
+
72
75
if (subflow_req -> mp_capable )
73
76
mptcp_token_destroy_request (subflow_req -> token );
74
77
tcp_request_sock_ops .destructor (req );
@@ -86,8 +89,8 @@ static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
86
89
}
87
90
88
91
/* validate received token and create truncated hmac and nonce for SYN-ACK */
89
- static bool subflow_token_join_request (struct request_sock * req ,
90
- const struct sk_buff * skb )
92
+ static struct mptcp_sock * subflow_token_join_request (struct request_sock * req ,
93
+ const struct sk_buff * skb )
91
94
{
92
95
struct mptcp_subflow_request_sock * subflow_req = mptcp_subflow_rsk (req );
93
96
u8 hmac [SHA256_DIGEST_SIZE ];
@@ -97,13 +100,13 @@ static bool subflow_token_join_request(struct request_sock *req,
97
100
msk = mptcp_token_get_sock (subflow_req -> token );
98
101
if (!msk ) {
99
102
SUBFLOW_REQ_INC_STATS (req , MPTCP_MIB_JOINNOTOKEN );
100
- return false ;
103
+ return NULL ;
101
104
}
102
105
103
106
local_id = mptcp_pm_get_local_id (msk , (struct sock_common * )req );
104
107
if (local_id < 0 ) {
105
108
sock_put ((struct sock * )msk );
106
- return false ;
109
+ return NULL ;
107
110
}
108
111
subflow_req -> local_id = local_id ;
109
112
@@ -114,9 +117,7 @@ static bool subflow_token_join_request(struct request_sock *req,
114
117
subflow_req -> remote_nonce , hmac );
115
118
116
119
subflow_req -> thmac = get_unaligned_be64 (hmac );
117
-
118
- sock_put ((struct sock * )msk );
119
- return true;
120
+ return msk ;
120
121
}
121
122
122
123
static void subflow_init_req (struct request_sock * req ,
@@ -133,6 +134,7 @@ static void subflow_init_req(struct request_sock *req,
133
134
134
135
subflow_req -> mp_capable = 0 ;
135
136
subflow_req -> mp_join = 0 ;
137
+ subflow_req -> msk = NULL ;
136
138
137
139
#ifdef CONFIG_TCP_MD5SIG
138
140
/* no MPTCP if MD5SIG is enabled on this socket or we may run out of
@@ -166,12 +168,9 @@ static void subflow_init_req(struct request_sock *req,
166
168
subflow_req -> remote_id = mp_opt .join_id ;
167
169
subflow_req -> token = mp_opt .token ;
168
170
subflow_req -> remote_nonce = mp_opt .nonce ;
169
- pr_debug ("token=%u, remote_nonce=%u" , subflow_req -> token ,
170
- subflow_req -> remote_nonce );
171
- if (!subflow_token_join_request (req , skb )) {
172
- subflow_req -> mp_join = 0 ;
173
- // @@ need to trigger RST
174
- }
171
+ subflow_req -> msk = subflow_token_join_request (req , skb );
172
+ pr_debug ("token=%u, remote_nonce=%u msk=%p" , subflow_req -> token ,
173
+ subflow_req -> remote_nonce , subflow_req -> msk );
175
174
}
176
175
}
177
176
@@ -354,23 +353,17 @@ static bool subflow_hmac_valid(const struct request_sock *req,
354
353
const struct mptcp_subflow_request_sock * subflow_req ;
355
354
u8 hmac [SHA256_DIGEST_SIZE ];
356
355
struct mptcp_sock * msk ;
357
- bool ret ;
358
356
359
357
subflow_req = mptcp_subflow_rsk (req );
360
- msk = mptcp_token_get_sock ( subflow_req -> token ) ;
358
+ msk = subflow_req -> msk ;
361
359
if (!msk )
362
360
return false;
363
361
364
362
subflow_generate_hmac (msk -> remote_key , msk -> local_key ,
365
363
subflow_req -> remote_nonce ,
366
364
subflow_req -> local_nonce , hmac );
367
365
368
- ret = true;
369
- if (crypto_memneq (hmac , mp_opt -> hmac , MPTCPOPT_HMAC_LEN ))
370
- ret = false;
371
-
372
- sock_put ((struct sock * )msk );
373
- return ret ;
366
+ return !crypto_memneq (hmac , mp_opt -> hmac , MPTCPOPT_HMAC_LEN );
374
367
}
375
368
376
369
static void mptcp_sock_destruct (struct sock * sk )
@@ -522,10 +515,12 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
522
515
} else if (ctx -> mp_join ) {
523
516
struct mptcp_sock * owner ;
524
517
525
- owner = mptcp_token_get_sock ( ctx -> token ) ;
518
+ owner = subflow_req -> msk ;
526
519
if (!owner )
527
520
goto dispose_child ;
528
521
522
+ /* move the msk reference ownership to the subflow */
523
+ subflow_req -> msk = NULL ;
529
524
ctx -> conn = (struct sock * )owner ;
530
525
if (!mptcp_finish_join (child ))
531
526
goto dispose_child ;
0 commit comments