Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp437980iog; Mon, 13 Jun 2022 06:02:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/wXwDAI8X9KXgVaAfOwt8Vaz1Cc15eIo8bLNexVGbdYhqTIIWZRdqmaDAXfCBm1DSYW7u X-Received: by 2002:a17:907:a422:b0:705:e944:fd3e with SMTP id sg34-20020a170907a42200b00705e944fd3emr51667638ejc.309.1655125337356; Mon, 13 Jun 2022 06:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125337; cv=none; d=google.com; s=arc-20160816; b=JH+7GBrLUqk/NydI4mDxGU5Ogyl8mihkt3k5CepzRBo5xERkMT5BrDK3/J4kWr/YFL 56gxwzMsjHynKzc0crTLmrULhe3S2Q4GeOKdRkuw/ZI7mPA4kvRI6luAMD2aD5HzL6Pv oG8q3KBZ+OIRZpTmn1+URGzMuH8jfRwWEkHxC/MS3Hx4vZXvN4abIkNRSpvAY62FP5Pf Yb3FNAMIF7kLnrqsuRDkXtuR932FA++2NVSSN91Gw61SlKtKePlhDutef/AamjKhlTow GDyNawGDxiUCJEavXEgzUYKZQhR7uIWFo0T387lFVEzxwz/Juhx0P/HvYDcdRyTiCsPE 3n/Q== 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=9mTmEbrbDy6Xjaek6va2TvR36+Byhr2jr3e/kq2luVM=; b=SSHqwQ12zelJNpI1c9oMArhP3PJmE725TPDWUHAS5gcvN/aGJdpyzVm09MeObXPoLS oyGjqcrHNCKlzCH7hiM2C9M013oHEsDd2pJ9VlMn+d/Ws2HJT3HRXWy8WpOcZwiOuw8i j4uDP+U6NwVO0+i6SiE94dd40P8LcOtbfwH4LbwO2cVaXjjtcn14wMul2pAVpQ+pcQo8 55GTloFqzCp6pgxg4uurE42Qarbbtfc1EpKUsVxnSfFfmUuet55VY9DcbQmHy8elv451 rBmTg+OEOSWvEFjqsWluvaI8LNFv2Ev20KBOys6iaaD02C7t+2BTCJ6UVwbTjjsjjD26 MpwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EB26++WW; 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 nc31-20020a1709071c1f00b00708de654a3esi8568551ejc.995.2022.06.13.06.01.49; Mon, 13 Jun 2022 06:02:17 -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=EB26++WW; 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 S231219AbiFMKQC (ORCPT + 99 others); Mon, 13 Jun 2022 06:16:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241812AbiFMKPm (ORCPT ); Mon, 13 Jun 2022 06:15:42 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB516BF7A; Mon, 13 Jun 2022 03:14:52 -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 sin.source.kernel.org (Postfix) with ESMTPS id CC17FCE1171; Mon, 13 Jun 2022 10:14:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF3DAC34114; Mon, 13 Jun 2022 10:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115289; bh=MnDzMeDKLpDlIzqk4erNLCvRJbkC19vwKGyigFu2yVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EB26++WWSbua7LlewdagCI4MZdfZ2PNKnbJcCAkREbWez/I0w5k0q12jRoCLPVvjH jMyr0QhRHYHZHbQTFVe/xs492qNnAMvh47LJI0CL3PgfYKT5J0nHN+kU966c7l7W4D gigru4nwNsnJzn8e86bwYc3bv/p5a6c9px7SF/3U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kyle Smith , Chaitanya Kulkarni , Hannes Reinecke , Christoph Hellwig , Sasha Levin Subject: [PATCH 4.9 022/167] nvme-pci: fix a NULL pointer dereference in nvme_alloc_admin_tags Date: Mon, 13 Jun 2022 12:08:16 +0200 Message-Id: <20220613094846.026729618@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094840.720778945@linuxfoundation.org> References: <20220613094840.720778945@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.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,T_SCC_BODY_TEXT_LINE 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: Smith, Kyle Miller (Nimble Kernel) [ Upstream commit da42761181627e9bdc37d18368b827948a583929 ] In nvme_alloc_admin_tags, the admin_q can be set to an error (typically -ENOMEM) if the blk_mq_init_queue call fails to set up the queue, which is checked immediately after the call. However, when we return the error message up the stack, to nvme_reset_work the error takes us to nvme_remove_dead_ctrl() nvme_dev_disable() nvme_suspend_queue(&dev->queues[0]). Here, we only check that the admin_q is non-NULL, rather than not an error or NULL, and begin quiescing a queue that never existed, leading to bad / NULL pointer dereference. Signed-off-by: Kyle Smith Reviewed-by: Chaitanya Kulkarni Reviewed-by: Hannes Reinecke Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index c87f27d3ee31..e7b872592f36 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1203,6 +1203,7 @@ static int nvme_alloc_admin_tags(struct nvme_dev *dev) dev->ctrl.admin_q = blk_mq_init_queue(&dev->admin_tagset); if (IS_ERR(dev->ctrl.admin_q)) { blk_mq_free_tag_set(&dev->admin_tagset); + dev->ctrl.admin_q = NULL; return -ENOMEM; } if (!blk_get_queue(dev->ctrl.admin_q)) { -- 2.35.1