@@ -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 )
@@ -438,22 +431,25 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
438
431
struct mptcp_subflow_context * listener = mptcp_subflow_ctx (sk );
439
432
struct mptcp_subflow_request_sock * subflow_req ;
440
433
struct mptcp_options_received mp_opt ;
441
- bool fallback_is_fatal = false ;
434
+ bool fallback , fallback_is_fatal ;
442
435
struct sock * new_msk = NULL ;
443
- bool fallback = false;
444
436
struct sock * child ;
445
437
446
438
pr_debug ("listener=%p, req=%p, conn=%p" , listener , req , listener -> conn );
447
439
448
- /* we need later a valid 'mp_capable' value even when options are not
449
- * parsed
440
+ /* After child creation we must look for 'mp_capable' even when options
441
+ * are not parsed
450
442
*/
451
443
mp_opt .mp_capable = 0 ;
452
- if (tcp_rsk (req )-> is_mptcp == 0 )
444
+
445
+ /* hopefully temporary handling for MP_JOIN+syncookie */
446
+ subflow_req = mptcp_subflow_rsk (req );
447
+ fallback_is_fatal = subflow_req -> mp_join ;
448
+ fallback = !tcp_rsk (req )-> is_mptcp ;
449
+ if (fallback )
453
450
goto create_child ;
454
451
455
452
/* if the sk is MP_CAPABLE, we try to fetch the client key */
456
- subflow_req = mptcp_subflow_rsk (req );
457
453
if (subflow_req -> mp_capable ) {
458
454
if (TCP_SKB_CB (skb )-> seq != subflow_req -> ssn_offset + 1 ) {
459
455
/* here we can receive and accept an in-window,
@@ -474,12 +470,11 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
474
470
if (!new_msk )
475
471
fallback = true;
476
472
} else if (subflow_req -> mp_join ) {
477
- fallback_is_fatal = true;
478
473
mptcp_get_options (skb , & mp_opt );
479
474
if (!mp_opt .mp_join ||
480
475
!subflow_hmac_valid (req , & mp_opt )) {
481
476
SUBFLOW_REQ_INC_STATS (req , MPTCP_MIB_JOINACKMAC );
482
- return NULL ;
477
+ fallback = true ;
483
478
}
484
479
}
485
480
@@ -522,10 +517,12 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
522
517
} else if (ctx -> mp_join ) {
523
518
struct mptcp_sock * owner ;
524
519
525
- owner = mptcp_token_get_sock ( ctx -> token ) ;
520
+ owner = subflow_req -> msk ;
526
521
if (!owner )
527
522
goto dispose_child ;
528
523
524
+ /* move the msk reference ownership to the subflow */
525
+ subflow_req -> msk = NULL ;
529
526
ctx -> conn = (struct sock * )owner ;
530
527
if (!mptcp_finish_join (child ))
531
528
goto dispose_child ;
0 commit comments