Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp133274rwi; Wed, 12 Oct 2022 17:19:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM57nstLuCM6K/01dCYN0OOTB1QhMqcNB8et1DtY2y5e63HR9MQhJZQrnUC0pTwI5MWpMlz6 X-Received: by 2002:a17:907:7b8b:b0:78d:cee5:3145 with SMTP id ne11-20020a1709077b8b00b0078dcee53145mr9776719ejc.537.1665620398328; Wed, 12 Oct 2022 17:19:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665620398; cv=none; d=google.com; s=arc-20160816; b=jd9MiCIG8REM5t1OvRXMQvCvms0ND/u7dq5DRYymPbFoJOLrzQjv7eIkffnEtT76cp Ws/2vSrTT39ozbU7u00qRFqAMuqPDcp91JjRs80txL5qGE7ei/m7zsApchBq4ChnQ5qK cn/DApIXaOecQ61620FUXwyHahoQkz4/IpAolP2MQYmf5J3xTIZ0cXIHSIrN86AQ5HZf 6TB6f1X4DRtLe9uV0qUfiiWuL/1AiY5fbq/XnJt5zJU09TMO/RYKcCWnDwZvHfA5PLoZ yeYhZo1uQ6WOrIUhui5y5n+owca1sUMt6Y7HpE64okVrhVQVm/OFklg0BOso7ztgiDWu RGag== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p54ADDVh5NcNNDQGbTmRAKIyX06WfmXCCnbKmt+8dpE=; b=1Cn7fVNtCIvj1E/4fkmJiM8dxgpiDJ3i/J+wW3LZnvs1v03f1gV7kb/Ky129kp/wLD NFc7dPbwLOyOk1ZuS6qWqmlDHaVDrDMCI2K9osedeM68BePEHJGvIQVVK7eZ0ZJKOcCW 1pI6Hkj6wOWK+Z+2kTx3yg5IeJrt+gS6agaz/C6xuU0utIJdDztffMoBea5J+/OVTnZ+ 2ezmpoj9ApkLLiAPRKuoGGsExUoxb1cIZARi0TG1zLvs8S/v3lsdVD7XQkSlaEop2f+g jCcWLTAGZjP+TXO7DbcdaaLwLSNaSHi5ZtRAfp6m8deLUYFpAAaM/n1fkWfIAl2626dj RVrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EB2pXyAy; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz12-20020a1709077d8c00b00782b261ea21si19741494ejc.729.2022.10.12.17.19.33; Wed, 12 Oct 2022 17:19:58 -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=@kernel.org header.s=k20201202 header.b=EB2pXyAy; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229811AbiJMARG (ORCPT + 99 others); Wed, 12 Oct 2022 20:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbiJMAQp (ORCPT ); Wed, 12 Oct 2022 20:16:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD40015048D; Wed, 12 Oct 2022 17:16:21 -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 BBCB6616B3; Thu, 13 Oct 2022 00:16:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3528CC433C1; Thu, 13 Oct 2022 00:16:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620181; bh=fvegeJIp2wdais0tigzcD56CJARkRkzBSW+xsY1dQP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EB2pXyAy4npPNYzi7Dq746MZ9nMJDBjUX0b1QWV1sX0x8N16IableQde9vCiuaoTz L2a1s6Fkq4KdR6JnkFynh4sOZLunDtJjvgGjba9/Eml11KGuu25qcU5y5sU+cqa2wc bfcLCW5z4VrgCfcEtzqWXD17lxp+BvaNx6bEbsq+2MBKLuzX3lriyqI3YnJTG/gRQM iPPkg34+3C0FJZUSvgWVprPJS65rzkrgLaGkYfo6u7LmUNhsZv/3VhgIpdOv0NxN6l 90g+NnB5FEN8BQ0WPcgG0bCZ3EONDHAYb1QUPpqBFVODWDJcnJv8qIl2EWSrVA3j0H WddU74wIm6Sew== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Shigeru Yoshida , syzbot+38e6c55d4969a14c1534@syzkaller.appspotmail.com, Josef Bacik , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org, nbd@other.debian.org Subject: [PATCH AUTOSEL 6.0 12/67] nbd: Fix hung when signal interrupts nbd_start_device_ioctl() Date: Wed, 12 Oct 2022 20:14:53 -0400 Message-Id: <20221013001554.1892206-12-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 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 2a709daefbc4..2a2a1d996a57 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1413,10 +1413,12 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd) 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(nbd); /* user requested, ignore socket errors */ -- 2.35.1