linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: don't kfree uninitialized s_group_info members
@ 2011-03-10 23:03 Eric Sandeen
  2011-03-22  1:27 ` Ted Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Sandeen @ 2011-03-10 23:03 UTC (permalink / raw)
  To: ext4 development; +Cc: dame_eugene

Per kernel.org bugzilla #30872 we may call kfree on uninitialized
members of the s_group_info array.  We can avoid this by kzalloc'ing
the array, and only freeing them on the error path if they are
non-zero.

This doesn't entirely solve the oops on mount if we fail down this
path; failed_mount4: frees the sbi, for one, which gets referenced
later in the failed mount paths - I haven't worked that out yet.

Reported-by: Eugene A. Shatokhin <dame_eugene@mail.ru>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index d1fe09a..e56befe 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2381,7 +2381,7 @@ static int ext4_mb_init_backend(struct super_block *sb)
 	/* An 8TB filesystem with 64-bit pointers requires a 4096 byte
 	 * kmalloc. A 128kb malloc should suffice for a 256TB filesystem.
 	 * So a two level scheme suffices for now. */
-	sbi->s_group_info = kmalloc(array_size, GFP_KERNEL);
+	sbi->s_group_info = kzalloc(array_size, GFP_KERNEL);
 	if (sbi->s_group_info == NULL) {
 		printk(KERN_ERR "EXT4-fs: can't allocate buddy meta group\n");
 		return -ENOMEM;
@@ -2412,7 +2412,8 @@ err_freebuddy:
 		kmem_cache_free(cachep, ext4_get_group_info(sb, i));
 	i = num_meta_group_infos;
 	while (i-- > 0)
-		kfree(sbi->s_group_info[i]);
+		if (sbi->s_group_info[i])
+			kfree(sbi->s_group_info[i]);
 	iput(sbi->s_buddy_cache);
 err_freesgi:
 	kfree(sbi->s_group_info);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: don't kfree uninitialized s_group_info members
  2011-03-10 23:03 [PATCH] ext4: don't kfree uninitialized s_group_info members Eric Sandeen
@ 2011-03-22  1:27 ` Ted Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Ted Ts'o @ 2011-03-22  1:27 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development, dame_eugene

On Thu, Mar 10, 2011 at 05:03:15PM -0600, Eric Sandeen wrote:
> Per kernel.org bugzilla #30872 we may call kfree on uninitialized
> members of the s_group_info array.  We can avoid this by kzalloc'ing
> the array, and only freeing them on the error path if they are
> non-zero.
> 
> This doesn't entirely solve the oops on mount if we fail down this
> path; failed_mount4: frees the sbi, for one, which gets referenced
> later in the failed mount paths - I haven't worked that out yet.
> 
> Reported-by: Eugene A. Shatokhin <dame_eugene@mail.ru>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Added to the ext4 patch tree, although I've dropped the second patch
hunk, since it's OK to call kfree on a NULL pointers:

> @@ -2412,7 +2412,8 @@ err_freebuddy:
>  		kmem_cache_free(cachep, ext4_get_group_info(sb, i));
>  	i = num_meta_group_infos;
>  	while (i-- > 0)
> -		kfree(sbi->s_group_info[i]);
> +		if (sbi->s_group_info[i])
> +			kfree(sbi->s_group_info[i]);
>  	iput(sbi->s_buddy_cache);
>  err_freesgi:
>  	kfree(sbi->s_group_info);

							- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-03-22  1:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-10 23:03 [PATCH] ext4: don't kfree uninitialized s_group_info members Eric Sandeen
2011-03-22  1:27 ` Ted Ts'o

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).