* [PATCH AUTOSEL 5.4 10/17] btrfs: handle memory allocation failure in btrfs_csum_one_bio
[not found] <20230531134502.3384828-1-sashal@kernel.org>
@ 2023-05-31 13:44 ` Sasha Levin
0 siblings, 0 replies; only message in thread
From: Sasha Levin @ 2023-05-31 13:44 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Johannes Thumshirn, syzbot+d8941552e21eac774778,
Christoph Hellwig, Anand Jain, David Sterba, Sasha Levin, clm,
josef, linux-btrfs
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
[ Upstream commit 806570c0bb7b4847828c22c4934fcf2dc8fc572f ]
Since f8a53bb58ec7 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/btrfs/file-item.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 61b82c69eed50..1a7183cdfe950 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -499,7 +499,9 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio,
sums = kvzalloc(btrfs_ordered_sum_size(fs_info,
bytes_left), GFP_KERNEL);
memalloc_nofs_restore(nofs_flag);
- BUG_ON(!sums); /* -ENOMEM */
+ if (!sums)
+ return BLK_STS_RESOURCE;
+
sums->len = bytes_left;
ordered = btrfs_lookup_ordered_extent(inode,
offset);
--
2.39.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-31 13:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20230531134502.3384828-1-sashal@kernel.org>
2023-05-31 13:44 ` [PATCH AUTOSEL 5.4 10/17] btrfs: handle memory allocation failure in btrfs_csum_one_bio Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox