Patch "md/md-bitmap: Synchronize bitmap_get_stats() with bitmap lifetime" has been added to the 6.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    md/md-bitmap: Synchronize bitmap_get_stats() with bitmap lifetime

to the 6.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     md-md-bitmap-synchronize-bitmap_get_stats-with-bitma.patch
and it can be found in the queue-6.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit f41040c9cfcd2ca71a95fabf83b861188d8118c7
Author: Yu Kuai <yukuai3@xxxxxxxxxx>
Date:   Fri Jan 24 17:20:55 2025 +0800

    md/md-bitmap: Synchronize bitmap_get_stats() with bitmap lifetime
    
    [ 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:
     <TASK>
     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@xxxxxxxxxxxxxxx # v6.12+
    Fixes: 32a7627cf3a3 ("[PATCH] md: optimised resync using Bitmap based intent logging")
    Reported-and-tested-by: Harshit Mogalapalli <harshit.m.mogalapalli@xxxxxxxxxx>
    Closes: https://lore.kernel.org/linux-raid/ca3a91a2-50ae-4f68-b317-abd9889f3907@xxxxxxxxxx/T/#m6e5086c95201135e4941fe38f9efa76daf9666c5
    Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20250124092055.4050195-1-yukuai1@xxxxxxxxxxxxxxx
    Signed-off-by: Song Liu <song@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 80b0cd7b88995..deb40a8ba3999 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2119,7 +2119,10 @@ int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
 
 	if (!bitmap)
 		return -ENOENT;
-
+	if (bitmap->mddev->bitmap_info.external)
+		return -ENOENT;
+	if (!bitmap->storage.sb_page) /* no superblock */
+		return -EINVAL;
 	sb = kmap_local_page(bitmap->storage.sb_page);
 	stats->sync_size = le64_to_cpu(sb->sync_size);
 	kunmap_local(sb);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index b73649fd8e039..534c4efd935f6 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -8327,6 +8327,10 @@ static int md_seq_show(struct seq_file *seq, void *v)
 		return 0;
 
 	spin_unlock(&all_mddevs_lock);
+
+	/* 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),
@@ -8397,6 +8401,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
 		seq_printf(seq, "\n");
 	}
 	spin_unlock(&mddev->lock);
+	mutex_unlock(&mddev->bitmap_info.mutex);
 	spin_lock(&all_mddevs_lock);
 	if (atomic_dec_and_test(&mddev->active))
 		__mddev_put(mddev);




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux