Skip to content

Commit

Permalink
Ext4Pkg: Fix division by zero by adding check for s_inodes_per_group
Browse files Browse the repository at this point in the history
Superblock s_inodes_per_group field can't be zero, it leads to division
by zero in BlockGroup routine Ext4ReadInode

Cc: Marvin Häuser <[email protected]>
Cc: Pedro Falcato <[email protected]>
Cc: Vitaly Cheptsov <[email protected]>
Fixes: d9ceedc ("Ext4Pkg: Add Ext4Dxe driver.")
Signed-off-by: Savva Mitrofanov <[email protected]>
Reviewed-by: Pedro Falcato <[email protected]>
Reviewed-by: Marvin Häuser <[email protected]>
  • Loading branch information
savvamitrofanov authored and heatd committed Feb 8, 2023
1 parent 0bea20a commit d99e159
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Features/Ext4Pkg/Ext4Dxe/Superblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ Ext4OpenSuperblock (

DEBUG ((DEBUG_FS, "Read only = %u\n", Partition->ReadOnly));

if (Sb->s_inodes_per_group == 0) {
DEBUG ((DEBUG_ERROR, "[ext4] Inodes per group can not be zero\n"));
return EFI_VOLUME_CORRUPTED;
}

Partition->BlockSize = (UINT32)LShiftU64 (1024, Sb->s_log_block_size);

// The size of a block group can also be calculated as 8 * Partition->BlockSize
Expand Down

0 comments on commit d99e159

Please sign in to comment.