Skip to content

Commit bf47020

Browse files
jankaraakpm00
authored andcommitted
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(), __mpage_writepage() 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. Link: https://lkml.kernel.org/r/20230126085155.26395-1-jack@suse.cz Signed-off-by: Jan Kara <jack@suse.cz> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Matthew Wilcox <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent a1f46ff commit bf47020

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

fs/mpage.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
532532
map_bh.b_size = 1 << blkbits;
533533
if (mpd->get_block(inode, block_in_file, &map_bh, 1))
534534
goto confused;
535+
if (!buffer_mapped(&map_bh))
536+
goto confused;
535537
if (buffer_new(&map_bh))
536538
clean_bdev_bh_alias(&map_bh);
537539
if (buffer_boundary(&map_bh)) {

0 commit comments

Comments
 (0)