Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp606301iog; Mon, 13 Jun 2022 09:02:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1shu3iMZ4waAxJcNt7hEtUILnmLuI6tnzslGXF+6TcKH0NbF0ciBd741Hbr2eMHbgOh9I9E X-Received: by 2002:aa7:c34d:0:b0:42d:ce57:5df2 with SMTP id j13-20020aa7c34d000000b0042dce575df2mr432267edr.315.1655136150754; Mon, 13 Jun 2022 09:02:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655136150; cv=none; d=google.com; s=arc-20160816; b=RTJk7saHNlKoUrmXIQTbz8Wk14U9lD18OsjYCdu8Gczc3DRp/hLPM017XAGobollhV B78xJXi0HRK0miqWDKzLd/M1b2RNGXmSH4FaNa6stfcuc7j0dce8Hjd01KdRa+hXt/R5 8b5dvubYIPjvZt2Lv8Bzt5/6n7190TfXVjqgSv7fL86GOfkc5AcMsW1GArcSophidoii pxPQycHwUzbgWMAbXK1heRhG3hlEAP9145I88bktbz2mw7TR0CMVsuJbpNfscU55hiAL AnwNwymAsPSrViDSdetoGUX5CjrfquV+mEta6teAS0f2Nvb1QyBBoxJI2/hCCid2M1lu /s7g== 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=oaaTGGG46eyvwSPszVMeDwwfVhP+YV6g4dilOFVOPoI=; b=iya7Hs3FW3rzxNhP/rPZtTgLfwk+Aba30Wr1jbqI73baFV1UiSYQRbcFp74PO+MDsY rbpZ2rXrC9Ea9xawpYpdCd7SP2i0YPAN9KkaHwyJqdwDKtAlp+Cw1juGEPTMYgc8AhBU YHhGVQwD/0v0au+qnGduLpxPqAODFSnKsFnCekz9OF3P73dzATTFvxG6wd/RdLWVJQKF 4T/avZmlawiZz2FxxIfg6KTMzq4hVtLIPDzPy0kDFnLsuEs28wuYALIUgIQyizQ0+IXs z90eoqezfdgfJFimW9mXu0ShonLch8IdxFt9d8F0UoGVR+NKadVZu3SjpS7YU3521RbL D/xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1U28CCCJ; 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 b29-20020a170906729d00b0070d8de4e431si7961409ejl.206.2022.06.13.09.02.05; Mon, 13 Jun 2022 09:02:30 -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=1U28CCCJ; 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 S1356812AbiFMLvX (ORCPT + 99 others); Mon, 13 Jun 2022 07:51:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357171AbiFMLpo (ORCPT ); Mon, 13 Jun 2022 07:45:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0DA749C98; Mon, 13 Jun 2022 03:51:47 -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 2E95DB80D3C; Mon, 13 Jun 2022 10:51:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99443C34114; Mon, 13 Jun 2022 10:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117505; bh=wZ952zhWikajxX9H/+8SDddrcd170PgC6i07FK0S+K4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1U28CCCJ+6E2XO8Wnd9UttOzz27/+c5lel1Z7aEwQWdnuuXIgq9s88TJXH4o7K1km /WIc1bLzf4w1/nQF0UxhMSjS4jbq5Fkzr6LGZt2QEtLlGzeYJ9Hrt1+e3o7bvA6xsT /MAc+euMqGLnSkHAYym9o1w6b7kQTeYvijcN76mw= 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.19 037/287] nvme-pci: fix a NULL pointer dereference in nvme_alloc_admin_tags Date: Mon, 13 Jun 2022 12:07:41 +0200 Message-Id: <20220613094924.990921410@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094923.832156175@linuxfoundation.org> References: <20220613094923.832156175@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 d7cf3202cdd3..b06d2b6bd3fe 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1522,6 +1522,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