lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4F42DBA0.4090502@redhat.com>
Date:	Mon, 20 Feb 2012 17:47:44 -0600
From:	Eric Sandeen <sandeen@...hat.com>
To:	Haogang Chen <haogangchen@...il.com>
CC:	Theodore Tso <tytso@....edu>,
	Andreas Dilger <adilger.kernel@...ger.ca>,
	linux-ext4@...r.kernel.org, linux-kernel@...r.kernel.org,
	Yongqiang Yang <xiaoqiangnk@...il.com>
Subject: Re: [PATCH] FS: ext4: fix integer overflow in alloc_flex_gd()

On 2/20/12 4:41 PM, Haogang Chen wrote:
> In alloc_flex_gd(), when flexbg_size is large, kmalloc size would
> overflow and flex_gd->groups would point to a buffer smaller than
> expected, causing OOB accesses when it is used.
> 
> Note that in ext4_resize_fs(), flexbg_size is calculated using
> sbi->s_log_groups_per_flex, which is read from the disk and only bounded
> to [1, 31]. The patch returns NULL for too large flexbg_size

Hm this raises a few questions I think.

On the one hand, making sure the kmalloc arg doesn't overflow here is
certainly a good thing and probably the right thing to do in the short term.

So I guess:

Reviewed-by: Eric Sandeen <sandeen@...hat.com>

for that, to close the hole.

But the types are a mess; alloc_flex_gd() takes an unsigned long; 
it's passed an int, and assigns to flex_gd->count, an ext4_group_t
(which is an unsigned int). They should probably all be ext4_group_t
for consistency.

But that's not the worst of it...

Doesn't this also mean that a valid s_log_groups_per_flex (i.e. 31)
will fail in this resize code?  That would be an unexpected outcome.
2^31 groups per flex is a little crazy, but still technically valid
according to the limits in the code.

So really, trying to allocate an array of all possible groups-per-flex
in the resize code is probably a really bad idea to start with, and the
resize code has got serious problems if kmalloc(UINT_MAX-1) is expected
to work...

-Eric

> Signed-off-by: Haogang Chen <haogangchen@...il.com>
> ---
>  fs/ext4/resize.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
> index f9d948f..8601f4b 100644
> --- a/fs/ext4/resize.c
> +++ b/fs/ext4/resize.c
> @@ -161,6 +161,8 @@ static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned long flexbg_size)
>  	if (flex_gd == NULL)
>  		goto out3;
>  
> +	if (flexbg_size >= UINT_MAX / sizeof(struct ext4_new_flex_group_data))
> +		goto out2;
>  	flex_gd->count = flexbg_size;
>  
>  	flex_gd->groups = kmalloc(sizeof(struct ext4_new_group_data) *

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ