From patchwork Mon Oct 24 11:31:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp615926wru; Mon, 24 Oct 2022 12:27:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5HzMxxBVvJM1wpbwSwxFsZ5jylTFt9gjxHqQ1gDBzHF6qEq/TlmdZNQ6WdxUt2td+SYK1j X-Received: by 2002:a05:6402:3487:b0:45d:2674:d187 with SMTP id v7-20020a056402348700b0045d2674d187mr32064414edc.386.1666639653025; Mon, 24 Oct 2022 12:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666639653; cv=none; d=google.com; s=arc-20160816; b=IGp6kFa581MDCZb8C1m11K62cTh700xEaKRzXGxSFgCNVFeoJ/DIGkzvfXbpXGxsH9 7lKywCfE99hzRm0NKRPreBHsIG+hJ7sQQwEdnavNryUWj64zMx2UTXxh/v4EJnFy3YLD SBLQ4TuWa52HCyhQIclb9bo/RcIuUY2qjX2xmcl4tbRWE286gXkrvFW1+9XEiglHjAVg KQt9UXhSjyykXZLsNvQ8u08CFxljrg/CV0mgUt6RWMdcMLbNC3vMoxjJwMMSndFT/k/k 07yj9k780lvtJJG6RkojVpimg0pgMGlRgIzr7Pfn/331YOL0dw+7HHnhxlik6HQtygqV Y1WA== 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=MZxfd6bfEaEw4wRBYRNv67TvJ/hoZwAF1MgcHbDVi4M=; b=Vpu/MF86QO9kFG9yotsl495zuGldF9R5OtOsFY1mV5z5as04Wf/hljA/or4ko50pT3 LNseynC48gymVgtiDGo68BiMxy1qwgA/1Vm03YPaCZHDQL3ZLqVTTFoD9u5gdXCtZhqL NGc1IoM0KwlKJUkY7ktvEN7G9lFy+zFC3949pBzVV2WAPfOAonyBJyroTtXiuwQO4n2u KqJ/AQvhV1MDU1Zg10F2/4Ac7vcJLV7IN1aLyrxvs/xqG0l+CjTSPgQFtbD1RQJNB7aJ VcggpEJ2sl7ntCq+Gp/nEncGasVYU8KW6fkGUkFCkE7lHYFAzhFVlUDxoxJUJMdXD9Th uNHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D7OibFfo; 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 u11-20020a170906950b00b00791bcf8aa61si402742ejx.505.2022.10.24.12.27.09; Mon, 24 Oct 2022 12:27:33 -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=D7OibFfo; 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 S233146AbiJXTX7 (ORCPT + 99 others); Mon, 24 Oct 2022 15:23:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbiJXTWf (ORCPT ); Mon, 24 Oct 2022 15:22:35 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 105563DBE5; Mon, 24 Oct 2022 10:57:29 -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 sin.source.kernel.org (Postfix) with ESMTPS id 0C04BCE1369; Mon, 24 Oct 2022 11:53:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3710C433C1; Mon, 24 Oct 2022 11:53:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612436; bh=iQieQ4Y/Cp6gHS2C7Lg2w/a+l9Ieo+k4kqJju/g1xY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D7OibFfoBNzu8/fN5abML/2hzCLHjivTdsFSvcXSjFdzqftgqmUTh/jPvFZxdVun/ YJdj71Bm6T7jsYrVZD+moin9frmYE6WfENwA8Q1qm/3Jurtxmnok+oxJfcN2zFcpjr dpixHWEtJWhcYrC7hoZ82Pw0Jy43Mlk1kWpI98bU= 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 4.14 196/210] nbd: Fix hung when signal interrupts nbd_start_device_ioctl() Date: Mon, 24 Oct 2022 13:31:53 +0200 Message-Id: <20221024113003.321506243@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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?1747598340966519833?= X-GMAIL-MSGID: =?utf-8?q?1747598340966519833?= 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 338d02a67afb..f01b8860ba14 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1258,10 +1258,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); bd_set_size(bdev, 0); /* user requested, ignore socket errors */