From patchwork Mon Oct 24 11:32:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp571185wru; Mon, 24 Oct 2022 10:32:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ksNLyymDJfJVpOTlVik8XI3IqwXdvIS846Epm51Va2yUKNsximCHc5H0lpC97wmpJJGD0 X-Received: by 2002:a05:6a00:1943:b0:563:8173:b46a with SMTP id s3-20020a056a00194300b005638173b46amr33777288pfk.34.1666632761959; Mon, 24 Oct 2022 10:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666632761; cv=none; d=google.com; s=arc-20160816; b=eyIBcx1odxlx7YMQ5VhrWeiXAbMKuHl5ldxIsw3L6pRlidnop8FEwk/0a9O5A9aEs/ uGc3K8xuwpTSaowu+OX0SuYKDR9AmmM+3JC6HmePdKM5ljGqm2xssL1XHTFVU6gxl3Ab WTeVMvjjrVYJL2eBJEPUk8mY42JJ6VSwbfHgODOmkWnAOX3BdcFr/T8Ude/iQvHoGFLf /rdB17SR7wEgkS9zQ3+gxom2YjbvvjHrDoBmFJS3lYnojthTxTc0orh8en9aUsIeCNie l7KaoM2B8C8cXEVumOLjc3PuXFlSzWh9KfmInblPw/CG1x4qeYVFHVNlNYe1pwocAdA0 eSqA== 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=KSb0X/FApwiPuKN+plDBynOQWCXhdlC8YtLovIo606A=; b=KRZRXOnfUQ87XdXpOoAYVlpRfodFjahYT4pY6Wj7pDw3TqeLOAbawY8bdhns3iPU9T oYjq74OPNKxH8cLVNyd9GrhsIp/vSNsS5hZqYkhVVN2JpfNJohnJ3uHeHKtsn1VEFoLl rmnVA9pEOWhCAX6j7vFZk2z01jzZz6dysCLQwwQoqJ5EOwy+5Hgo5Cfbd/7ISjIV3mXo +kN0WuxEBgx6zXgvxFSbzPiCyMSVmSY5VS+v82jZY8AR9T5aqGRoG+aL2jvEcmZN9F36 rhLpSBg1yNnA2AUX6aYlU2bSkYLP0BDNH6HLuZ+HoDh/wedw2ldWuqc9u5bL5o5tyRm4 PE8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mREXkcK7; 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 b22-20020a63d316000000b0045650af278bsi10837pgg.817.2022.10.24.10.32.28; Mon, 24 Oct 2022 10:32:41 -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=mREXkcK7; 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 S232068AbiJXR30 (ORCPT + 99 others); Mon, 24 Oct 2022 13:29:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233364AbiJXR2t (ORCPT ); Mon, 24 Oct 2022 13:28:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B1723472F; Mon, 24 Oct 2022 09:04:39 -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 92D6BB81711; Mon, 24 Oct 2022 12:31:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3D1DC4314C; Mon, 24 Oct 2022 12:31:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614691; bh=UR63eXK32mdq79RpdY/D8aufxHgBPZJACfCRDlovMcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mREXkcK7qX+01GyJZ0MyRUZnhv3eNxmMpyg1L6doLbUm6hkTaFeXdFjQSibiy4DJE HSZXx/R1XqEeVSWsIv6FxSGVJom5VrfHQsB/oP1GSkZqs5LsfkoezAMUmynBdXwwmi H1liHgFcsrm3n9r8/JAHCFbIPDfghQiqRTV/wCog= 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.10 358/390] nbd: Fix hung when signal interrupts nbd_start_device_ioctl() Date: Mon, 24 Oct 2022 13:32:35 +0200 Message-Id: <20221024113038.239469781@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747591115422162765?= X-GMAIL-MSGID: =?utf-8?q?1747591115422162765?= 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 4a6b82d434ee..b0d3dadeb964 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1342,10 +1342,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 */