Skip to content

Commit 46ef85f

Browse files
jinpuwanghailan94
authored andcommitted
md/bitmap: fix GPF in write_page caused by resize race
A General Protection Fault occurs in write_page() during array resize: RIP: 0010:write_page+0x22b/0x3c0 [md_mod] This is a use-after-free race between bitmap_daemon_work() and __bitmap_resize(). The daemon iterates over `bitmap->storage.filemap` without locking, while the resize path frees that storage via md_bitmap_file_unmap(). `quiesce()` does not stop the md thread, allowing concurrent access to freed pages. Fix by holding `mddev->bitmap_info.mutex` during the bitmap update. Link: https://lore.kernel.org/linux-raid/[email protected] Closes: https://lore.kernel.org/linux-raid/CAMGffE=Mbfp=7xD_hYxXk1PAaCZNSEAVeQGKGy7YF9f2S4=NEA@mail.gmail.com/T/#u Cc: [email protected] Fixes: d60b479 ("md/bitmap: add bitmap_resize function to allow bitmap resizing.") Signed-off-by: Jack Wang <[email protected]> Signed-off-by: Yu Kuai <[email protected]>
1 parent d119bd2 commit 46ef85f

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

drivers/md/md-bitmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2453,6 +2453,7 @@ static int __bitmap_resize(struct bitmap *bitmap, sector_t blocks,
24532453
memcpy(page_address(store.sb_page),
24542454
page_address(bitmap->storage.sb_page),
24552455
sizeof(bitmap_super_t));
2456+
mutex_lock(&bitmap->mddev->bitmap_info.mutex);
24562457
spin_lock_irq(&bitmap->counts.lock);
24572458
md_bitmap_file_unmap(&bitmap->storage);
24582459
bitmap->storage = store;
@@ -2560,7 +2561,7 @@ static int __bitmap_resize(struct bitmap *bitmap, sector_t blocks,
25602561
set_page_attr(bitmap, i, BITMAP_PAGE_DIRTY);
25612562
}
25622563
spin_unlock_irq(&bitmap->counts.lock);
2563-
2564+
mutex_unlock(&bitmap->mddev->bitmap_info.mutex);
25642565
if (!init) {
25652566
__bitmap_unplug(bitmap);
25662567
bitmap->mddev->pers->quiesce(bitmap->mddev, 0);

0 commit comments

Comments
 (0)