2023-03-23 15:07:07

by Jan Kara

[permalink] [raw]
Subject: [PATCH 2/2] ext4: Fix crash on shutdown filesystem

Test generic/388 triggered a crash in mpage_release_unused_pages()
because a page in mpd->first_page..mpd->next_page range was not locked.
This can happen in data=journal mode when we exit from
mpage_prepare_extent_to_map() before actually initializing
mpd->next_page. Move the initialization to a place before we can exit
with error from mpage_prepare_extent_to_map().

Fixes: f7233fb54d18 ("ext4: Convert data=journal writeback to use ext4_writepages()")
Signed-off-by: Jan Kara <[email protected]>
---
fs/ext4/inode.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 15bac8181798..dbcc8b48c7ba 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2428,6 +2428,8 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
else
tag = PAGECACHE_TAG_DIRTY;

+ mpd->map.m_len = 0;
+ mpd->next_page = index;
/*
* Start a transaction for writeback of journalled data. We don't start
* the transaction if the filesystem is frozen. In that case we
@@ -2443,8 +2445,6 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
return PTR_ERR(handle);
}
folio_batch_init(&fbatch);
- mpd->map.m_len = 0;
- mpd->next_page = index;
while (index <= end) {
nr_folios = filemap_get_folios_tag(mapping, &index, end,
tag, &fbatch);
--
2.35.3