Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp341952pxk; Fri, 11 Sep 2020 08:22:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7mAoaRikjunaHda+qLYsd4er2eMYfWe6qW+2/BXzPTefTtBmCxpqjI6njzC9dBZ9HPfOa X-Received: by 2002:aa7:da09:: with SMTP id r9mr2622966eds.7.1599837752322; Fri, 11 Sep 2020 08:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599837752; cv=none; d=google.com; s=arc-20160816; b=AlltiiKpMOVQXYnvLKNlXyYJAAFkOFQPfes097Gc/YiFaBKttUwoWiDvCpf+vaeShN IlEwINmF0OLJdJgoRaJImAaObg9zbX860KaicI8pli5maOOEz4LahximT0mE1lzf2sM0 A0wFGopy36QjAb6xlLY6ay6iHJY/GLTNOG/rI6H55YCC1Wy9M/8Oxe/0Is6hs7Qy7s93 M8f2QMVRxMM16Rx7Jj3i9Yi5J6KZmSOcsTDxFAHJOEFe+ks8X51+7IBpXZsV3XCt58Gd o0Cqp66bf95lGKzcAsbEJHQXIaj1JiwI0U+s0QYOFuskeRgy/FfIhDSTARbQQi3Aahja z31g== 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=zPJJw1XMjIfK6Qu69mcbheh8Es89Ew/6UEXuporKHfw=; b=RKTchO/EQSfsPLDG0glzcTQSEYBKDQD68g2lgmX9ySx7nKKq0HAUspcL8fefwc/LG3 E9UUrf+3nK1ACKt9py2qf+M/fAWelwb4hskCE9luQ98X90wj4Z6V5UfKAodpSqGV81C2 4P5ogvTwhwz+WkhurnMNzUTaeAMEb3vWa+Do4kXxM/8u86OkG45VTWij62ANf5MNWkz9 hSlA8Ekiq9Nye7YqcqprU54vML+kNZ6HoOWQLOhcbfR1wloNrq69+uPBvGt5ixYShXeS DLz/KKf5Lf+6jeQbKWuaR558wja8HptBMsuwbnIZ8nPoOUHmMJqoki7TDbWC9ueZJ5gV Jg2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YdZaKN6A; 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 l60si1435692ede.535.2020.09.11.08.22.09; Fri, 11 Sep 2020 08:22:32 -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=YdZaKN6A; 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 S1726265AbgIKPT2 (ORCPT + 99 others); Fri, 11 Sep 2020 11:19:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:52718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbgIKPPh (ORCPT ); Fri, 11 Sep 2020 11:15:37 -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 9AE0E223E8; Fri, 11 Sep 2020 12:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829140; bh=pOqmTT5z1pxK3xTG04T+GA+KPQhbWQMJzXgVzu1idOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YdZaKN6AhUKv4f6lLUHIOCNqcYm8butgvf7ySdvNwemoRkHE4rJMUwxiW64QMszY3 M6DKh8q604S/LDF8/YCvYdMGIFUbAZPlYU7r2jJbhVSuq8KECvpCe/OOEAAqx7aROB d3/g8axR05r/Ik8sgAqJXi8ZNL3xBbOcGk2EXc6E= 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 4.14 11/12] tipc: fix shutdown() of connectionless socket Date: Fri, 11 Sep 2020 14:47:05 +0200 Message-Id: <20200911122458.967159042@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122458.413137406@linuxfoundation.org> References: <20200911122458.413137406@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 @@ -2126,18 +2126,21 @@ static int tipc_shutdown(struct socket * lock_sock(sk); __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;