* [PATCH] ext4: avoid oversized shift in ext4_fill_flex_info()
@ 2011-12-26 6:36 Xi Wang
2011-12-26 7:20 ` Andreas Dilger
0 siblings, 1 reply; 3+ messages in thread
From: Xi Wang @ 2011-12-26 6:36 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger; +Cc: linux-ext4, Xi Wang
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).
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;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: avoid oversized shift in ext4_fill_flex_info()
2011-12-26 6:36 [PATCH] ext4: avoid oversized shift in ext4_fill_flex_info() Xi Wang
@ 2011-12-26 7:20 ` Andreas Dilger
2011-12-27 2:26 ` Xi Wang
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Dilger @ 2011-12-26 7:20 UTC (permalink / raw)
To: Xi Wang
Cc: Theodore Ts'o, Andreas Dilger, linux-ext4@vger.kernel.org,
Xi Wang
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
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] ext4: avoid oversized shift in ext4_fill_flex_info()
2011-12-26 7:20 ` Andreas Dilger
@ 2011-12-27 2:26 ` Xi Wang
0 siblings, 0 replies; 3+ messages in thread
From: Xi Wang @ 2011-12-27 2:26 UTC (permalink / raw)
To: Andreas Dilger
Cc: Theodore Ts'o, Andreas Dilger, linux-ext4@vger.kernel.org
On Dec 26, 2011, at 2:20 AM, Andreas Dilger wrote:
> 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.
This patch is based on commit 503358ae "ext4: avoid divide by zero
when trying to mount a corrupted file system", as I quote: "If
s_log_groups_per_flex is greater than 31, then groups_per_flex will
will overflow and cause a divide by zero error." The intent is to
avoid oversized shift in that commit, because the behavior is
undefined in C and may vary on different architectures.
My understanding is that sbi->s_es->s_log_groups_per_flex needs a
sanity check if it is read from a malicious or corrupted filesystem
in ext4_fill_flex_info(), which is called from ext4_fill_super().
Did I miss anything?
- xi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-12-27 2:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-26 6:36 [PATCH] ext4: avoid oversized shift in ext4_fill_flex_info() Xi Wang
2011-12-26 7:20 ` Andreas Dilger
2011-12-27 2:26 ` Xi Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox