All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio
@ 2023-05-04 11:58 Johannes Thumshirn
  2023-05-04 14:03 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2023-05-04 11:58 UTC (permalink / raw)
  To: David Sterba; +Cc: linux-btrfs, Johannes Thumshirn, syzbot+d8941552e21eac774778

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
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 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 bda1a4109160..e74b9804bcde 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -792,7 +792,9 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio)
 				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.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio
  2023-05-04 11:58 [PATCH] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio Johannes Thumshirn
@ 2023-05-04 14:03 ` Christoph Hellwig
  2023-05-05  6:26 ` Anand Jain
  2023-05-10 13:05 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2023-05-04 14:03 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: David Sterba, linux-btrfs, syzbot+d8941552e21eac774778

On Thu, May 04, 2023 at 01:58:13PM +0200, Johannes Thumshirn wrote:
> 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().

Not BUG()ing here is an obvious improvement, so:

Reviewed-by: Christoph Hellwig <hch@lst.de>

But if this allocation can actually fail, this just means this failure
now means writeback under memory pressure can't make progress and the
inode is now toast.  So we really need to look into something like a
mempool here in the longer run.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio
  2023-05-04 11:58 [PATCH] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio Johannes Thumshirn
  2023-05-04 14:03 ` Christoph Hellwig
@ 2023-05-05  6:26 ` Anand Jain
  2023-05-10 13:05 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Anand Jain @ 2023-05-05  6:26 UTC (permalink / raw)
  To: Johannes Thumshirn, David Sterba; +Cc: linux-btrfs, syzbot+d8941552e21eac774778

LGTM.
Reviewed-by: Anand Jain <anand.jain@oracle.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio
  2023-05-04 11:58 [PATCH] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio Johannes Thumshirn
  2023-05-04 14:03 ` Christoph Hellwig
  2023-05-05  6:26 ` Anand Jain
@ 2023-05-10 13:05 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2023-05-10 13:05 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: David Sterba, linux-btrfs, syzbot+d8941552e21eac774778

On Thu, May 04, 2023 at 01:58:13PM +0200, Johannes Thumshirn wrote:
> 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
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Added to misc-next, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-10 13:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04 11:58 [PATCH] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio Johannes Thumshirn
2023-05-04 14:03 ` Christoph Hellwig
2023-05-05  6:26 ` Anand Jain
2023-05-10 13:05 ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.