[Devel] [PATCH RHEL7 COMMIT] ms/ext4: potential crash on allocation error in ext4_alloc_flex_bg_array()
Konstantin Khorenko
khorenko at virtuozzo.com
Tue Mar 31 18:21:05 MSK 2020
The commit is pushed to "branch-rh7-3.10.0-1062.12.1.vz7.145.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1062.12.1.vz7.145.5
------>
commit b78dc59cabe062fd16b8ebd1bf333c6755990143
Author: Dan Carpenter <dan.carpenter at oracle.com>
Date: Tue Mar 31 18:21:05 2020 +0300
ms/ext4: potential crash on allocation error in ext4_alloc_flex_bg_array()
ms commit 37b0b6b8b99c
If sbi->s_flex_groups_allocated is zero and the first allocation fails
then this code will crash. The problem is that "i--" will set "i" to
-1 but when we compare "i >= sbi->s_flex_groups_allocated" then the -1
is type promoted to unsigned and becomes UINT_MAX. Since UINT_MAX
is more than zero, the condition is true so we call kvfree(new_groups[-1]).
The loop will carry on freeing invalid memory until it crashes.
mFixes: 7c990728b99e ("ext4: fix potential race between s_flex_groups online resizing and access")
Reviewed-by: Suraj Jitindar Singh <surajjs at amazon.com>
Signed-off-by: Dan Carpenter <dan.carpenter at oracle.com>
Cc: stable at kernel.org
Link: https://lore.kernel.org/r/20200228092142.7irbc44yaz3by7nb@kili.mountain
Signed-off-by: Theodore Ts'o <tytso at mit.edu>
https://jira.sw.ru/browse/PSBM-102478
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
fs/ext4/super.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index a6b2522655d3e..6f1fde0f42688 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2169,7 +2169,7 @@ int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)
{
struct ext4_sb_info *sbi = EXT4_SB(sb);
struct flex_groups **old_groups, **new_groups;
- int size, i;
+ int size, i, j;
if (!sbi->s_log_groups_per_flex)
return 0;
@@ -2190,8 +2190,8 @@ int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)
sizeof(struct flex_groups)),
GFP_KERNEL);
if (!new_groups[i]) {
- for (i--; i >= sbi->s_flex_groups_allocated; i--)
- kvfree(new_groups[i]);
+ for (j = sbi->s_flex_groups_allocated; j < i; j++)
+ kvfree(new_groups[j]);
kvfree(new_groups);
ext4_msg(sb, KERN_ERR,
"not enough memory for %d flex groups", size);
More information about the Devel
mailing list