diff mbox series

[02/10] ext2fs: Fix overflow when checking s_inodes_count in ext2fs_open()

Message ID 20180530125118.25274-3-jack@suse.cz
State Superseded, archived
Headers show
Series e2fsprogs: Handle s_inodes_count overflow better | expand

Commit Message

Jan Kara May 30, 2018, 12:51 p.m. UTC
The check whether s_inodes_count is correct in ext2fs_open() can
overflow and thus not catch all problematic cases. Fix the test.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 lib/ext2fs/openfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Dilger June 4, 2018, 4:21 a.m. UTC | #1
On May 30, 2018, at 6:51 AM, Jan Kara <jack@suse.cz> wrote:
> 
> The check whether s_inodes_count is correct in ext2fs_open() can
> overflow and thus not catch all problematic cases. Fix the test.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>

Not sure if "__u64" is exactly the best type there, since that is
normally for on-disk types.  Maybe "u64" or "unsigned long long"
would be better, but not really a reason to redo the patch by itself.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> lib/ext2fs/openfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
> index 532e70f7f645..e9ad0cd1a2c6 100644
> --- a/lib/ext2fs/openfs.c
> +++ b/lib/ext2fs/openfs.c
> @@ -386,7 +386,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
> 		goto cleanup;
> 	}
> 	fs->group_desc_count = 	groups_cnt;
> -	if (fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) !=
> +	if ((__u64)fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) !=
> 	    fs->super->s_inodes_count) {
> 		retval = EXT2_ET_CORRUPT_SUPERBLOCK;
> 		goto cleanup;
> --
> 2.13.6
> 


Cheers, Andreas
diff mbox series

Patch

diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 532e70f7f645..e9ad0cd1a2c6 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -386,7 +386,7 @@  errcode_t ext2fs_open2(const char *name, const char *io_options,
 		goto cleanup;
 	}
 	fs->group_desc_count = 	groups_cnt;
-	if (fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) !=
+	if ((__u64)fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) !=
 	    fs->super->s_inodes_count) {
 		retval = EXT2_ET_CORRUPT_SUPERBLOCK;
 		goto cleanup;