Patchwork Commit c1a1e7fc24d6 causes segfault in ext2fs_new_inode

login
register
mail settings
Submitter Eric Sandeen
Date March 30, 2012, 7:38 p.m.
Message ID <4F760BC2.4070401@redhat.com>
Download mbox | patch
Permalink /patch/149738/
State Not Applicable
Headers show

Comments

Eric Sandeen - March 30, 2012, 7:38 p.m.
On 3/30/12 8:19 AM, Richard W.M. Jones wrote:
> On Fri, Mar 30, 2012 at 01:57:26PM +0100, Richard W.M. Jones wrote:
>> [I'm tracking this issue here:
>> https://bugzilla.redhat.com/show_bug.cgi?id=808421]
> 
> A bit of further investigation:
> 
> I'm currently not passing EXT2_FLAG_64BITS when opening the
> filesystem.  Passing this flag fixes the issue, so I'm going to do
> that (are there any downsides?)
> 
> It seems like a non-64-bit-compatible bitmap was being created, and
> that doesn't have the bitmap->bitmap_ops field initialized because
> gen_bitmap.c doesn't use this field.  Somehow, though, we end up
> calling a function in gen_bitmap64.c which requires that this field be
> defined.
> 
> Rich.
> 

Well here's what's busted:

        if (bitmap->bitmap_ops->find_first_zero)
                return bitmap->bitmap_ops->find_first_zero(bitmap, start, end, out);

        if (!bitmap || !EXT2FS_IS_64_BITMAP(bitmap) || bitmap->cluster_bits)
                return EINVAL;

bitmap->bitmap_ops->find_first_zero only exists for a 64-bit bitmap, which
gets tested after we try to deref it :(

I wonder if this fixes it:



But then the next conditional would give us EINVAL since !EXT2FS_IS_64_BITMAP,
and I don't think things would go well after that either.

I am a little confused by the existence of two different
struct ext2fs_struct_generic_bitmap's in the code.  But treating one as the
other looks doomed to failure ;)

I haven't wrapped my head around this yet.

-Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric Sandeen - March 30, 2012, 10:25 p.m.
On 3/30/12 2:38 PM, Eric Sandeen wrote:
> On 3/30/12 8:19 AM, Richard W.M. Jones wrote:
>> On Fri, Mar 30, 2012 at 01:57:26PM +0100, Richard W.M. Jones wrote:
>>> [I'm tracking this issue here:
>>> https://bugzilla.redhat.com/show_bug.cgi?id=808421]
>>
>> A bit of further investigation:
>>
>> I'm currently not passing EXT2_FLAG_64BITS when opening the
>> filesystem.  Passing this flag fixes the issue, so I'm going to do
>> that (are there any downsides?)
>>
>> It seems like a non-64-bit-compatible bitmap was being created, and
>> that doesn't have the bitmap->bitmap_ops field initialized because
>> gen_bitmap.c doesn't use this field.  Somehow, though, we end up
>> calling a function in gen_bitmap64.c which requires that this field be
>> defined.
>>
>> Rich.
>>
> 
> Well here's what's busted:
> 
>         if (bitmap->bitmap_ops->find_first_zero)
>                 return bitmap->bitmap_ops->find_first_zero(bitmap, start, end, out);
> 
>         if (!bitmap || !EXT2FS_IS_64_BITMAP(bitmap) || bitmap->cluster_bits)
>                 return EINVAL;
> 
> bitmap->bitmap_ops->find_first_zero only exists for a 64-bit bitmap, which
> gets tested after we try to deref it :(
> 
> I wonder if this fixes it:

I guess it doesn't.  Seems ext2fs_find_first_zero_generic_bmap needs
a 32-bit-bitmap fallback.

-Eric

> diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
> index b57df54..ce6c23d 100644
> --- a/lib/ext2fs/gen_bitmap64.c
> +++ b/lib/ext2fs/gen_bitmap64.c
> @@ -768,7 +768,7 @@ errcode_t ext2fs_find_first_zero_generic_bmap(ext2fs_generic_bitmap bitmap,
>  {
>  	int b;
>  
> -	if (bitmap->bitmap_ops->find_first_zero)
> +	if (EXT2FS_IS_64_BITMAP(bitmap) && bitmap->bitmap_ops->find_first_zero)
>  		return bitmap->bitmap_ops->find_first_zero(bitmap, start, end, out);
>  
>  	if (!bitmap || !EXT2FS_IS_64_BITMAP(bitmap) || bitmap->cluster_bits)
> 
> 
> But then the next conditional would give us EINVAL since !EXT2FS_IS_64_BITMAP,
> and I don't think things would go well after that either.
> 
> I am a little confused by the existence of two different
> struct ext2fs_struct_generic_bitmap's in the code.  But treating one as the
> other looks doomed to failure ;)
> 
> I haven't wrapped my head around this yet.
> 
> -Eric
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
index b57df54..ce6c23d 100644
--- a/lib/ext2fs/gen_bitmap64.c
+++ b/lib/ext2fs/gen_bitmap64.c
@@ -768,7 +768,7 @@  errcode_t ext2fs_find_first_zero_generic_bmap(ext2fs_generic_bitmap bitmap,
 {
 	int b;
 
-	if (bitmap->bitmap_ops->find_first_zero)
+	if (EXT2FS_IS_64_BITMAP(bitmap) && bitmap->bitmap_ops->find_first_zero)
 		return bitmap->bitmap_ops->find_first_zero(bitmap, start, end, out);
 
 	if (!bitmap || !EXT2FS_IS_64_BITMAP(bitmap) || bitmap->cluster_bits)