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 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.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,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 862A2C38A24 for ; Thu, 7 May 2020 14:28:07 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E98420B1F for ; Thu, 7 May 2020 14:28:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FFqcQ1e6"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="BzaaMT2I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E98420B1F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Q9iYrCAkyGhtRGxQyLIotbZUG1CEgBJzXMuTQ2ajQPk=; b=FFqcQ1e6MHDlF8 oLrhxX1fcZGssCroCuf69ycsOxzzVad8TD8RetWq3iOCYO7FlidE5BqdlF2U1wDvEc+3NpP3m4tG6 URUhashVp0LI1rh6x3kBn7Jp7wIW/F8H+D3Tl6rSOkzzpV7lcESg0TCcXYP1OSlgpFKbElMDLFnVR v506K5Jm9Ekoy5IAec+z/8Eyb5Ix69S2d/eBi5kcWZk7xMBqVwaX9+l/R21PgTmjtHo1d4FfskjlM 1jNQLqzZUOVs/JKPMBIPyzY+MXWRi10EETGx8wF9HO1Pc74wpvB1ErB+IaUXxp4b7bE4SgclZSBsL Q06wLp6lpMKtqMe3xKYA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWhVM-0001dN-Je; Thu, 07 May 2020 14:28:04 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWhVH-0001XN-Rp for linux-nvme@lists.infradead.org; Thu, 07 May 2020 14:28:01 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200507_072759_962649_0AB97824 X-CRM114-Status: GOOD ( 10.95 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , Niklas Cassel , Christoph Hellwig , linux-nvme@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-nvme mailing list linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme