2023-06-14 10:22:18

by Fabio M. De Francesco

[permalink] [raw]
Subject: [PATCH] ext4: Drop the call to ext4_error() from ext4_get_group_info()

A recent patch added a call to ext4_error() which is problematic since
some callers of the ext4_get_group_info() function may be holding a
spinlock, whereas ext4_error() must never be called in atomic context.

This triggered a report from Syzbot: "BUG: sleeping function called from
invalid context in ext4_update_super" (see the link below).

Therefore, drop the call to ext4_error() from ext4_get_group_info(). In
the meantime use eight characters tabs instead of nine characters ones.

Reported-by: [email protected]
Closes: https://lore.kernel.org/all/[email protected]/
Fixes: 5354b2af3406 ("ext4: allow ext4_get_group_info() to fail")
Suggested-by: Theodore Ts'o <[email protected]>
Signed-off-by: Fabio M. De Francesco <[email protected]>
---
fs/ext4/balloc.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index c1edde817be8..e8da678a0103 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -324,17 +324,15 @@ static ext4_fsblk_t ext4_valid_block_bitmap_padding(struct super_block *sb,
struct ext4_group_info *ext4_get_group_info(struct super_block *sb,
ext4_group_t group)
{
- struct ext4_group_info **grp_info;
- long indexv, indexh;
-
- if (unlikely(group >= EXT4_SB(sb)->s_groups_count)) {
- ext4_error(sb, "invalid group %u", group);
- return NULL;
- }
- indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb));
- indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1);
- grp_info = sbi_array_rcu_deref(EXT4_SB(sb), s_group_info, indexv);
- return grp_info[indexh];
+ struct ext4_group_info **grp_info;
+ long indexv, indexh;
+
+ if (unlikely(group >= EXT4_SB(sb)->s_groups_count))
+ return NULL;
+ indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb));
+ indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1);
+ grp_info = sbi_array_rcu_deref(EXT4_SB(sb), s_group_info, indexv);
+ return grp_info[indexh];
}

/*
--
2.41.0



2023-06-15 15:12:59

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH] ext4: Drop the call to ext4_error() from ext4_get_group_info()


On Wed, 14 Jun 2023 12:02:55 +0200, Fabio M. De Francesco wrote:
> A recent patch added a call to ext4_error() which is problematic since
> some callers of the ext4_get_group_info() function may be holding a
> spinlock, whereas ext4_error() must never be called in atomic context.
>
> This triggered a report from Syzbot: "BUG: sleeping function called from
> invalid context in ext4_update_super" (see the link below).
>
> [...]

Applied, thanks!

[1/1] ext4: Drop the call to ext4_error() from ext4_get_group_info()
commit: f451fd97dd2b78f286379203a47d9d295c467255

Best regards,
--
Theodore Ts'o <[email protected]>