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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A587FC433EF for ; Tue, 16 Nov 2021 00:03:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88B9E61175 for ; Tue, 16 Nov 2021 00:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349132AbhKPAGX (ORCPT ); Mon, 15 Nov 2021 19:06:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:45222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345072AbhKOT0K (ORCPT ); Mon, 15 Nov 2021 14:26:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6E61663713; Mon, 15 Nov 2021 19:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637003389; bh=AtRP5XiR+CgkAOFjl+aDTVB6Zga+m98wcHP/Bzqj6Mo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cb7ghgIqR7D+OGV7A2ZaU8CITqFJSDprnlAi+f2DfsJq2fWVkRWFux+e1FtCQ0N6z Vux1vstqiK7QJj81tVB16pL2FeYWg0/ISyCS4RclL+D7nhRCM0bgWtJehlroXr7xxJ JB3wap3nbwcZeYsoJZkU4NcVzQNjo+LT8plmx5f8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coly Li , Christoph Hellwig , Hannes Reinecke , Ulf Hansson , Jens Axboe Subject: [PATCH 5.15 884/917] bcache: fix use-after-free problem in bcache_device_free() Date: Mon, 15 Nov 2021 18:06:19 +0100 Message-Id: <20211115165459.028711455@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211115165428.722074685@linuxfoundation.org> References: <20211115165428.722074685@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coly Li commit 8468f45091d2866affed6f6a7aecc20779139173 upstream. In bcache_device_free(), pointer disk is referenced still in ida_simple_remove() after blk_cleanup_disk() gets called on this pointer. This may cause a potential panic by use-after-free on the disk pointer. This patch fixes the problem by calling blk_cleanup_disk() after ida_simple_remove(). Fixes: bc70852fd104 ("bcache: convert to blk_alloc_disk/blk_cleanup_disk") Signed-off-by: Coly Li Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Ulf Hansson Cc: stable@vger.kernel.org # v5.14+ Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20211103064917.67383-1-colyli@suse.de Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -885,9 +885,9 @@ static void bcache_device_free(struct bc bcache_device_detach(d); if (disk) { - blk_cleanup_disk(disk); ida_simple_remove(&bcache_device_idx, first_minor_to_idx(disk->first_minor)); + blk_cleanup_disk(disk); } bioset_exit(&d->bio_split);