From patchwork Mon Oct 24 11:32:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp441955wru; Mon, 24 Oct 2022 06:06:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7w8Og9ozS5WWGB6pY6JPBqxR8Zgu8pHp/F2pasdplTqpTbWZ8vzcJUTpPEEKmxoc47UBHr X-Received: by 2002:a63:814a:0:b0:460:9253:bf8e with SMTP id t71-20020a63814a000000b004609253bf8emr27602355pgd.469.1666616800798; Mon, 24 Oct 2022 06:06:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616800; cv=none; d=google.com; s=arc-20160816; b=IqC+b8ucPudb1v4IYo4KRdS6hdXrmf6Jxk0gichPqjJ8EagIbjkDaomiP+zu5XV/Kq IomgbJh8MejWz5gOd3qVP2sIo8NOfj1dxczT3l27bzU5Ba5mkShrCuTk2mFPKWA+WF+G 3zJtZ5eUx8eNOMnc5p1CgtaPSiNRRRxUu5Ik53i0UzYP9m8Cul4Q8fVFwaGLmNxcZcms t8TeeulcfjO9ACF5so6QXQ65ERPqVXZUSo+iImSvGCcqMcrLRwGpmDoY2/k1n1aCG57y 5lsGpjq4pp3exYazTtXaYKZGZaIJd3HHwa2ZXzFjtvbNgZy+Ofl6S0B4hrZwCkK3JiH8 +kAg== 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=aFZh1fb57CzmOkjHSfXMFO9BXE05aLNfYtVigtAbPUU=; b=nD7812GVUb93B0g8dqsQBY3sou8I+xpCfdbB2JNvbKfKxsBaB2QFlhhd+WDiFRJBxP 2w4iIDSrQx3sxo8C5xwTYXmSASZAqCw1E+RAzurmBHx0vkfh9IIXEjhJPi/e/Oiyw5XZ +EcppUHupQAB7WL6M4y7ataVXpm6F4cpae4607wq/7GkX6Z9A7M1vV2ty+AbvlXpA1Kb 6HS6jb7mdxHbEKxmxWihAkkYsW73xD4kK3ilAqM0ZqJXjqQVnkRQjV155PeM2ShggEny gjg40Hz4qn/DxgHHbburUIM4iMsbVdEjIOYYUhx/vw5r5+AhX8t+9LUKunm9e/eIL7i/ ZfRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iQjuipbj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pq8-20020a17090b3d8800b0020382775a6fsi14793577pjb.149.2022.10.24.06.06.20; Mon, 24 Oct 2022 06:06:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iQjuipbj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235330AbiJXNE0 (ORCPT + 99 others); Mon, 24 Oct 2022 09:04:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234954AbiJXNAq (ORCPT ); Mon, 24 Oct 2022 09:00:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A7D31C41D; Mon, 24 Oct 2022 05:19:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 841B66128E; Mon, 24 Oct 2022 12:14:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93B46C433D6; Mon, 24 Oct 2022 12:14:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613684; bh=azAkJqJbnTmmew6QdoYoIdY01RIbkpxXD1N808qO7go=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iQjuipbjFV7GZAhF0XTvuMjgPwvu61qfM76DPBNt/AFVHXNdRrMTnL2QXl41xGRt0 H9QRjUUoSFugl7RV0MmTSJ/BhmsfHZOBgW3Aplq8GfF69t3VI8eKmP/UZua/puDL1v wDkwFzPxbd+gPNziLomUjn20XohORU1AADSEECBk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+38e6c55d4969a14c1534@syzkaller.appspotmail.com, Shigeru Yoshida , Josef Bacik , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 231/255] nbd: Fix hung when signal interrupts nbd_start_device_ioctl() Date: Mon, 24 Oct 2022 13:32:21 +0200 Message-Id: <20221024113010.835858082@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747574378926940066?= X-GMAIL-MSGID: =?utf-8?q?1747574378926940066?= From: Shigeru Yoshida [ Upstream commit 1de7c3cf48fc41cd95adb12bd1ea9033a917798a ] syzbot reported hung task [1]. The following program is a simplified version of the reproducer: int main(void) { int sv[2], fd; if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) < 0) return 1; if ((fd = open("/dev/nbd0", 0)) < 0) return 1; if (ioctl(fd, NBD_SET_SIZE_BLOCKS, 0x81) < 0) return 1; if (ioctl(fd, NBD_SET_SOCK, sv[0]) < 0) return 1; if (ioctl(fd, NBD_DO_IT) < 0) return 1; return 0; } When signal interrupt nbd_start_device_ioctl() waiting the condition atomic_read(&config->recv_threads) == 0, the task can hung because it waits the completion of the inflight IOs. This patch fixes the issue by clearing queue, not just shutdown, when signal interrupt nbd_start_device_ioctl(). Link: https://syzkaller.appspot.com/bug?id=7d89a3ffacd2b83fdd39549bc4d8e0a89ef21239 [1] Reported-by: syzbot+38e6c55d4969a14c1534@syzkaller.appspotmail.com Signed-off-by: Shigeru Yoshida Reviewed-by: Josef Bacik Link: https://lore.kernel.org/r/20220907163502.577561-1-syoshida@redhat.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 09323b0510f0..610dc6a36a9d 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1327,10 +1327,12 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b mutex_unlock(&nbd->config_lock); ret = wait_event_interruptible(config->recv_wq, atomic_read(&config->recv_threads) == 0); - if (ret) + if (ret) { sock_shutdown(nbd); - flush_workqueue(nbd->recv_workq); + nbd_clear_que(nbd); + } + flush_workqueue(nbd->recv_workq); mutex_lock(&nbd->config_lock); nbd_bdev_reset(bdev); /* user requested, ignore socket errors */