From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E8FD3B9DB6; Sat, 30 May 2026 17:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780163254; cv=none; b=tCv3o+Axk0042cbRUE9Hnuyc565RlFjkweeQyNd6IaGvpGRAVassRLY+qWPeCCi1m4dK3JlQRSbo1ij5YscxWsZEZ4BjaVR9swyR7nQVLV9vJOwFnM7mHREItItWyD7Iy9p4GVncS8bpjj5Hx9LQf9YTfilVMjMoutLYEMCLM2o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780163254; c=relaxed/simple; bh=Ff64B8fWcF3F96qEgyB139FQ4e66gZ6veRtJ+rFEvYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=inAefaw+ewtTAUfB+qPyTeahqGVaMQlPwdEiLSZq3BzLFDYSfafzd/FV56oJEiXoyKk/i1jN8Vke24wLswab3ZV3n6AMWsEO3o+bYywKMbwQfkN1UqUL+i1prM8a2sBQnWVKcnZAdZZAzeUxcXhLDMinLWyYxLEWD3St3lDKYy8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PWCUQSnI; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="PWCUQSnI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DF531F00893; Sat, 30 May 2026 17:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780163252; bh=1nR4AiNfossZXVgtTJh5RFkHNG6JSqfzSyspmQSSmts=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PWCUQSnIsm5PLIBMRrX/5ZcIxFlUuZhhtuqLYn9u2g/RHNFXbwW6+mi14HRp+z8R5 YDnt7K7LPoEaQpPmqNL6ROkSdgkCAdnjeX/FmSkwPG/W6PaZCwXncUDZ5OU/gIZVkT aXUE8CONbC17tBuJF/mXXqr5ulVhrSM+9cpOVeAk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yu Kuai , Song Liu , Johnny Hao , Harshit Mogalapalli Subject: [PATCH 5.15 159/776] md/md-bitmap: Synchronize bitmap_get_stats() with bitmap lifetime Date: Sat, 30 May 2026 17:57:53 +0200 Message-ID: <20260530160244.581821421@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160240.228940103@linuxfoundation.org> References: <20260530160240.228940103@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yu Kuai [ Upstream commit 8d28d0ddb986f56920ac97ae704cc3340a699a30 ] After commit ec6bb299c7c3 ("md/md-bitmap: add 'sync_size' into struct md_bitmap_stats"), following panic is reported: Oops: general protection fault, probably for non-canonical address RIP: 0010:bitmap_get_stats+0x2b/0xa0 Call Trace: md_seq_show+0x2d2/0x5b0 seq_read_iter+0x2b9/0x470 seq_read+0x12f/0x180 proc_reg_read+0x57/0xb0 vfs_read+0xf6/0x380 ksys_read+0x6c/0xf0 do_syscall_64+0x82/0x170 entry_SYSCALL_64_after_hwframe+0x76/0x7e Root cause is that bitmap_get_stats() can be called at anytime if mddev is still there, even if bitmap is destroyed, or not fully initialized. Deferenceing bitmap in this case can crash the kernel. Meanwhile, the above commit start to deferencing bitmap->storage, make the problem easier to trigger. Fix the problem by protecting bitmap_get_stats() with bitmap_info.mutex. Cc: stable@vger.kernel.org # v6.12+ Fixes: 32a7627cf3a3 ("[PATCH] md: optimised resync using Bitmap based intent logging") Reported-and-tested-by: Harshit Mogalapalli Closes: https://lore.kernel.org/linux-raid/ca3a91a2-50ae-4f68-b317-abd9889f3907@oracle.com/T/#m6e5086c95201135e4941fe38f9efa76daf9666c5 Signed-off-by: Yu Kuai Link: https://lore.kernel.org/r/20250124092055.4050195-1-yukuai1@huaweicloud.com Signed-off-by: Song Liu [ The context change is due to the commit 38f287d7e495 ("md/md-bitmap: replace md_bitmap_status() with a new helper md_bitmap_get_stats()") in v6.12 and the commit f9cfe7e7f96a ("md: Fix md_seq_ops() regressions") in v6.8 which are irrelevant to the logic of this patch. ] Signed-off-by: Johnny Hao Signed-off-by: Greg Kroah-Hartman --- drivers/md/md-bitmap.c | 4 ++++ drivers/md/md.c | 4 ++++ 2 files changed, 8 insertions(+) --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -2033,6 +2033,10 @@ void md_bitmap_status(struct seq_file *s if (!bitmap) return; + if (bitmap->mddev->bitmap_info.external) + return; + if (!bitmap->storage.sb_page) /* no superblock */ + return; counts = &bitmap->counts; --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -8300,6 +8300,9 @@ static int md_seq_show(struct seq_file * return 0; } + /* prevent bitmap to be freed after checking */ + mutex_lock(&mddev->bitmap_info.mutex); + spin_lock(&mddev->lock); if (mddev->pers || mddev->raid_disks || !list_empty(&mddev->disks)) { seq_printf(seq, "%s : %sactive", mdname(mddev), @@ -8371,6 +8374,7 @@ static int md_seq_show(struct seq_file * seq_printf(seq, "\n"); } spin_unlock(&mddev->lock); + mutex_unlock(&mddev->bitmap_info.mutex); return 0; }