summaryrefslogtreecommitdiff
path: root/fs/mpage.c
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2023-01-25 16:59:14 +0300
committerJan Kara <jack@suse.cz>2023-01-26 18:46:35 +0300
commit7010839ccfd4f875c23c1758f6321ee6312cc548 (patch)
tree171afbec4871e09f39df020db6b81a4e889d6ab6 /fs/mpage.c
parent3c21204818ae45504b5d8ce8902748ef2306f0f3 (diff)
downloadlinux-7010839ccfd4f875c23c1758f6321ee6312cc548.tar.xz
fs: gracefully handle ->get_block not mapping bh in __mpage_writepage
When filesystem's ->get_block function does not map the buffer head when called from __mpage_writepage(), the function will happily go and pass bogus bdev and block number to bio allocation routines which leads to crashes sooner or later. E.g. UDF can do this because it doesn't want to allocate blocks from ->writepages callbacks. It allocates blocks on write or page fault but writeback can still spot dirty buffers without underlying blocks allocated e.g. if blocksize < pagesize, the tail page is dirtied (which means all its buffers are dirtied), and truncate extends the file so that some buffer starts to be within i_size. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/mpage.c')
-rw-r--r--fs/mpage.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/mpage.c b/fs/mpage.c
index 0f8ae954a579..ce53179428db 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -532,6 +532,8 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
map_bh.b_size = 1 << blkbits;
if (mpd->get_block(inode, block_in_file, &map_bh, 1))
goto confused;
+ if (!buffer_mapped(&map_bh))
+ goto confused;
if (buffer_new(&map_bh))
clean_bdev_bh_alias(&map_bh);
if (buffer_boundary(&map_bh)) {