Skip to content

Commit 7cad645

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: fix ordered extent split error handling in btrfs_dio_submit_io
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. Reported-by: syzbot <syzbot+5b82f0e951f8c2bcdb8f@syzkaller.appspotmail.com> Fixes: b41b6f6 ("btrfs: use btrfs_finish_ordered_extent to complete direct writes") Reviewed-by: Josef Bacik <josef@toxicpanda.com> Tested-by: syzbot <syzbot+5b82f0e951f8c2bcdb8f@syzkaller.appspotmail.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 17b17fc commit 7cad645

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/btrfs/inode.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7873,8 +7873,11 @@ static void btrfs_dio_submit_io(const struct iomap_iter *iter, struct bio *bio,
78737873

78747874
ret = btrfs_extract_ordered_extent(bbio, dio_data->ordered);
78757875
if (ret) {
7876-
bbio->bio.bi_status = errno_to_blk_status(ret);
7877-
btrfs_dio_end_io(bbio);
7876+
btrfs_finish_ordered_extent(dio_data->ordered, NULL,
7877+
file_offset, dip->bytes,
7878+
!ret);
7879+
bio->bi_status = errno_to_blk_status(ret);
7880+
iomap_dio_bio_end_io(bio);
78787881
return;
78797882
}
78807883
}

0 commit comments

Comments
 (0)