[01/10] libext2fs: Fix possible inode count overflow when creating fs

Message ID 20180612095328.5215-2-jack@suse.cz
State Accepted, archived
Headers show
Series
  • e2fsprogs: Handle s_inodes_count overflow better
Related show

Commit Message

Jan Kara June 12, 2018, 9:53 a.m.
If blocks count is exactly 1<<32, then the code computing number of
inode count in ext2fs_initialize() will overflow and set number of
inodes to 0 (which will be later fixed up to EXT2_FIRST_INODE(super)+1).
Fix the off-by-one bug in the check.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 lib/ext2fs/initialize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Theodore Y. Ts'o June 19, 2018, 3:20 a.m. | #1
On Tue, Jun 12, 2018 at 11:53:19AM +0200, Jan Kara wrote:
> If blocks count is exactly 1<<32, then the code computing number of
> inode count in ext2fs_initialize() will overflow and set number of
> inodes to 0 (which will be later fixed up to EXT2_FIRST_INODE(super)+1).
> Fix the off-by-one bug in the check.
> 
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> Signed-off-by: Jan Kara <jack@suse.cz>

Applied, thanks.

					- Ted

Patch

diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index dbe798b27826..e1eff22eac33 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -295,7 +295,7 @@  retry:
 	i = fs->blocksize >= 4096 ? 1 : 4096 / fs->blocksize;
 
 	if (ext2fs_has_feature_64bit(super) &&
-	    (ext2fs_blocks_count(super) / i) > (1ULL << 32))
+	    (ext2fs_blocks_count(super) / i) >= (1ULL << 32))
 		set_field(s_inodes_count, ~0U);
 	else
 		set_field(s_inodes_count, ext2fs_blocks_count(super) / i);