Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1640567pxy; Mon, 2 Aug 2021 06:53:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoQ3XJEnP2rSTP47yvWWT62ngZ80NGobsyhmSdKOnSli/08RLzmycl1ag3XO2XyS0Vu2PG X-Received: by 2002:a05:6638:39c2:: with SMTP id o2mr14604271jav.87.1627912394990; Mon, 02 Aug 2021 06:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912394; cv=none; d=google.com; s=arc-20160816; b=Gaj+QnRvvcSKfRlIJtc5tX/nUOML1aUgC4eTVXTkhN3DK30RvYFMAd5AimPvbpGoWF xUI12FaG8M8rpmzTeXcPRnT+vEZ3e6u3RZCN7hBC0fKUWdrXKhy6PXf6yW8+qWJQE9bo EsKuIlf6CcAF2OXnNR01hZspYBemKhYlNnsfPcKOECRYkBVJq/p44FkiFhFuyG6CR6bG GPDJQ8skoXPxdItvKtTvj5KeMoCU8JEquwSzJVd20Zu9P8Sa14l2KIZB1kmUAsD1Jm6e Fy6TkT8W5wEEnnRRBAd9LQUilcNOn4M4A95YkgJs+stNYU+L0VKz7xppFYV3glQSaLeW sg1w== 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=kF0HgtPW/1KRmFKpmhf5oRIwObcVedS8P+HXHu6XNQc=; b=hpfiCH8nenEMXEHl2y60Qg4SNwoz8pVOJ86mtfOpXG8DZG8ZJLl0i2PCZLqRSceNfr chiMOYyCJ2gNo2R2pBDkPQl03c6FR4u/+u6wRFEqiJcZ7m+dmtIR9T372+BzILgnBi2N ZIRlhEwNc7WmXa2mgiHof5lYqQ6WK7WMA3oBc+ZeyMS5QhaMDza3/rUXHA1Yr2LC7bNo NQ3yPxfMLUrtu7cS+QNIuvnTT8LzNXCp4Yatpl3m1+xQ8XZkLlLIRKe3T4OVmt6l1t7n oogLBpOe4Qw9OuaWKip75UiYKMKDYGmJpGHi677JX8El5qmzfq4S3+nQQ7g8mE2wE1uk 0xjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zLD0kAqn; 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 i186si13207336ioa.76.2021.08.02.06.53.03; Mon, 02 Aug 2021 06:53:14 -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=zLD0kAqn; 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 S235128AbhHBNvc (ORCPT + 99 others); Mon, 2 Aug 2021 09:51:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:57788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234211AbhHBNrr (ORCPT ); Mon, 2 Aug 2021 09:47:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F249461103; Mon, 2 Aug 2021 13:47:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912054; bh=wnslEh+/CqGL10fP+rL+33qA8HgDQectD4DqqV+0yHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zLD0kAqniWfW3DGo7yPoWmOxGh0lK3F6Ag7CavoYlPE872ArzoeBQEQqmCLwZsiyp mmoi63XutUBrxftlhNIZD2AEhrtwqdDoAxfgWXR/CQkiPoYIOkqJg6jnMiyH6JBMTv cL/l5wrvToC80rVJq0SEDBWp+uqHasElOuDJkDcs= 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 4.9 27/32] tipc: fix sleeping in tipc accept routine Date: Mon, 2 Aug 2021 15:44:47 +0200 Message-Id: <20210802134333.778879018@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802134332.931915241@linuxfoundation.org> References: <20210802134332.931915241@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 c1b9074f3325..607785077445 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1985,7 +1985,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 @@ -1994,12 +1994,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)) @@ -2014,7 +2014,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