diff mbox

btrfs: Fix superblock csum type check.

Message ID 1430183163-10870-1-git-send-email-quwenruo@cn.fujitsu.com (mailing list archive)
State Superseded
Headers show

Commit Message

Qu Wenruo April 28, 2015, 1:06 a.m. UTC
Old csum type check is wrong and can't catch csum_type 1(not supported).

Fix it to avoid hostile 0 division.

Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
Changelog:
v2:
   Fix existing codes other than adding new one.
v3:
   Just remove the tailing in btrfs_csum_sizes array.
---
 fs/btrfs/ctree.h   | 2 +-
 fs/btrfs/disk-io.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

David Sterba April 29, 2015, 5:23 p.m. UTC | #1
On Tue, Apr 28, 2015 at 09:06:03AM +0800, Qu Wenruo wrote:
> Old csum type check is wrong and can't catch csum_type 1(not supported).
> 
> Fix it to avoid hostile 0 division.
> 
> Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Reviewed-by: David Sterba <dsterba@suse.cz>

> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -428,7 +428,7 @@ static int btrfs_check_super_csum(char *raw_disk_sb)
>  
>  	if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) {
>  		printk(KERN_ERR "BTRFS: unsupported checksum algorithm %u\n",
> -				csum_type);
> +		       csum_type);

Please avoid unrelated changes.

>  		ret = 1;
>  	}
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo April 30, 2015, 12:33 a.m. UTC | #2
-------- Original Message  --------
Subject: Re: [PATCH] btrfs: Fix superblock csum type check.
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo@cn.fujitsu.com>
Date: 2015?04?30? 01:23

> On Tue, Apr 28, 2015 at 09:06:03AM +0800, Qu Wenruo wrote:
>> Old csum type check is wrong and can't catch csum_type 1(not supported).
>>
>> Fix it to avoid hostile 0 division.
>>
>> Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
>> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
>
> Reviewed-by: David Sterba <dsterba@suse.cz>
>
>> --- a/fs/btrfs/disk-io.c
>> +++ b/fs/btrfs/disk-io.c
>> @@ -428,7 +428,7 @@ static int btrfs_check_super_csum(char *raw_disk_sb)
>>
>>   	if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) {
>>   		printk(KERN_ERR "BTRFS: unsupported checksum algorithm %u\n",
>> -				csum_type);
>> +		       csum_type);
>
> Please avoid unrelated changes.
Thanks for reviewing.

Do I need to send a newer version to discard this format change?

Thanks,
Qu
>
>>   		ret = 1;
>>   	}
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba May 4, 2015, 4:08 p.m. UTC | #3
On Thu, Apr 30, 2015 at 08:33:26AM +0800, Qu Wenruo wrote:
> >> -				csum_type);
> >> +		       csum_type);
> >
> > Please avoid unrelated changes.
> Thanks for reviewing.
> 
> Do I need to send a newer version to discard this format change?

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

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index f9c89ca..745b5e7 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -174,7 +174,7 @@  struct btrfs_ordered_sum;
 /* csum types */
 #define BTRFS_CSUM_TYPE_CRC32	0
 
-static int btrfs_csum_sizes[] = { 4, 0 };
+static int btrfs_csum_sizes[] = { 4 };
 
 /* four bytes for CRC32 */
 #define BTRFS_EMPTY_DIR_SIZE 0
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 639f266..e3495b1 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -428,7 +428,7 @@  static int btrfs_check_super_csum(char *raw_disk_sb)
 
 	if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) {
 		printk(KERN_ERR "BTRFS: unsupported checksum algorithm %u\n",
-				csum_type);
+		       csum_type);
 		ret = 1;
 	}