History

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.

Jan Kara committed 3 years ago

Commit bf470201 parent a1f46ff1 file · +2 −0Browse files

Unified · Split

fs/mpage.c+2−0
@@ -532,6 +532,8 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc, · 531 unmodified lines
532 map_bh.b_size = 1 << blkbits;532 map_bh.b_size = 1 << blkbits;
533 if (mpd->get_block(inode, block_in_file, &map_bh, 1))533 if (mpd->get_block(inode, block_in_file, &map_bh, 1))
534 goto confused;534 goto confused;
535 if (!buffer_mapped(&map_bh))
536 goto confused;
535 if (buffer_new(&map_bh))537 if (buffer_new(&map_bh))
536 clean_bdev_bh_alias(&map_bh);538 clean_bdev_bh_alias(&map_bh);
537 if (buffer_boundary(&map_bh)) {539 if (buffer_boundary(&map_bh)) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t