ext2: fix sleeping in atomic bugs on error
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 21 Sep 2021 20:32:33 +0000 (23:32 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 9 Oct 2021 11:25:59 +0000 (13:25 +0200)
[ Upstream commit 372d1f3e1bfede719864d0d1fbf3146b1e638c88 ]

The ext2_error() function syncs the filesystem so it sleeps.  The caller
is holding a spinlock so it's not allowed to sleep.

   ext2_statfs() <- disables preempt
   -> ext2_count_free_blocks()
      -> ext2_get_group_desc()

Fix this by using WARN() to print an error message and a stack trace
instead of using ext2_error().

Link: https://lore.kernel.org/r/20210921203233.GA16529@kili
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ext2/balloc.c

index 4c40c0786e168bf1c9c92a5c9afe3d538f63142f..bd32140bdfee54bfc4848551a807b4a1846bd567 100644 (file)
@@ -46,10 +46,9 @@ struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
        struct ext2_sb_info *sbi = EXT2_SB(sb);
 
        if (block_group >= sbi->s_groups_count) {
-               ext2_error (sb, "ext2_get_group_desc",
-                           "block_group >= groups_count - "
-                           "block_group = %d, groups_count = %lu",
-                           block_group, sbi->s_groups_count);
+               WARN(1, "block_group >= groups_count - "
+                    "block_group = %d, groups_count = %lu",
+                    block_group, sbi->s_groups_count);
 
                return NULL;
        }
@@ -57,10 +56,9 @@ struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
        group_desc = block_group >> EXT2_DESC_PER_BLOCK_BITS(sb);
        offset = block_group & (EXT2_DESC_PER_BLOCK(sb) - 1);
        if (!sbi->s_group_desc[group_desc]) {
-               ext2_error (sb, "ext2_get_group_desc",
-                           "Group descriptor not loaded - "
-                           "block_group = %d, group_desc = %lu, desc = %lu",
-                            block_group, group_desc, offset);
+               WARN(1, "Group descriptor not loaded - "
+                    "block_group = %d, group_desc = %lu, desc = %lu",
+                     block_group, group_desc, offset);
                return NULL;
        }