Skip to contentSkip to conversation

ext2: replace BUG_ON with WARN_ON_ONCE in ext2_get_blocks

PATCH In review Milos Nikic 2 participants 3 messages Feb 7 – Feb 27 ext2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext2: replace BUG_ON with WARN_ON_ONCE in ext2_get_blocks

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.

---
 fs/ext2/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext2/inode.c +2 -1
index dbfe9098a124..18bf1a91dbc2 100644
@@ -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);
 
Signature · 1 line
2.52.0
#1 lore raw

Hi Jan,

Just a friendly ping on this patch now that a few weeks have passed. Let me know if you need any changes!

Thanks,
Milos

#2 lore raw
Quoted 4 lines · Milos Nikic

Hi Jan,

Just a friendly ping on this patch now that a few weeks have passed. Let me know if you need any changes!

Thanks merged now.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR