From: Andreas Dilger <aedilger@gmail.com>
To: Xi Wang <xi.wang@gmail.com>
Cc: Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
"linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>,
Xi Wang <xi.wang@gmail.com>
Subject: Re: [PATCH] ext4: avoid oversized shift in ext4_fill_flex_info()
Date: Mon, 26 Dec 2011 00:20:59 -0700 [thread overview]
Message-ID: <C0DF217A-64C8-49E3-B979-652DB2C362C3@gmail.com> (raw)
In-Reply-To: <1324881404-3791-1-git-send-email-xi.wang@gmail.com>
On 2011-12-25, at 23:36, Xi Wang <xi.wang@gmail.com> wrote:
> Commit 503358ae fixed a division by zero, but groups_per_flex still
> overflows due to an oversized shift, given a large s_log_groups_per_flex
> like 36. (1 << 36) is undefined in C; the result may vary depending
> on the architecture, e.g., 16 on x86, thus bypassing the sanity check
> (groups_per_flex < 2).
While this is true in theory, it is not possible to have 2^32 groups per flex group. This would mean 2^32 block bitmaps and inode bitmaps in a single group, which is impossible.
> Signed-off-by: Xi Wang <xi.wang@gmail.com>
> ---
> fs/ext4/super.c | 9 +++++----
> 1 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 3e1329e..6deaf41 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -2010,14 +2010,15 @@ static int ext4_fill_flex_info(struct super_block *sb)
> size_t size;
> int i;
>
> - sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
> - groups_per_flex = 1 << sbi->s_log_groups_per_flex;
> -
> - if (groups_per_flex < 2) {
> + if (sbi->s_es->s_log_groups_per_flex == 0 ||
> + sbi->s_es->s_log_groups_per_flex >= 32) {
> sbi->s_log_groups_per_flex = 0;
> return 1;
> }
>
> + sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
> + groups_per_flex = 1 << sbi->s_log_groups_per_flex;
> +
> /* We allocate both existing and potentially added groups */
> flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
> ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
> --
> 1.7.5.4
>
next prev parent reply other threads:[~2011-12-26 7:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-26 6:36 [PATCH] ext4: avoid oversized shift in ext4_fill_flex_info() Xi Wang
2011-12-26 7:20 ` Andreas Dilger [this message]
2011-12-27 2:26 ` Xi Wang
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=C0DF217A-64C8-49E3-B979-652DB2C362C3@gmail.com \
--to=aedilger@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=xi.wang@gmail.com \
/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