Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp180906rwi; Wed, 12 Oct 2022 18:13:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5tx8GYXEQDNr00oQ8kxsOW0dReflZtC/XnWDzgcfuHo8FTp2VNrAoX0B2oQyr/GVYQJ4Mt X-Received: by 2002:a17:902:e848:b0:180:c732:1e52 with SMTP id t8-20020a170902e84800b00180c7321e52mr26609333plg.83.1665623606599; Wed, 12 Oct 2022 18:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665623606; cv=none; d=google.com; s=arc-20160816; b=0EGQ2ZH0FFF2T57qQdPkg8jU5rUotjhiNfTDh/Tz/B3J3gJUPe2pVsxuNrRomWZ6Cg VheayXvr1sHzPUYrd+AvOWPZLukBqNJa6/X14NCc2t0Lwm6RnX/qa38JdHGSga8Hz/ic VO0ceFJFEGq+jk0DlqQ1jfuFzsTe0BNyowcUipD7LHaKuPxu2EHXtqOiga4PFPSXNxRs Xd5TPE8HGZJWVydlIClCbX6tAuHY+TgGRF4amJX70o6nSya8hMQ0t+QPb1TjC7aLJ+GV UP9SMd2iXJLlkcX6cF6VDeDG923nigWjsXRCUHj0GuRbIa8wDsYMfvrRa9Z6GAd/WSBq dQ9g== 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=l/jJq7MnGHm9gvqc8F56IvEzvEO21bdw3eK1P33ARVs=; b=IXKxpauJNi1TvNvN+IdSDTMxMA5S+ckAKR7TAOO39MK8NTQgFFwsy5Y6pICOAXb3bK fOwcjf3sNZmUjB3k65V5oeEoaDw8QI8iWfay7orRfCMfQnNLWCpy1L371B4gZPSYVNF7 2AiN6O2ycOcsEN2OTz77ot4nDbQ2x0C1NolObzseNXcVGMeQLAcRZwDph19GDgtdTjIS SMx21U6+yuC6hd3BzJVPtKsubycJ2aNXmNLd2OCG+x2TCUT9tdkn2hfFyMwp+VbhXyXK z/35vyJyT+BcbWe5KuvZIHCeRFrWu3RXIwdNm+ZI691HHUkggVeITZZQRWdu2H1FUSdV FZ2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WL8xodcr; 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 d13-20020a056a0010cd00b0053e1d872a91si21063937pfu.83.2022.10.12.18.13.15; Wed, 12 Oct 2022 18:13:26 -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=WL8xodcr; 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 S231169AbiJMA0C (ORCPT + 99 others); Wed, 12 Oct 2022 20:26:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231174AbiJMAX5 (ORCPT ); Wed, 12 Oct 2022 20:23:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F2DAC4AF; Wed, 12 Oct 2022 17:22:24 -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 3C38661697; Thu, 13 Oct 2022 00:21:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEC51C433C1; Thu, 13 Oct 2022 00:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620512; bh=Qq5cqGeTeMGpEVXtKhhwlv6hcwVtjhamt4f+1/vSqbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WL8xodcrnlhGSAYf5IMmabksG3T47xaPWAMh/hhdVtbwqn/dd6X1QrnvBX5WTcbEJ RtZIwHS+2qO2miHgPYZTfcl/X6H01vuVdIZbVA2n/CUTibwgchSsXtuT1aaCxCL/RS r6SZ2hEUaHfs8fSv6Bzvw2iCHvKrhsgCceOYEvOnAg9aqsi1XL2TIi6oVkrPp2/WOe JEhwNesqZc8sVDJmlTx4bY2deikzE5O1xh9IkMK3hhZwFIIrvypR9UshN3XS2cDjoJ oNPNT9RY9S2BHbRTpl64rRHZZ4rLfwLMxSoWo5qgyJ6HWlACHBT3qpSJ1mhgpUeiUw o/jSwAEGaWoPg== 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 5.15 09/47] nbd: Fix hung when signal interrupts nbd_start_device_ioctl() Date: Wed, 12 Oct 2022 20:20:44 -0400 Message-Id: <20221013002124.1894077-9-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013002124.1894077-1-sashal@kernel.org> References: <20221013002124.1894077-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 b391ca062add..ec2b5dd2ce4a 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1351,10 +1351,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 */ -- 2.35.1