Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp390152pxk; Fri, 11 Sep 2020 09:37:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzES/mU2DCAOQe5nH5qhw00Llv5T7fd/moAaSjpVuUbfoDjKcYd7jXqRCMkRSd7AijrH47+ X-Received: by 2002:a17:906:7013:: with SMTP id n19mr2830984ejj.388.1599842222734; Fri, 11 Sep 2020 09:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599842222; cv=none; d=google.com; s=arc-20160816; b=it6soKbjgqaRYT+FQK2hJtUh/Obviz5jd0Udb7cvmiJC4Qe7RG6GwCObbQOiDPCfrx hbSKxhRmW7Ni3hurny0RhWLJWC1XH5HMNPZ2EK4j2NQYu4AkUYY4Ggtlc1YKAwJtZhiU 1Xzt8pvuZxgrUonWSYfA7Lby+1V3wU+LZDE5ZOtNFvCykKiyoK+4ecodD3fZOQcGSlAX dh6tiyGqE4YKjtU913FA/QTegwc9/mXD2n9wmJcIuo3ksbg1ZsLJHAlOabGUKwOVKpsf 5ZUSPzw+BuZXkFW2nBBMY443oE0B1Q5x9aVfRv5UxAz1IMcChUtfl4/pqFtM6rI2wDSn mD3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ij6WQ/NhPqjRg9eGrhMh+F7qrvO3+k11SdD8kbKVyGQ=; b=CcvitipjAFT4z4ASl1E2pQNnEnu6FGA+mhXxd3euY0l7/zmNMvxFuWR7r5rQub1u2P ChDsZs0UXeiHU2JQAok5R+Je3csED0gThNi6W54r5AUakhbz3o+4kGCzYqxWg+SN+JgM ++ATYbmkF44dsjAUKUj48a5gsXB48Iyhlb8zP/B6/E4ERhrxhGvT07hsXCU+AcRIX2pi 4T99oKaHIvYNrBHyfTcdt/569IHv2vg1HzT9ja8xEvUOfnnLmj9Vi5kb4FJwkK+unAnB HUa3n45K61Vbl6dAuEaIEgyLBRQ7ie2OhV2Umgkn0tjImo5k90BU2UkCMwBtP2p6U0lL LayQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=npfiVqhq; 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=fail (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 ng3si1630656ejb.720.2020.09.11.09.36.39; Fri, 11 Sep 2020 09:37:02 -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=@kernel.org header.s=default header.b=npfiVqhq; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726458AbgIKQdW (ORCPT + 99 others); Fri, 11 Sep 2020 12:33:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:53396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbgIKPRj (ORCPT ); Fri, 11 Sep 2020 11:17:39 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D536422400; Fri, 11 Sep 2020 12:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829178; bh=VHEHsFs9eWmEuMzGT3hxFB0fbn9NzjjQntg5CD00oP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=npfiVqhq1ZkE3ntBbh3iaj2efd5Xr/Vei83UjZ7zju20yjxfkCWGgHEiki+FV1SFY //+LXeMYZMSQ5u5F1mNUuaOjBSvw9RnF5b+3NfF7GSTE7tjKGi3DEGO+A/t9Za3CU6 wO/rugF6923qVtZEjQGVQTRJDmoE3T6cu98PjMOg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , "David S. Miller" Subject: [PATCH 5.8 13/16] tipc: fix shutdown() of connectionless socket Date: Fri, 11 Sep 2020 14:47:30 +0200 Message-Id: <20200911122500.236937094@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122459.585735377@linuxfoundation.org> References: <20200911122459.585735377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tetsuo Handa [ Upstream commit 2a63866c8b51a3f72cea388dfac259d0e14c4ba6 ] syzbot is reporting hung task at nbd_ioctl() [1], for there are two problems regarding TIPC's connectionless socket's shutdown() operation. ---------- #include #include #include #include #include int main(int argc, char *argv[]) { const int fd = open("/dev/nbd0", 3); alarm(5); ioctl(fd, NBD_SET_SOCK, socket(PF_TIPC, SOCK_DGRAM, 0)); ioctl(fd, NBD_DO_IT, 0); /* To be interrupted by SIGALRM. */ return 0; } ---------- One problem is that wait_for_completion() from flush_workqueue() from nbd_start_device_ioctl() from nbd_ioctl() cannot be completed when nbd_start_device_ioctl() received a signal at wait_event_interruptible(), for tipc_shutdown() from kernel_sock_shutdown(SHUT_RDWR) from nbd_mark_nsock_dead() from sock_shutdown() from nbd_start_device_ioctl() is failing to wake up a WQ thread sleeping at wait_woken() from tipc_wait_for_rcvmsg() from sock_recvmsg() from sock_xmit() from nbd_read_stat() from recv_work() scheduled by nbd_start_device() from nbd_start_device_ioctl(). Fix this problem by always invoking sk->sk_state_change() (like inet_shutdown() does) when tipc_shutdown() is called. The other problem is that tipc_wait_for_rcvmsg() cannot return when tipc_shutdown() is called, for tipc_shutdown() sets sk->sk_shutdown to SEND_SHUTDOWN (despite "how" is SHUT_RDWR) while tipc_wait_for_rcvmsg() needs sk->sk_shutdown set to RCV_SHUTDOWN or SHUTDOWN_MASK. Fix this problem by setting sk->sk_shutdown to SHUTDOWN_MASK (like inet_shutdown() does) when the socket is connectionless. [1] https://syzkaller.appspot.com/bug?id=3fe51d307c1f0a845485cf1798aa059d12bf18b2 Reported-by: syzbot Signed-off-by: Tetsuo Handa Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/socket.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -2773,18 +2773,21 @@ static int tipc_shutdown(struct socket * trace_tipc_sk_shutdown(sk, NULL, TIPC_DUMP_ALL, " "); __tipc_shutdown(sock, TIPC_CONN_SHUTDOWN); - sk->sk_shutdown = SEND_SHUTDOWN; + if (tipc_sk_type_connectionless(sk)) + sk->sk_shutdown = SHUTDOWN_MASK; + else + sk->sk_shutdown = SEND_SHUTDOWN; if (sk->sk_state == TIPC_DISCONNECTING) { /* Discard any unreceived messages */ __skb_queue_purge(&sk->sk_receive_queue); - /* Wake up anyone sleeping in poll */ - sk->sk_state_change(sk); res = 0; } else { res = -ENOTCONN; } + /* Wake up anyone sleeping in poll. */ + sk->sk_state_change(sk); release_sock(sk); return res;