]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ext2: replace BUG_ON with WARN_ON_ONCE in ext2_get_blocks
authorMilos Nikic <nikic.milos@gmail.com>
Sat, 7 Feb 2026 01:06:17 +0000 (17:06 -0800)
committerJan Kara <jack@suse.cz>
Fri, 27 Feb 2026 11:15:26 +0000 (12:15 +0100)
If ext2_get_blocks() is called with maxblocks == 0, it currently triggers
a BUG_ON(), causing a kernel panic.

While this condition implies a logic error in the caller, a filesystem
should not crash the system due to invalid arguments.

Replace the BUG_ON() with a WARN_ON_ONCE() to provide a stack trace for
debugging, and return -EINVAL to handle the error gracefully.

Signed-off-by: Milos Nikic <nikic.milos@gmail.com>
Link: https://patch.msgid.link/20260207010617.216675-1-nikic.milos@gmail.com
Signed-off-by: Jan Kara <jack@suse.cz>
fs/ext2/inode.c

index dbfe9098a1245d97ba97cff24395754197043c33..18bf1a91dbc24b426f353ff6463a09f526d86834 100644 (file)
@@ -638,7 +638,8 @@ static int ext2_get_blocks(struct inode *inode,
        int count = 0;
        ext2_fsblk_t first_block = 0;
 
-       BUG_ON(maxblocks == 0);
+       if (WARN_ON_ONCE(maxblocks == 0))
+               return -EINVAL;
 
        depth = ext2_block_to_path(inode,iblock,offsets,&blocks_to_boundary);