Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7424809rwi; Mon, 24 Oct 2022 14:34:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7EuWFNOdgD49bCE6pWE5b/I5ZOtOy9jGt91/4yGcDJC32tBck54VxT+sgdaB5dreDjD/X+ X-Received: by 2002:a17:906:9c83:b0:779:c14c:55e4 with SMTP id fj3-20020a1709069c8300b00779c14c55e4mr28684436ejc.619.1666647285560; Mon, 24 Oct 2022 14:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666647285; cv=none; d=google.com; s=arc-20160816; b=NaEPQsMQ6gd6p39DeC3Kfr7mvtsFjIaWodIDLYu2AmPHz6aSsnmd7cCWcGPm09sUCz mk5PJ+Ec6YiSYiZ3cvPLkfhMCAhI2fMzd60P4aa/IyJ0mXJE7b5clAMYZnGeM9S1RBKn h5TOA/aQMFbNBJupKCNCVk92gYHVAm+3JCIW9EziNzTzpKcyaLMsWRVBIi56PmwO3mWD c0uCulBdn47yBnjafuiZGMbBQgnR0BYjiIlpr5A79DcfJ2OyJgPGdKjVlAOWvnjqESPG 1k1nlbmzCde/6mrFT/+uK9SIA6BN+WWY2MZ7LvBsVCDHGa82YAkqvma17xzfhQ7iTDBv 2upQ== 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=5gs6Qd7Jc5ZFe97NMyU7u3ZUueb7WRbdIpeOiS/sr+M=; b=CGmFJCyvvPXvI0vdrbOHFTatuSO0cIKj2bpvxN9FwaHEwQdaYyfQF71bzp4YX2We/R gn1BXUXpctewlY8IvTT6zWlol1qoVLFD10choA58RET5ef0oZ4g9dwnTihs6MVzDlD+g MhEWlws38D4TiAUoDMpQiPJslyE4hHcYx0In30lPqlfeJ1oz7z8rPJTK5VUm2BTEFz6d 7Rni1aLCTP7Ax8k86GMhbnTAMd43rS2GKEhZ2QII/BK75R1Y3Wt2b9O1w2AHnSkE5VC/ rIynmFj9/t9yS6zKE4av4ibmF/G+p5+W6wPat8hAFtiZeuqSvkHgEsNZhsiEXYVIw9C4 9EfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZChTQCb0; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cy28-20020a0564021c9c00b00458cdba7a90si669774edb.471.2022.10.24.14.34.19; Mon, 24 Oct 2022 14:34:45 -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=ZChTQCb0; 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 S230338AbiJXVRP (ORCPT + 99 others); Mon, 24 Oct 2022 17:17:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233589AbiJXVQj (ORCPT ); Mon, 24 Oct 2022 17:16:39 -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 C4849153E01; Mon, 24 Oct 2022 12:22:16 -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 33A4DB811E0; Mon, 24 Oct 2022 12:03:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87166C433D6; Mon, 24 Oct 2022 12:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613024; bh=LEl6rAYkaTCrqCjHts82zcSQepTHnV6TX+kZhzawsB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZChTQCb0vGcdIMH2BsgdJMiOsM6SuEVSRHmsOxQoXPeKcOMEjHwHy2B3sNbGc+Qi8 JkrKfhlsVFtnCwKYZnBFeZ8m/DpkyHDrQ/xFX9Ih+i+aVcXvLwjYIMNfl3Po3CxY88 Zr/GsfA2NW2qgJFzSCGU8vro1RFE5SsLzKyL+WCs= 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.19 209/229] nbd: Fix hung when signal interrupts nbd_start_device_ioctl() Date: Mon, 24 Oct 2022 13:32:08 +0200 Message-Id: <20221024113005.961123796@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 2ef7eec6461c..cc66983e8b6a 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1271,10 +1271,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