From: Andreas Dilger <adilger@whamcloud.com>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org,
Andreas Dilger <adilger@whamcloud.com>,
Andreas Dilger <adilger@dilger.ca>
Subject: [PATCH 7/9] e2fsck: fix overflow if more than 4B inodes
Date: Thu, 6 Feb 2020 18:09:44 -0700 [thread overview]
Message-ID: <1581037786-62789-7-git-send-email-adilger@whamcloud.com> (raw)
In-Reply-To: <1581037786-62789-1-git-send-email-adilger@whamcloud.com>
Even though we don't have support for filesystems with over 4B inodes
in the current e2fsprogs, this may happen in the future. There are
latent overflow bugs when calculating the number of inodes in the
filesystem that can trivially be fixed now, rather than waiting for
them to be hit at some point in the future. The block number calcs
are already correct in this code.
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
---
e2fsck/pass5.c | 2 +-
lib/ext2fs/bitmaps.c | 3 ++-
lib/ext2fs/imager.c | 6 ++++--
misc/fuse2fs.c | 2 +-
4 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c
index 3a5c88d..c1d45a5 100644
--- a/e2fsck/pass5.c
+++ b/e2fsck/pass5.c
@@ -842,7 +842,7 @@ static void check_inode_end(e2fsck_t ctx)
clear_problem_context(&pctx);
- end = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
+ end = (__u64)EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
pctx.errcode = ext2fs_fudge_inode_bitmap_end(fs->inode_map, end,
&save_inodes_count);
if (pctx.errcode) {
diff --git a/lib/ext2fs/bitmaps.c b/lib/ext2fs/bitmaps.c
index e25db2c..834a396 100644
--- a/lib/ext2fs/bitmaps.c
+++ b/lib/ext2fs/bitmaps.c
@@ -62,7 +62,8 @@ errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
start = 1;
end = fs->super->s_inodes_count;
- real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count);
+ real_end = (__u64)EXT2_INODES_PER_GROUP(fs->super) *
+ fs->group_desc_count;
/* Are we permitted to use new-style bitmaps? */
if (fs->flags & EXT2_FLAG_64BITS)
diff --git a/lib/ext2fs/imager.c b/lib/ext2fs/imager.c
index fee27ac..09cd508 100644
--- a/lib/ext2fs/imager.c
+++ b/lib/ext2fs/imager.c
@@ -344,7 +344,8 @@ errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags)
}
bmap = fs->inode_map;
itr = 1;
- cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
+ cnt = (__u64)EXT2_INODES_PER_GROUP(fs->super) *
+ fs->group_desc_count;
size = (EXT2_INODES_PER_GROUP(fs->super) / 8);
} else {
if (!fs->block_map) {
@@ -419,7 +420,8 @@ errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags)
}
bmap = fs->inode_map;
itr = 1;
- cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
+ cnt = (__u64)EXT2_INODES_PER_GROUP(fs->super) *
+ fs->group_desc_count;
size = (EXT2_INODES_PER_GROUP(fs->super) / 8);
} else {
if (!fs->block_map) {
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index be2cd1d..31493e2 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -2364,7 +2364,7 @@ static int op_statfs(const char *path EXT2FS_ATTR((unused)),
overhead = 0;
else
overhead = fs->desc_blocks +
- fs->group_desc_count *
+ (blk64_t)fs->group_desc_count *
(fs->inode_blocks_per_group + 2);
reserved = ext2fs_r_blocks_count(fs->super);
if (!reserved)
--
1.8.0
next prev parent reply other threads:[~2020-02-07 1:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-07 1:09 [PATCH 1/9] e2fsck: fix e2fsck_allocate_memory() overflow Andreas Dilger
2020-02-07 1:09 ` [PATCH 2/9] e2fsck: use proper types for variables Andreas Dilger
2020-02-29 23:27 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 3/9] e2fsck: avoid mallinfo() if over 2GB allocated Andreas Dilger
2020-02-29 23:28 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 4/9] e2fsck: reduce memory usage for many directories Andreas Dilger
2020-02-29 23:29 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 5/9] debugfs: allow comment lines in command file Andreas Dilger
2020-02-29 23:32 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 6/9] debugfs: print inode numbers as unsigned Andreas Dilger
2020-02-29 23:34 ` Theodore Y. Ts'o
2020-02-07 1:09 ` Andreas Dilger [this message]
2020-02-29 23:35 ` [PATCH 7/9] e2fsck: fix overflow if more than 4B inodes Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 8/9] e2fsck: consistently use ext2fs_get_mem() Andreas Dilger
2020-02-29 23:36 ` Theodore Y. Ts'o
2020-03-04 23:23 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 9/9] misc: handle very large files with filefrag Andreas Dilger
2020-03-04 23:27 ` Theodore Y. Ts'o
2020-02-12 0:58 ` [PATCH] " Andreas Dilger
2020-02-12 1:09 ` Andreas Dilger
2020-02-12 1:07 ` [PATCH] e2fsck: avoid overflow with very large dirs Andreas Dilger
2020-03-04 23:39 ` Theodore Y. Ts'o
2020-02-29 23:25 ` [PATCH 1/9] e2fsck: fix e2fsck_allocate_memory() overflow Theodore Y. Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1581037786-62789-7-git-send-email-adilger@whamcloud.com \
--to=adilger@whamcloud.com \
--cc=adilger@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).