From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65A20C38A24 for ; Thu, 7 May 2020 14:28:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 367F32083B for ; Thu, 7 May 2020 14:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588861684; bh=H9NGpbmB4s+b6la1kpO6pyUowVzREBF2y2Ty2yUwlEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=nY8AdkYO7sVZ1XHH5z3Hm11CQHArgdIhHQqyMf3AqoUTlWCGj1MerdcXLoMI3Ua/a YEmjAVudpguBh2td0rLuWR6dlywJn65G2933XbwjMuGaUrdjHuqzjj36zKF0Fl1BDm Xre23TnvGoytEt6DOrasY5x/QEa9TyMQOFZpUW/w= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgEGO2C (ORCPT ); Thu, 7 May 2020 10:28:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:54040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727879AbgEGO17 (ORCPT ); Thu, 7 May 2020 10:27:59 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5F0882083B; Thu, 7 May 2020 14:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588861679; bh=H9NGpbmB4s+b6la1kpO6pyUowVzREBF2y2Ty2yUwlEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BzaaMT2It4gAnarnAtzBQ7tipdVi4YwqCKkr/dLWc6vg5J7/TTdYbNiLXrwbpTELd 5oK0MeLOGT2UDkYqZw2ut0D0EohAfNItG2MuboqzeNL3Fo8nKA6MJ7J8o2ypm0bRZf hfg231BdZm2mrDBdXiTd5u6LHsS29vUwYEUFr3UQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Niklas Cassel , Christoph Hellwig , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 5.6 26/50] nvme: prevent double free in nvme_alloc_ns() error handling Date: Thu, 7 May 2020 10:27:02 -0400 Message-Id: <20200507142726.25751-26-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200507142726.25751-1-sashal@kernel.org> References: <20200507142726.25751-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Niklas Cassel [ Upstream commit 132be62387c7a72a38872676c18b0dfae264adb8 ] When jumping to the out_put_disk label, we will call put_disk(), which will trigger a call to disk_release(), which calls blk_put_queue(). Later in the cleanup code, we do blk_cleanup_queue(), which will also call blk_put_queue(). Putting the queue twice is incorrect, and will generate a KASAN splat. Set the disk->queue pointer to NULL, before calling put_disk(), so that the first call to blk_put_queue() will not free the queue. The second call to blk_put_queue() uses another pointer to the same queue, so this call will still free the queue. Fixes: 85136c010285 ("lightnvm: simplify geometry enumeration") Signed-off-by: Niklas Cassel Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 652ca87dac949..fb4c35a430650 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3580,6 +3580,8 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) return 0; out_put_disk: + /* prevent double queue cleanup */ + ns->disk->queue = NULL; put_disk(ns->disk); out_unlink_ns: mutex_lock(&ctrl->subsys->lock); -- 2.20.1