Skip to content

Commit 806570c

Browse files
morbidrsakdave
authored andcommitted
btrfs: handle memory allocation failure in btrfs_csum_one_bio
Since f8a53bb ("btrfs: handle checksum generation in the storage layer") the failures of btrfs_csum_one_bio() are handled via bio_end_io(). This means, we can return BLK_STS_RESOURCE from btrfs_csum_one_bio() in case the allocation of the ordered sums fails. This also fixes a syzkaller report, where injecting a failure into the kvzalloc() call results in a BUG_ON(). Reported-by: syzbot+d8941552e21eac774778@syzkaller.appspotmail.com Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 7561551 commit 806570c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/btrfs/file-item.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,9 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio)
792792
sums = kvzalloc(btrfs_ordered_sum_size(fs_info,
793793
bytes_left), GFP_KERNEL);
794794
memalloc_nofs_restore(nofs_flag);
795-
BUG_ON(!sums); /* -ENOMEM */
795+
if (!sums)
796+
return BLK_STS_RESOURCE;
797+
796798
sums->len = bytes_left;
797799
ordered = btrfs_lookup_ordered_extent(inode,
798800
offset);

0 commit comments

Comments
 (0)