* [PATCH] fs: gracefully handle ->get_block not mapping bh in __mpage_writepage
@ 2023-01-26 8:51 Jan Kara
2023-01-26 15:15 ` Christoph Hellwig
2023-01-26 19:54 ` Andrew Morton
0 siblings, 2 replies; 4+ messages in thread
From: Jan Kara @ 2023-01-26 8:51 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Christoph Hellwig, Andrew Morton, Matthew Wilcox, Jan Kara
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.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/mpage.c | 2 ++
1 file changed, 2 insertions(+)
I'd like to get this patch merged through my tree as other UDF fixes depend on
it and without this change the kernel crashes in unfortunate ways.
diff --git a/fs/mpage.c b/fs/mpage.c
index 9f040c1d5912..8bd77a8e2627 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -538,6 +538,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)) {
--
2.35.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] fs: gracefully handle ->get_block not mapping bh in __mpage_writepage
2023-01-26 8:51 [PATCH] fs: gracefully handle ->get_block not mapping bh in __mpage_writepage Jan Kara
@ 2023-01-26 15:15 ` Christoph Hellwig
2023-01-26 19:54 ` Andrew Morton
1 sibling, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2023-01-26 15:15 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-fsdevel, Christoph Hellwig, Andrew Morton, Matthew Wilcox
On Thu, Jan 26, 2023 at 09:51:55AM +0100, Jan Kara wrote:
> 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.
Yes, this matches what the buffer.c helpers do, so:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fs: gracefully handle ->get_block not mapping bh in __mpage_writepage
2023-01-26 8:51 [PATCH] fs: gracefully handle ->get_block not mapping bh in __mpage_writepage Jan Kara
2023-01-26 15:15 ` Christoph Hellwig
@ 2023-01-26 19:54 ` Andrew Morton
2023-01-27 13:32 ` Jan Kara
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2023-01-26 19:54 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-fsdevel, Christoph Hellwig, Matthew Wilcox
On Thu, 26 Jan 2023 09:51:55 +0100 Jan Kara <jack@suse.cz> wrote:
> When filesystem's ->get_block function does not map the buffer head when
> called from __mpage_writepage(), the function will happily go and pass
"the function" being __mpage_writepage(), not ->get_block()...
> bogus bdev and block number to bio allocation routines which leads to
> crashes sooner or later.
Crashes are unwelcome. How is this bug triggered? Should we backport
the fix? I assume this is a longstanding thing and that any Fixes:
target would be ancient? If ancient, why did it take so long to
discover?
> 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.
>
> ...
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fs: gracefully handle ->get_block not mapping bh in __mpage_writepage
2023-01-26 19:54 ` Andrew Morton
@ 2023-01-27 13:32 ` Jan Kara
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2023-01-27 13:32 UTC (permalink / raw)
To: Andrew Morton; +Cc: Jan Kara, linux-fsdevel, Christoph Hellwig, Matthew Wilcox
On Thu 26-01-23 11:54:55, Andrew Morton wrote:
> On Thu, 26 Jan 2023 09:51:55 +0100 Jan Kara <jack@suse.cz> wrote:
>
> > When filesystem's ->get_block function does not map the buffer head when
> > called from __mpage_writepage(), the function will happily go and pass
>
> "the function" being __mpage_writepage(), not ->get_block()...
Ah, right :)
> > bogus bdev and block number to bio allocation routines which leads to
> > crashes sooner or later.
>
> Crashes are unwelcome. How is this bug triggered? Should we backport
> the fix? I assume this is a longstanding thing and that any Fixes:
> target would be ancient? If ancient, why did it take so long to
> discover?
fsstress was able to trigger the problem for UDF. The problem is there likely
since the time __mpage_writepage() was created (definitely pre-git). But
usually filesystems using mpage_writepages() just allocate blocks in their
->get_block() method so the problem was not visible until I've changed UDF
to not allocate blocks from page writeback (to fix some other bug).
For that reason, I'm actually carrying this change in my tree so that I
don't get swamped with 0-day and syzbot reports on that offending UDF fix.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-27 13:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-26 8:51 [PATCH] fs: gracefully handle ->get_block not mapping bh in __mpage_writepage Jan Kara
2023-01-26 15:15 ` Christoph Hellwig
2023-01-26 19:54 ` Andrew Morton
2023-01-27 13:32 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).