* [PATCH] btrfs: fix ordered extent split error handling in btrfs_dio_submit_io
@ 2023-07-14 8:42 Christoph Hellwig
2023-07-14 14:04 ` Josef Bacik
2023-07-17 23:46 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: Christoph Hellwig @ 2023-07-14 8:42 UTC (permalink / raw)
To: clm, josef, dsterba; +Cc: linux-btrfs, syzbot
When the call to btrfs_extract_ordered_extent in btrfs_dio_submit_io
fails to allocate memory for a new ordered_extent, it calls into the
btrfs_dio_end_io for error handling. btrfs_dio_end_io then assumes that
bbio->ordered is set because it is supposed to be at this point, except
for this error handling corner case. Try to not overload the
btrfs_dio_end_io with error handling of a bio in a non-canonical state,
and instead call btrfs_finish_ordered_extent and iomap_dio_bio_end_io
directly for this error case.
Fixes: b41b6f6937dc ("btrfs: use btrfs_finish_ordered_extent to complete direct writes")
Reported-by: syzbot <syzbot+5b82f0e951f8c2bcdb8f@syzkaller.appspotmail.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: syzbot <syzbot+5b82f0e951f8c2bcdb8f@syzkaller.appspotmail.com>
---
fs/btrfs/inode.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index dbbb67293e345c..a7064c2bee5b8e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7849,8 +7849,11 @@ static void btrfs_dio_submit_io(const struct iomap_iter *iter, struct bio *bio,
ret = btrfs_extract_ordered_extent(bbio, dio_data->ordered);
if (ret) {
- bbio->bio.bi_status = errno_to_blk_status(ret);
- btrfs_dio_end_io(bbio);
+ btrfs_finish_ordered_extent(dio_data->ordered, NULL,
+ file_offset, dip->bytes,
+ !ret);
+ bio->bi_status = errno_to_blk_status(ret);
+ iomap_dio_bio_end_io(bio);
return;
}
}
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: fix ordered extent split error handling in btrfs_dio_submit_io
2023-07-14 8:42 [PATCH] btrfs: fix ordered extent split error handling in btrfs_dio_submit_io Christoph Hellwig
@ 2023-07-14 14:04 ` Josef Bacik
2023-07-17 23:46 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2023-07-14 14:04 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: clm, dsterba, linux-btrfs, syzbot
On Fri, Jul 14, 2023 at 10:42:41AM +0200, Christoph Hellwig wrote:
> When the call to btrfs_extract_ordered_extent in btrfs_dio_submit_io
> fails to allocate memory for a new ordered_extent, it calls into the
> btrfs_dio_end_io for error handling. btrfs_dio_end_io then assumes that
> bbio->ordered is set because it is supposed to be at this point, except
> for this error handling corner case. Try to not overload the
> btrfs_dio_end_io with error handling of a bio in a non-canonical state,
> and instead call btrfs_finish_ordered_extent and iomap_dio_bio_end_io
> directly for this error case.
>
> Fixes: b41b6f6937dc ("btrfs: use btrfs_finish_ordered_extent to complete direct writes")
> Reported-by: syzbot <syzbot+5b82f0e951f8c2bcdb8f@syzkaller.appspotmail.com>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Tested-by: syzbot <syzbot+5b82f0e951f8c2bcdb8f@syzkaller.appspotmail.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: fix ordered extent split error handling in btrfs_dio_submit_io
2023-07-14 8:42 [PATCH] btrfs: fix ordered extent split error handling in btrfs_dio_submit_io Christoph Hellwig
2023-07-14 14:04 ` Josef Bacik
@ 2023-07-17 23:46 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2023-07-17 23:46 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: clm, josef, dsterba, linux-btrfs, syzbot
On Fri, Jul 14, 2023 at 10:42:41AM +0200, Christoph Hellwig wrote:
> When the call to btrfs_extract_ordered_extent in btrfs_dio_submit_io
> fails to allocate memory for a new ordered_extent, it calls into the
> btrfs_dio_end_io for error handling. btrfs_dio_end_io then assumes that
> bbio->ordered is set because it is supposed to be at this point, except
> for this error handling corner case. Try to not overload the
> btrfs_dio_end_io with error handling of a bio in a non-canonical state,
> and instead call btrfs_finish_ordered_extent and iomap_dio_bio_end_io
> directly for this error case.
>
> Fixes: b41b6f6937dc ("btrfs: use btrfs_finish_ordered_extent to complete direct writes")
> Reported-by: syzbot <syzbot+5b82f0e951f8c2bcdb8f@syzkaller.appspotmail.com>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Tested-by: syzbot <syzbot+5b82f0e951f8c2bcdb8f@syzkaller.appspotmail.com>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-17 23:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-14 8:42 [PATCH] btrfs: fix ordered extent split error handling in btrfs_dio_submit_io Christoph Hellwig
2023-07-14 14:04 ` Josef Bacik
2023-07-17 23:46 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox