From nobody Thu Sep 18 08:14:30 2025 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a17:907:7811:b0:6d8:2910:9a8 with SMTP id la17csp297532ejc; Wed, 15 Jun 2022 02:17:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrfve2GEJE2LowiIOF+n3r98XamNgweoDUQTcmDHfky/93VRmvfUn3xQ5KGTp16IrzsQTY X-Received: by 2002:a63:1359:0:b0:3fd:a384:d69c with SMTP id 25-20020a631359000000b003fda384d69cmr7941264pgt.289.1655284633051; Wed, 15 Jun 2022 02:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655284633; cv=none; d=google.com; s=arc-20160816; b=Qqh9YQ+dzKr1f/Q3JWoDCUlTifhsx1dZ7n3UVzr4DN5hhvrHaPQm5AL05PKb+8Ebzn dhJTUYNO9kAkDkjaM3Sgq8Jyrj6KZkD1fWibVknsW5BQ1K1xJiZ7of8TuRFVZP+O/A1X FoQK+VcDgAsZRqEpN+YSB3/11xtrJYN9SdUGo7wRHCmzNaKj8bueJgyRTLBlgBpSVeDb h0qJtmIlgdap4G46vvMPwtyhOTJXVZDjG/ACCMzJeblbG+In8B8RoobQujopwcm8TQDh llQB4s3SwQaO4Yl/m3FmcelwHYiz7Jz2Gi8EPk6VoelPvvLKizX+NhDYB0k8B8jvIJeQ veow== 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=69vsEmHqxmCClUDYO0nhCF/yZYhk33vQMIF1L1ed2Uc=; b=wFTGuNPfV8FvGZuOtVOXyYe1rHobxtpsEXUmvCwVG0Sk+OgrW5zqWthlE59etr5WTv ZjeKCO0asVTvov8/peOC5hl0beMYQlE2guBmgLf834pXyXbWaF77nuMwNqNQa1Elaibg mFVvfea1WVnuA2KLspLs/TqlV9RzbyUj2T3E6gJTLFI726b35Tyt+ttJHul0JSMQFfQT uFoEXkr1n/D3Dld0fsb/ObrnXWGjmsIPhH9H9oGxXYnaOAW/D3vRihnU8HbhnhmWYG/5 a8M4yzlVs3Ud2ZI7ZnJKyOq7HR+lVgIhuyrHy885owcqSFQX5zao1toHtHHTsCXRtmSh gbsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RMEzQlrL; spf=pass (google.com: domain of mptcp+bounces-5653-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 139.178.88.99 as permitted sender) smtp.mailfrom="mptcp+bounces-5653-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s3-20020a056a00178300b0050d5b4ee692si18104069pfg.106.2022.06.15.02.17.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jun 2022 02:17:13 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-5653-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RMEzQlrL; spf=pass (google.com: domain of mptcp+bounces-5653-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 139.178.88.99 as permitted sender) smtp.mailfrom="mptcp+bounces-5653-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 30ECC280A98 for ; Wed, 15 Jun 2022 09:17:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8AA797A; Wed, 15 Jun 2022 09:17:09 +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.133.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 24B8023BD for ; Wed, 15 Jun 2022 09:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655284627; 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=69vsEmHqxmCClUDYO0nhCF/yZYhk33vQMIF1L1ed2Uc=; b=RMEzQlrLloZouJc9GjcgrZ1Ys6fzovlQwIB1sUE6jjY6PgP7ZR+c0c8gOj0xUzV0geXxsd BxDtOiieNBvS+3GU6j+IoXpCoRcMRLp7tfWHpvRskKQJJJcPBLRr5O+l46Xm6AVWK0wYOO mWCRfqGSLMYcz2Phi+zHYnpGyhwtYnA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-90-XmP7Kle8PlSrODLYodnprw-1; Wed, 15 Jun 2022 05:17:05 -0400 X-MC-Unique: XmP7Kle8PlSrODLYodnprw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A59123831C4A for ; Wed, 15 Jun 2022 09:17:05 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.193.220]) by smtp.corp.redhat.com (Postfix) with ESMTP id 350F2C2811A for ; Wed, 15 Jun 2022 09:17:05 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-net 4/5] mptcp: fix shutdown vs fallback race Date: Wed, 15 Jun 2022 11:16:15 +0200 Message-Id: <4fe795f3e0e7c87c2df1a8839f2a3c1d07a11e34.1655283387.git.pabeni@redhat.com> 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.85 on 10.11.54.8 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 2910105a99b0..3a781f6f5709 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 1d2d71711872..9860179bfd5e 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -927,12 +927,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 040901c1f40c..75fdc6474d0e 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1273,7 +1273,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