From patchwork Sat Oct 22 07:28:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7727 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1110039wrr; Sat, 22 Oct 2022 01:51:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Mmogdon1K8bTgdXIDetHqBzX49hcmiEms4dMhq+kD7eitrbjkFKdFdIDKBU2a+sygJw9h X-Received: by 2002:a17:907:7fa9:b0:791:a5c2:e25 with SMTP id qk41-20020a1709077fa900b00791a5c20e25mr16230566ejc.444.1666428665773; Sat, 22 Oct 2022 01:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428665; cv=none; d=google.com; s=arc-20160816; b=p2BmtGC26XcfGLRk0AgkFCldx0CpUsbQ+EAJsA42Fo/d71wzzDQIhZjuTE43PsW4mc KjkcBGQyESk9q3Qe303H4NvJAqQkq5PGebJ7erGUdXKKI2jveXphpVT/OJuD9/2jvSMw 8Cwz3GNdgAMOOyrS6c7GKMZ5kZ55/IOq8dkJLWdso4tcJggAdWDCK57GrIBzj3j+hin4 t3Sae2XQtiK7aJ2y1m1Vq+iySw2tDmtRjSZFxW5phPJc+Giqkv+zrHyvccG9IZMMkE9Z DjZY5lk5xcjjQrF/vYuhjYtYN330zmCk83KjAdC9Q1tRROeohkVOs5onPwdntg5OhGcT nTNQ== 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=ufNDMjjxo9BePpoAwHqlXIDDm3IgUDOGDL5vHRJUpeQ=; b=QfIiKe6gJnQPogU0KeieI1aw2ZP4o9ZBx9b10OFSKxO1z7HSfryJOKeElalsduvPcu Q7+j5TfGKxZZ5WeiQsf/dLph3OLh92JEzfHtL/S+WIG2uO8ipOFVUZwWWCGG5WgjZnAe mNTSK6Jkw8wV+CMLsMV8lkE11+h7jozpYvR39V9E5WWQmyYM77aOhg1+lX5q5A4qBCMr efF0irie8y0DHZeacJe1A0E+ZVBvwz3j60BNWDa6SmYYhN50HUFRcbyASszG+T16elzt bQrN8zk9rh0da2HmuMcXtagtWnokrW7PFuLdMU+/beetK1Fz22JENCFCSuPe2EFMVJuw y8LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G54kT+or; 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 oz42-20020a1709077daa00b0077ed84da316si23691188ejc.217.2022.10.22.01.50.40; Sat, 22 Oct 2022 01:51:05 -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=G54kT+or; 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 S231319AbiJVIuD (ORCPT + 99 others); Sat, 22 Oct 2022 04:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234807AbiJVIrt (ORCPT ); Sat, 22 Oct 2022 04:47:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 235957D1D0; Sat, 22 Oct 2022 01:10:03 -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 ams.source.kernel.org (Postfix) with ESMTPS id 86F02B82E19; Sat, 22 Oct 2022 08:06:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3903C433C1; Sat, 22 Oct 2022 08:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666426012; bh=eguKnLad2H8M6bUVtKYKwm5h06Y8UI6NP/VWTx8rUIM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G54kT+orGCcqgpWnboH36xHylUZBIlwD1TMx8kZ4q0w9S6Rbq85U4FZm8VVSweDSr mLLJOD5BRwFPN3QRbn7PbSVauH6qYHgXTitu5TAoHpoxDK1N7YDao3k0SMT7f7WQd3 S2BR9+U9uyaM9jigSUXrcyIOnTwaRukk7VU1VekI= 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.19 660/717] nbd: Fix hung when signal interrupts nbd_start_device_ioctl() Date: Sat, 22 Oct 2022 09:28:59 +0200 Message-Id: <20221022072527.585225648@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747377104217548214?= X-GMAIL-MSGID: =?utf-8?q?1747377104217548214?= 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 20e9c53eec53..3a3680b3c4fe 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1414,10 +1414,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 */