From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A718EB64DD for ; Tue, 1 Aug 2023 09:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233132AbjHAJff (ORCPT ); Tue, 1 Aug 2023 05:35:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233135AbjHAJfS (ORCPT ); Tue, 1 Aug 2023 05:35:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5C2C19BD for ; Tue, 1 Aug 2023 02:33:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 81FC5614CF for ; Tue, 1 Aug 2023 09:33:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 928C7C433C7; Tue, 1 Aug 2023 09:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1690882379; bh=D8XI6PrJbOi9BlFFCH18YSxQrLwSBKH9W7qi8IWQ2wc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dfJeYb2ON/wCgQ66EawQK8RJkXyLM8zVGr9aM85AHTE1mo0933tazBtgxovt6pJDS O2C37bdE6KhRyfjgjHYmNIvvwh06xP1Z9koQcFzB0n4JZsJxQTfIhY3lH0CB9ZywrO iiL7SXCV1ciR3bxmSUGQZTIuYC/U+HO4uEdqRMtc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christoph Paasch , Paolo Abeni , Matthieu Baerts , "David S. Miller" , Sasha Levin Subject: [PATCH 6.1 056/228] mptcp: do not rely on implicit state check in mptcp_listen() Date: Tue, 1 Aug 2023 11:18:34 +0200 Message-ID: <20230801091924.903125011@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801091922.799813980@linuxfoundation.org> References: <20230801091922.799813980@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Paolo Abeni [ Upstream commit 0226436acf2495cde4b93e7400e5a87305c26054 ] Since the blamed commit, closing the first subflow resets the first subflow socket state to SS_UNCONNECTED. The current mptcp listen implementation relies only on such state to prevent touching not-fully-disconnected sockets. Incoming mptcp fastclose (or paired endpoint removal) unconditionally closes the first subflow. All the above allows an incoming fastclose followed by a listen() call to successfully race with a blocking recvmsg(), potentially causing the latter to hit a divide by zero bug in cleanup_rbuf/__tcp_select_window(). Address the issue explicitly checking the msk socket state in mptcp_listen(). An alternative solution would be moving the first subflow socket state update into mptcp_disconnect(), but in the long term the first subflow socket should be removed: better avoid relaying on it for internal consistency check. Fixes: b29fcfb54cd7 ("mptcp: full disconnect implementation") Cc: stable@vger.kernel.org Reported-by: Christoph Paasch Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/414 Signed-off-by: Paolo Abeni Reviewed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/mptcp/protocol.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 208da9a9909c2..37ff6766fd526 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3753,6 +3753,11 @@ static int mptcp_listen(struct socket *sock, int backlog) pr_debug("msk=%p", msk); lock_sock(sk); + + err = -EINVAL; + if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM) + goto unlock; + ssock = __mptcp_nmpc_socket(msk); if (!ssock) { err = -EINVAL; -- 2.39.2