@@ -820,9 +820,12 @@ static struct ipv6_pinfo *mptcp_inet6_sk(const struct sock *sk)
820820}
821821#endif
822822
823- static struct sock * mptcp_sk_clone_lock (const struct sock * sk )
823+ struct sock * mptcp_sk_clone (const struct sock * sk , struct request_sock * req )
824824{
825+ struct mptcp_subflow_request_sock * subflow_req = mptcp_subflow_rsk (req );
825826 struct sock * nsk = sk_clone_lock (sk , GFP_ATOMIC );
827+ struct mptcp_sock * msk ;
828+ u64 ack_seq ;
826829
827830 if (!nsk )
828831 return NULL ;
@@ -832,6 +835,36 @@ static struct sock *mptcp_sk_clone_lock(const struct sock *sk)
832835 inet_sk (nsk )-> pinet6 = mptcp_inet6_sk (nsk );
833836#endif
834837
838+ __mptcp_init_sock (nsk );
839+
840+ msk = mptcp_sk (nsk );
841+ msk -> local_key = subflow_req -> local_key ;
842+ msk -> token = subflow_req -> token ;
843+ msk -> subflow = NULL ;
844+
845+ if (unlikely (mptcp_token_new_accept (subflow_req -> token , nsk ))) {
846+ bh_unlock_sock (nsk );
847+
848+ /* we can't call into mptcp_close() here - possible BH context
849+ * free the sock directly
850+ */
851+ nsk -> sk_prot -> destroy (nsk );
852+ sk_free (nsk );
853+ return NULL ;
854+ }
855+
856+ msk -> write_seq = subflow_req -> idsn + 1 ;
857+ if (subflow_req -> remote_key_valid ) {
858+ msk -> can_ack = true;
859+ msk -> remote_key = subflow_req -> remote_key ;
860+ mptcp_crypto_key_sha (msk -> remote_key , NULL , & ack_seq );
861+ ack_seq ++ ;
862+ msk -> ack_seq = ack_seq ;
863+ }
864+ bh_unlock_sock (nsk );
865+
866+ /* keep a single reference */
867+ __sock_put (nsk );
835868 return nsk ;
836869}
837870
@@ -859,40 +892,26 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
859892 struct mptcp_subflow_context * subflow ;
860893 struct sock * new_mptcp_sock ;
861894 struct sock * ssk = newsk ;
862- u64 ack_seq ;
863895
864896 subflow = mptcp_subflow_ctx (newsk );
865- lock_sock ( sk ) ;
897+ new_mptcp_sock = subflow -> conn ;
866898
867- local_bh_disable ();
868- new_mptcp_sock = mptcp_sk_clone_lock (sk );
869- if (!new_mptcp_sock ) {
870- * err = - ENOBUFS ;
871- local_bh_enable ();
872- release_sock (sk );
873- mptcp_subflow_shutdown (newsk , SHUT_RDWR + 1 , 0 , 0 );
874- tcp_close (newsk , 0 );
875- return NULL ;
899+ /* is_mptcp should be false if subflow->conn is missing, see
900+ * subflow_syn_recv_sock()
901+ */
902+ if (WARN_ON_ONCE (!new_mptcp_sock )) {
903+ tcp_sk (newsk )-> is_mptcp = 0 ;
904+ return newsk ;
876905 }
877906
878- __mptcp_init_sock (new_mptcp_sock );
907+ /* acquire the 2nd reference for the owning socket */
908+ sock_hold (new_mptcp_sock );
879909
910+ local_bh_disable ();
911+ bh_lock_sock (new_mptcp_sock );
880912 msk = mptcp_sk (new_mptcp_sock );
881- msk -> local_key = subflow -> local_key ;
882- msk -> token = subflow -> token ;
883- msk -> subflow = NULL ;
884913 msk -> first = newsk ;
885914
886- mptcp_token_update_accept (newsk , new_mptcp_sock );
887-
888- msk -> write_seq = subflow -> idsn + 1 ;
889- if (subflow -> can_ack ) {
890- msk -> can_ack = true;
891- msk -> remote_key = subflow -> remote_key ;
892- mptcp_crypto_key_sha (msk -> remote_key , NULL , & ack_seq );
893- ack_seq ++ ;
894- msk -> ack_seq = ack_seq ;
895- }
896915 newsk = new_mptcp_sock ;
897916 mptcp_copy_inaddrs (newsk , ssk );
898917 list_add (& subflow -> node , & msk -> conn_list );
@@ -903,18 +922,6 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
903922 inet_sk_state_store (new_mptcp_sock , TCP_SYN_RECV );
904923 bh_unlock_sock (new_mptcp_sock );
905924 local_bh_enable ();
906- release_sock (sk );
907-
908- /* the subflow can already receive packet, avoid racing with
909- * the receive path and process the pending ones
910- */
911- lock_sock (ssk );
912- subflow -> rel_write_seq = 1 ;
913- subflow -> tcp_sock = ssk ;
914- subflow -> conn = new_mptcp_sock ;
915- if (unlikely (!skb_queue_empty (& ssk -> sk_receive_queue )))
916- mptcp_subflow_data_available (ssk );
917- release_sock (ssk );
918925 }
919926
920927 return newsk ;
0 commit comments