Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1647004pxy; Mon, 2 Aug 2021 07:02:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyWweBGdDL3tvtcGvUw9YGHl/eiNScY2FVBTG0BrMu5ugYiEuVu4EpZBAxwTawf13chuZE X-Received: by 2002:aa7:dd0f:: with SMTP id i15mr19302753edv.47.1627912928887; Mon, 02 Aug 2021 07:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912928; cv=none; d=google.com; s=arc-20160816; b=pNg5Ga82EMWxYW/jGjOLhGNQh9cvW3K60ntTIx6ZhU48BIn3n+MfZ4fL3fGZ9esxtu D2gkrUiNF5lEAZnCGdddCOIc/lfeBkuTGbxsfNSIfjtYna0bDyfKz3A3DIo+LuHvwTdz TpcOOHoSEuEoEgqFnygXton9bIesqUmmpJOXCNXcVxS3A1B5edjcLriEIhpx6Nmvn8tT u5zrY5c367t9VJ7n2KwMUJ9NmueSnavDcFiThdWz3m2ucpvVyUH1OeRuzuJdt5Rog0yS dpMrZEg2v7XU+85oLCQd4OLVOEk7u+IUmCqWmmPsOCEsZJy+oyXznRUxOBWhFW4D63A+ uHoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dwey83LPEbIjLI8cs8ZWY8F5A1cGPliFsfHQi4Lo7ow=; b=RxNGidm8b6RCHMXMKpmUFCutL1ibRCPR/cCKxe02leMeAQYfplEUI0c4OP9ZcpFh0Y JUeuaeQdN/n+3TzFspmfQMQoAfIE7KadsX6c2aaqdQIf0clGYpNg9P1YS2SxzwRn53a5 oyTNB2vA1yl717xFw7mTHRqaJ1oH/Y/dbat4vrolulHdfj7jJK75wydpgf5puoO9iXQJ IxU2p2XGLYV1bUvU8HnMMy6Tex2VEYJRH36D9j+lta6OuYWBR+eWVavduNX/nEhp5Eot aKikHwDqJwoQJjGjoniF6BWUqf4ASaxcJgJiQb2k5i/7+nRHjRjYknH2qvU0pY7SBUD1 FmtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yQ4JVvUA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si9900542edr.367.2021.08.02.07.01.44; Mon, 02 Aug 2021 07:02:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yQ4JVvUA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235959AbhHBN6B (ORCPT + 99 others); Mon, 2 Aug 2021 09:58:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:33500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234639AbhHBNvk (ORCPT ); Mon, 2 Aug 2021 09:51:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 99E9E61108; Mon, 2 Aug 2021 13:51:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912276; bh=H5v5wfb2zFopAgaoROblUXmSz2SQUzUggOjBYxEAH5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yQ4JVvUAnx5ZU9G5epuTPpJhlCl5RNPOZEtOYTNAmfXclA08mEhyI1Qx8m5HhaXDs PVe1ht3qhF8RF4lJBz321h8jq7z7Ou2iclnu4DiseB74gTfyFkCjnFeeJcrRf3cDxl B2Qv7Ps08jHoa7hW0FRl2eQ4Be7daX59Qx9fDr7g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jon Maloy , Hoang Le , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 26/40] tipc: fix sleeping in tipc accept routine Date: Mon, 2 Aug 2021 15:45:06 +0200 Message-Id: <20210802134336.227510777@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802134335.408294521@linuxfoundation.org> References: <20210802134335.408294521@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hoang Le [ Upstream commit d237a7f11719ff9320721be5818352e48071aab6 ] The release_sock() is blocking function, it would change the state after sleeping. In order to evaluate the stated condition outside the socket lock context, switch to use wait_woken() instead. Fixes: 6398e23cdb1d8 ("tipc: standardize accept routine") Acked-by: Jon Maloy Signed-off-by: Hoang Le Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/tipc/socket.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index cdade990fe44..a5922ce9109c 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -2501,7 +2501,7 @@ static int tipc_listen(struct socket *sock, int len) static int tipc_wait_for_accept(struct socket *sock, long timeo) { struct sock *sk = sock->sk; - DEFINE_WAIT(wait); + DEFINE_WAIT_FUNC(wait, woken_wake_function); int err; /* True wake-one mechanism for incoming connections: only @@ -2510,12 +2510,12 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo) * anymore, the common case will execute the loop only once. */ for (;;) { - prepare_to_wait_exclusive(sk_sleep(sk), &wait, - TASK_INTERRUPTIBLE); if (timeo && skb_queue_empty(&sk->sk_receive_queue)) { + add_wait_queue(sk_sleep(sk), &wait); release_sock(sk); - timeo = schedule_timeout(timeo); + timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, timeo); lock_sock(sk); + remove_wait_queue(sk_sleep(sk), &wait); } err = 0; if (!skb_queue_empty(&sk->sk_receive_queue)) @@ -2527,7 +2527,6 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo) if (signal_pending(current)) break; } - finish_wait(sk_sleep(sk), &wait); return err; } -- 2.30.2