From nobody Thu Sep 18 08:15:36 2025 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:ab0:35eb:0:0:0:0:0 with SMTP id w11csp62539uau; Fri, 17 Jun 2022 03:06:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s1zk/FO/S7t9/NUmWaBDjOTMr4ShJ6muTeyWjRVsLTuaGVVp/5RW2ly/jO48nGwL5LBbEn X-Received: by 2002:a9d:2c5:0:b0:60c:2bf9:1dbd with SMTP id 63-20020a9d02c5000000b0060c2bf91dbdmr3696030otl.254.1655460409844; Fri, 17 Jun 2022 03:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655460409; cv=none; d=google.com; s=arc-20160816; b=WY5XkxFiAevxbZ4s0BZ1ZNwFNPaZzE6hRbkYoqTesffWw6gnznrbS/MHgH3GSbcd/t w7UzwRfyH81qYcv/CWX7FwRqJWOwYG95mNASOduTmzvWgymUYyLkSyv/ErOEBQNeN2ei HUdxfZmHhFfQVjqaEVhe8LxIpXEHjh1m5M0TDP1bnTowchd6VqrMPbHZLrkT2vuzzTW0 BlnV1g7FGNo4teTXbVZ1MDqjexRe0KPJlWHjKKhKIFffgcNdzAEaH6pvVm5vt2n8RwTl pC4VCEghnL9kI7JlFwZEtiUQQMstdq/w3VwtfX2e2NXaLdu2uSkrG0KwEGhQTC0mg3B5 ozwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=xYQus3YQknyusLBNs7uB0crJL6zFcmSaszgzANWh19k=; b=l59W6C6bOkWOZZrPMCLUUOuqhqctI9ROpQ8V/FHMydC5zAM0rUqUvFm2HwbazcD7Tn 539wt02C6uKgpObasrQHmVJEmtYrOPZlKGSF6tuTZ3Vi0rWcQOFQASBFQr/mdLvNAo0H XIfuWTlp9N/veRWYyrbqnGCNaO2/tTa7nZyqQCwI75xu8Ok9HigYfb444W2Yq6uY1waP FxaQ0q4GtoDR4ULV1wqYUlD2w5joSJLNZZZyr7UAD9UE5FJi761Aor4jGHTOpBgrRnMN Cfw7ykdrcu8OmdN0/QJJ9woKwyultJU6xV2/HUuY5vgqTxl9YQBD5NrW4s3Xn4vF3GSu 55OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BJCcriSJ; spf=pass (google.com: domain of mptcp+bounces-5688-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 139.178.84.19 as permitted sender) smtp.mailfrom="mptcp+bounces-5688-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from da.mirrors.kernel.org (da.mirrors.kernel.org. [139.178.84.19]) by mx.google.com with ESMTPS id m188-20020aca58c5000000b0032e879825ecsi3473557oib.116.2022.06.17.03.06.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2022 03:06:49 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-5688-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 139.178.84.19 as permitted sender) client-ip=139.178.84.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BJCcriSJ; spf=pass (google.com: domain of mptcp+bounces-5688-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 139.178.84.19 as permitted sender) smtp.mailfrom="mptcp+bounces-5688-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by da.mirrors.kernel.org (Postfix) with ESMTPS id AB28E2E0A1C for ; Fri, 17 Jun 2022 10:06:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAA652F32; Fri, 17 Jun 2022 10:06:45 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 972F22F2F for ; Fri, 17 Jun 2022 10:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655460403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xYQus3YQknyusLBNs7uB0crJL6zFcmSaszgzANWh19k=; b=BJCcriSJY2QkSFl2HJaAVdgtecjVG8+oyxevGMFqnp0l5pHtB3ECyJiQ4f4HGTK13C9Abq z3xG924AFVm0ZbeFh7uqEBba0MvnFbnYhorHNOoWGg5njLBA0AYkpbxabJDACkzMuGRk1H nLj23snPMobUuJuJ/R7GXOGy5z/Q4yw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-139-uC00SaTBPI6BJ2KCqETvuw-1; Fri, 17 Jun 2022 06:06:42 -0400 X-MC-Unique: uC00SaTBPI6BJ2KCqETvuw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EBD03802C17 for ; Fri, 17 Jun 2022 10:06:41 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.194.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AAFE4010E4D for ; Fri, 17 Jun 2022 10:06:41 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-net v3 4/6] mptcp: fix shutdown vs fallback race Date: Fri, 17 Jun 2022 12:05:18 +0200 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pabeni@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8"; x-default="true" If the MPTCP socket shutdown happens before a fallback to TCP, and all the pending data have been already spooled, we never close the TCP connection. Address the issue explicitly checking for critical condition at fallback time. Signed-off-by: Paolo Abeni --- net/mptcp/options.c | 2 +- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 19 ++++++++++++++++--- net/mptcp/subflow.c | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 0bfa6662447c..57eab237c837 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -966,7 +966,7 @@ static bool check_fully_established(struct mptcp_sock *= msk, struct sock *ssk, goto reset; subflow->mp_capable =3D 0; pr_fallback(msk); - __mptcp_do_fallback(msk); + mptcp_do_fallback(ssk); return false; } =20 diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 725fd417ebb1..00ba9c44933a 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1245,7 +1245,7 @@ static void mptcp_update_infinite_map(struct mptcp_so= ck *msk, MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_INFINITEMAPTX); mptcp_subflow_ctx(ssk)->send_infinite_map =3D 0; pr_fallback(msk); - __mptcp_do_fallback(msk); + mptcp_do_fallback(ssk); } =20 static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 077a717799a0..ad9b02b1b3e6 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -941,12 +941,25 @@ static inline void __mptcp_do_fallback(struct mptcp_s= ock *msk) set_bit(MPTCP_FALLBACK_DONE, &msk->flags); } =20 -static inline void mptcp_do_fallback(struct sock *sk) +static inline void mptcp_do_fallback(struct sock *ssk) { - struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(sk); - struct mptcp_sock *msk =3D mptcp_sk(subflow->conn); + struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); + struct sock *sk =3D subflow->conn; + struct mptcp_sock *msk; =20 + msk =3D mptcp_sk(sk); __mptcp_do_fallback(msk); + if (READ_ONCE(msk->snd_data_fin_enable) && !(ssk->sk_shutdown & SEND_SHUT= DOWN)) { + gfp_t saved_allocation =3D ssk->sk_allocation; + + /* we are in a atomic (BH) scope, override ssk default for data + * fin allocation + */ + ssk->sk_allocation =3D GFP_ATOMIC; + ssk->sk_shutdown |=3D SEND_SHUTDOWN; + tcp_shutdown(ssk, SEND_SHUTDOWN); + ssk->sk_allocation =3D saved_allocation; + } } =20 #define pr_fallback(a) pr_debug("%s:fallback to TCP (msk=3D%p)", __func__,= a) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index c82a9a6e0267..b157e275315e 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1279,7 +1279,7 @@ static bool subflow_check_data_avail(struct sock *ssk) return false; } =20 - __mptcp_do_fallback(msk); + mptcp_do_fallback(ssk); } =20 skb =3D skb_peek(&ssk->sk_receive_queue); --=20 2.35.3