All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
@ 2018-05-26  8:09 ` Yunlong Song
  0 siblings, 0 replies; 13+ messages in thread
From: Yunlong Song @ 2018-05-26  8:09 UTC (permalink / raw)
  To: jaegeuk, chao, yuchao0, yunlong.song, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

zone_align_start_offset should be u64, but config.start_sector is u32,
so it may be overflow when computing zone_align_start_offset.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 fsck/resize.c      | 7 ++++---
 mkfs/f2fs_format.c | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/fsck/resize.c b/fsck/resize.c
index d285dd7..8ac7d45 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -11,7 +11,8 @@
 
 static int get_new_sb(struct f2fs_super_block *sb)
 {
-	u_int32_t zone_size_bytes, zone_align_start_offset;
+	u_int32_t zone_size_bytes;
+	u_int64_t zone_align_start_offset;
 	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
 	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
 	u_int32_t total_valid_blks_available;
@@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
 
 	zone_size_bytes = segment_size_bytes * segs_per_zone;
 	zone_align_start_offset =
-		(c.start_sector * c.sector_size +
+		((u_int64_t) c.start_sector * c.sector_size +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * c.sector_size;
+		(u_int64_t) c.start_sector * c.sector_size;
 
 	set_sb(segment_count, (c.target_sectors * c.sector_size -
 				zone_align_start_offset) / segment_size_bytes /
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 0a99a77..f045e23 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
 	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
 
 	zone_align_start_offset =
-		(c.start_sector * c.sector_size +
+		((u_int64_t) c.start_sector * c.sector_size +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * c.sector_size;
+		(u_int64_t) c.start_sector * c.sector_size;
 
 	if (c.start_sector % c.sectors_per_blk) {
 		MSG(1, "\t%s: Align start sector number to the page unit\n",
-- 
1.8.5.2

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

* [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
@ 2018-05-26  8:09 ` Yunlong Song
  0 siblings, 0 replies; 13+ messages in thread
From: Yunlong Song @ 2018-05-26  8:09 UTC (permalink / raw)
  To: jaegeuk, chao, yuchao0, yunlong.song, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

zone_align_start_offset should be u64, but config.start_sector is u32,
so it may be overflow when computing zone_align_start_offset.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 fsck/resize.c      | 7 ++++---
 mkfs/f2fs_format.c | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/fsck/resize.c b/fsck/resize.c
index d285dd7..8ac7d45 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -11,7 +11,8 @@
 
 static int get_new_sb(struct f2fs_super_block *sb)
 {
-	u_int32_t zone_size_bytes, zone_align_start_offset;
+	u_int32_t zone_size_bytes;
+	u_int64_t zone_align_start_offset;
 	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
 	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
 	u_int32_t total_valid_blks_available;
@@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
 
 	zone_size_bytes = segment_size_bytes * segs_per_zone;
 	zone_align_start_offset =
-		(c.start_sector * c.sector_size +
+		((u_int64_t) c.start_sector * c.sector_size +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * c.sector_size;
+		(u_int64_t) c.start_sector * c.sector_size;
 
 	set_sb(segment_count, (c.target_sectors * c.sector_size -
 				zone_align_start_offset) / segment_size_bytes /
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 0a99a77..f045e23 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
 	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
 
 	zone_align_start_offset =
-		(c.start_sector * c.sector_size +
+		((u_int64_t) c.start_sector * c.sector_size +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * c.sector_size;
+		(u_int64_t) c.start_sector * c.sector_size;
 
 	if (c.start_sector % c.sectors_per_blk) {
 		MSG(1, "\t%s: Align start sector number to the page unit\n",
-- 
1.8.5.2

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

* Re: [f2fs-dev] [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
  2018-05-26  8:09 ` Yunlong Song
@ 2018-05-26 11:27   ` Junling Zheng
  -1 siblings, 0 replies; 13+ messages in thread
From: Junling Zheng @ 2018-05-26 11:27 UTC (permalink / raw)
  To: Yunlong Song, jaegeuk, chao, yuchao0, yunlong.song
  Cc: linux-kernel, linux-f2fs-devel, miaoxie

No neet to change zone_align_start_offset to u64, because zone_align_start_offset is always
smaller than zone_size_bytes, which is u32.

Thanks,
Junling

On 2018/5/26 16:09, Yunlong Song wrote:
> zone_align_start_offset should be u64, but config.start_sector is u32,
> so it may be overflow when computing zone_align_start_offset.
> 
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> ---
>  fsck/resize.c      | 7 ++++---
>  mkfs/f2fs_format.c | 4 ++--
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/fsck/resize.c b/fsck/resize.c
> index d285dd7..8ac7d45 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -11,7 +11,8 @@
>  
>  static int get_new_sb(struct f2fs_super_block *sb)
>  {
> -	u_int32_t zone_size_bytes, zone_align_start_offset;
> +	u_int32_t zone_size_bytes;
> +	u_int64_t zone_align_start_offset;
>  	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
>  	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
>  	u_int32_t total_valid_blks_available;
> @@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
>  
>  	zone_size_bytes = segment_size_bytes * segs_per_zone;
>  	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		((u_int64_t) c.start_sector * c.sector_size +
>  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>  		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		(u_int64_t) c.start_sector * c.sector_size;
>  
>  	set_sb(segment_count, (c.target_sectors * c.sector_size -
>  				zone_align_start_offset) / segment_size_bytes /
> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> index 0a99a77..f045e23 100644
> --- a/mkfs/f2fs_format.c
> +++ b/mkfs/f2fs_format.c
> @@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
>  	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
>  
>  	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		((u_int64_t) c.start_sector * c.sector_size +
>  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>  		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		(u_int64_t) c.start_sector * c.sector_size;
>  
>  	if (c.start_sector % c.sectors_per_blk) {
>  		MSG(1, "\t%s: Align start sector number to the page unit\n",
> 

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

* Re: [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
@ 2018-05-26 11:27   ` Junling Zheng
  0 siblings, 0 replies; 13+ messages in thread
From: Junling Zheng @ 2018-05-26 11:27 UTC (permalink / raw)
  To: Yunlong Song, jaegeuk, chao, yuchao0, yunlong.song
  Cc: miaoxie, linux-kernel, linux-f2fs-devel

No neet to change zone_align_start_offset to u64, because zone_align_start_offset is always
smaller than zone_size_bytes, which is u32.

Thanks,
Junling

On 2018/5/26 16:09, Yunlong Song wrote:
> zone_align_start_offset should be u64, but config.start_sector is u32,
> so it may be overflow when computing zone_align_start_offset.
> 
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> ---
>  fsck/resize.c      | 7 ++++---
>  mkfs/f2fs_format.c | 4 ++--
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/fsck/resize.c b/fsck/resize.c
> index d285dd7..8ac7d45 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -11,7 +11,8 @@
>  
>  static int get_new_sb(struct f2fs_super_block *sb)
>  {
> -	u_int32_t zone_size_bytes, zone_align_start_offset;
> +	u_int32_t zone_size_bytes;
> +	u_int64_t zone_align_start_offset;
>  	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
>  	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
>  	u_int32_t total_valid_blks_available;
> @@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
>  
>  	zone_size_bytes = segment_size_bytes * segs_per_zone;
>  	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		((u_int64_t) c.start_sector * c.sector_size +
>  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>  		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		(u_int64_t) c.start_sector * c.sector_size;
>  
>  	set_sb(segment_count, (c.target_sectors * c.sector_size -
>  				zone_align_start_offset) / segment_size_bytes /
> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> index 0a99a77..f045e23 100644
> --- a/mkfs/f2fs_format.c
> +++ b/mkfs/f2fs_format.c
> @@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
>  	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
>  
>  	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		((u_int64_t) c.start_sector * c.sector_size +
>  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>  		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		(u_int64_t) c.start_sector * c.sector_size;
>  
>  	if (c.start_sector % c.sectors_per_blk) {
>  		MSG(1, "\t%s: Align start sector number to the page unit\n",
> 



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [f2fs-dev] [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
  2018-05-26 11:27   ` Junling Zheng
@ 2018-05-27 13:41     ` Yunlong Song
  -1 siblings, 0 replies; 13+ messages in thread
From: Yunlong Song @ 2018-05-27 13:41 UTC (permalink / raw)
  To: Junling Zheng, jaegeuk, chao, yuchao0, yunlong.song
  Cc: linux-kernel, linux-f2fs-devel, miaoxie

Just keep it same with u_int64_t defined in mkfs/f2fs_format.c, and 
c.start_sector * c.sector_size
may be u32 overflow, so add (u_int64_t) before c.start_sector * 
c.sector_size and change the target
value zone_align_start_offset to (u_int64_t).

On 2018/5/26 19:27, Junling Zheng wrote:
> No neet to change zone_align_start_offset to u64, because zone_align_start_offset is always
> smaller than zone_size_bytes, which is u32.
>
> Thanks,
> Junling
>
> On 2018/5/26 16:09, Yunlong Song wrote:
>> zone_align_start_offset should be u64, but config.start_sector is u32,
>> so it may be overflow when computing zone_align_start_offset.
>>
>> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
>> ---
>>   fsck/resize.c      | 7 ++++---
>>   mkfs/f2fs_format.c | 4 ++--
>>   2 files changed, 6 insertions(+), 5 deletions(-)
>>
>> diff --git a/fsck/resize.c b/fsck/resize.c
>> index d285dd7..8ac7d45 100644
>> --- a/fsck/resize.c
>> +++ b/fsck/resize.c
>> @@ -11,7 +11,8 @@
>>   
>>   static int get_new_sb(struct f2fs_super_block *sb)
>>   {
>> -	u_int32_t zone_size_bytes, zone_align_start_offset;
>> +	u_int32_t zone_size_bytes;
>> +	u_int64_t zone_align_start_offset;
>>   	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
>>   	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
>>   	u_int32_t total_valid_blks_available;
>> @@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
>>   
>>   	zone_size_bytes = segment_size_bytes * segs_per_zone;
>>   	zone_align_start_offset =
>> -		(c.start_sector * c.sector_size +
>> +		((u_int64_t) c.start_sector * c.sector_size +
>>   		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>>   		zone_size_bytes * zone_size_bytes -
>> -		c.start_sector * c.sector_size;
>> +		(u_int64_t) c.start_sector * c.sector_size;
>>   
>>   	set_sb(segment_count, (c.target_sectors * c.sector_size -
>>   				zone_align_start_offset) / segment_size_bytes /
>> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
>> index 0a99a77..f045e23 100644
>> --- a/mkfs/f2fs_format.c
>> +++ b/mkfs/f2fs_format.c
>> @@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
>>   	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
>>   
>>   	zone_align_start_offset =
>> -		(c.start_sector * c.sector_size +
>> +		((u_int64_t) c.start_sector * c.sector_size +
>>   		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>>   		zone_size_bytes * zone_size_bytes -
>> -		c.start_sector * c.sector_size;
>> +		(u_int64_t) c.start_sector * c.sector_size;
>>   
>>   	if (c.start_sector % c.sectors_per_blk) {
>>   		MSG(1, "\t%s: Align start sector number to the page unit\n",
>>
>
>
> .
>

-- 
Thanks,
Yunlong Song

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

* Re: [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
@ 2018-05-27 13:41     ` Yunlong Song
  0 siblings, 0 replies; 13+ messages in thread
From: Yunlong Song @ 2018-05-27 13:41 UTC (permalink / raw)
  To: Junling Zheng, jaegeuk, chao, yuchao0, yunlong.song
  Cc: miaoxie, linux-kernel, linux-f2fs-devel

Just keep it same with u_int64_t defined in mkfs/f2fs_format.c, and 
c.start_sector * c.sector_size
may be u32 overflow, so add (u_int64_t) before c.start_sector * 
c.sector_size and change the target
value zone_align_start_offset to (u_int64_t).

On 2018/5/26 19:27, Junling Zheng wrote:
> No neet to change zone_align_start_offset to u64, because zone_align_start_offset is always
> smaller than zone_size_bytes, which is u32.
>
> Thanks,
> Junling
>
> On 2018/5/26 16:09, Yunlong Song wrote:
>> zone_align_start_offset should be u64, but config.start_sector is u32,
>> so it may be overflow when computing zone_align_start_offset.
>>
>> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
>> ---
>>   fsck/resize.c      | 7 ++++---
>>   mkfs/f2fs_format.c | 4 ++--
>>   2 files changed, 6 insertions(+), 5 deletions(-)
>>
>> diff --git a/fsck/resize.c b/fsck/resize.c
>> index d285dd7..8ac7d45 100644
>> --- a/fsck/resize.c
>> +++ b/fsck/resize.c
>> @@ -11,7 +11,8 @@
>>   
>>   static int get_new_sb(struct f2fs_super_block *sb)
>>   {
>> -	u_int32_t zone_size_bytes, zone_align_start_offset;
>> +	u_int32_t zone_size_bytes;
>> +	u_int64_t zone_align_start_offset;
>>   	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
>>   	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
>>   	u_int32_t total_valid_blks_available;
>> @@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
>>   
>>   	zone_size_bytes = segment_size_bytes * segs_per_zone;
>>   	zone_align_start_offset =
>> -		(c.start_sector * c.sector_size +
>> +		((u_int64_t) c.start_sector * c.sector_size +
>>   		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>>   		zone_size_bytes * zone_size_bytes -
>> -		c.start_sector * c.sector_size;
>> +		(u_int64_t) c.start_sector * c.sector_size;
>>   
>>   	set_sb(segment_count, (c.target_sectors * c.sector_size -
>>   				zone_align_start_offset) / segment_size_bytes /
>> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
>> index 0a99a77..f045e23 100644
>> --- a/mkfs/f2fs_format.c
>> +++ b/mkfs/f2fs_format.c
>> @@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
>>   	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
>>   
>>   	zone_align_start_offset =
>> -		(c.start_sector * c.sector_size +
>> +		((u_int64_t) c.start_sector * c.sector_size +
>>   		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>>   		zone_size_bytes * zone_size_bytes -
>> -		c.start_sector * c.sector_size;
>> +		(u_int64_t) c.start_sector * c.sector_size;
>>   
>>   	if (c.start_sector % c.sectors_per_blk) {
>>   		MSG(1, "\t%s: Align start sector number to the page unit\n",
>>
>
>
> .
>

-- 
Thanks,
Yunlong Song



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
  2018-05-26  8:09 ` Yunlong Song
@ 2018-05-28  7:29   ` Chao Yu
  -1 siblings, 0 replies; 13+ messages in thread
From: Chao Yu @ 2018-05-28  7:29 UTC (permalink / raw)
  To: Yunlong Song, jaegeuk, chao, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

On 2018/5/26 16:09, Yunlong Song wrote:
> zone_align_start_offset should be u64, but config.start_sector is u32,
> so it may be overflow when computing zone_align_start_offset.

Could you rebase this patch on top of "f2fs-tools: fix to match with the
start_sector"?

Thanks,

> 
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> ---
>  fsck/resize.c      | 7 ++++---
>  mkfs/f2fs_format.c | 4 ++--
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/fsck/resize.c b/fsck/resize.c
> index d285dd7..8ac7d45 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -11,7 +11,8 @@
>  
>  static int get_new_sb(struct f2fs_super_block *sb)
>  {
> -	u_int32_t zone_size_bytes, zone_align_start_offset;
> +	u_int32_t zone_size_bytes;
> +	u_int64_t zone_align_start_offset;
>  	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
>  	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
>  	u_int32_t total_valid_blks_available;
> @@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
>  
>  	zone_size_bytes = segment_size_bytes * segs_per_zone;
>  	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		((u_int64_t) c.start_sector * c.sector_size +
>  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>  		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		(u_int64_t) c.start_sector * c.sector_size;
>  
>  	set_sb(segment_count, (c.target_sectors * c.sector_size -
>  				zone_align_start_offset) / segment_size_bytes /
> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> index 0a99a77..f045e23 100644
> --- a/mkfs/f2fs_format.c
> +++ b/mkfs/f2fs_format.c
> @@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
>  	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
>  
>  	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		((u_int64_t) c.start_sector * c.sector_size +
>  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>  		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		(u_int64_t) c.start_sector * c.sector_size;
>  
>  	if (c.start_sector % c.sectors_per_blk) {
>  		MSG(1, "\t%s: Align start sector number to the page unit\n",
> 

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

* Re: [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
@ 2018-05-28  7:29   ` Chao Yu
  0 siblings, 0 replies; 13+ messages in thread
From: Chao Yu @ 2018-05-28  7:29 UTC (permalink / raw)
  To: Yunlong Song, jaegeuk, chao, yunlong.song
  Cc: linux-kernel, linux-f2fs-devel, miaoxie

On 2018/5/26 16:09, Yunlong Song wrote:
> zone_align_start_offset should be u64, but config.start_sector is u32,
> so it may be overflow when computing zone_align_start_offset.

Could you rebase this patch on top of "f2fs-tools: fix to match with the
start_sector"?

Thanks,

> 
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> ---
>  fsck/resize.c      | 7 ++++---
>  mkfs/f2fs_format.c | 4 ++--
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/fsck/resize.c b/fsck/resize.c
> index d285dd7..8ac7d45 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -11,7 +11,8 @@
>  
>  static int get_new_sb(struct f2fs_super_block *sb)
>  {
> -	u_int32_t zone_size_bytes, zone_align_start_offset;
> +	u_int32_t zone_size_bytes;
> +	u_int64_t zone_align_start_offset;
>  	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
>  	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
>  	u_int32_t total_valid_blks_available;
> @@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
>  
>  	zone_size_bytes = segment_size_bytes * segs_per_zone;
>  	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		((u_int64_t) c.start_sector * c.sector_size +
>  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>  		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		(u_int64_t) c.start_sector * c.sector_size;
>  
>  	set_sb(segment_count, (c.target_sectors * c.sector_size -
>  				zone_align_start_offset) / segment_size_bytes /
> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> index 0a99a77..f045e23 100644
> --- a/mkfs/f2fs_format.c
> +++ b/mkfs/f2fs_format.c
> @@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
>  	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
>  
>  	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		((u_int64_t) c.start_sector * c.sector_size +
>  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>  		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		(u_int64_t) c.start_sector * c.sector_size;
>  
>  	if (c.start_sector % c.sectors_per_blk) {
>  		MSG(1, "\t%s: Align start sector number to the page unit\n",
> 


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
  2018-05-28  7:29   ` Chao Yu
@ 2018-05-30  2:33     ` Jaegeuk Kim
  -1 siblings, 0 replies; 13+ messages in thread
From: Jaegeuk Kim @ 2018-05-30  2:33 UTC (permalink / raw)
  To: Chao Yu
  Cc: Yunlong Song, chao, yunlong.song, miaoxie, bintian.wang,
	shengyong1, heyunlei, linux-f2fs-devel, linux-kernel

On 05/28, Chao Yu wrote:
> On 2018/5/26 16:09, Yunlong Song wrote:
> > zone_align_start_offset should be u64, but config.start_sector is u32,
> > so it may be overflow when computing zone_align_start_offset.
> 
> Could you rebase this patch on top of "f2fs-tools: fix to match with the
> start_sector"?

Yes, please. I updated dev-test. :P

> 
> Thanks,
> 
> > 
> > Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> > ---
> >  fsck/resize.c      | 7 ++++---
> >  mkfs/f2fs_format.c | 4 ++--
> >  2 files changed, 6 insertions(+), 5 deletions(-)
> > 
> > diff --git a/fsck/resize.c b/fsck/resize.c
> > index d285dd7..8ac7d45 100644
> > --- a/fsck/resize.c
> > +++ b/fsck/resize.c
> > @@ -11,7 +11,8 @@
> >  
> >  static int get_new_sb(struct f2fs_super_block *sb)
> >  {
> > -	u_int32_t zone_size_bytes, zone_align_start_offset;
> > +	u_int32_t zone_size_bytes;
> > +	u_int64_t zone_align_start_offset;
> >  	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
> >  	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
> >  	u_int32_t total_valid_blks_available;
> > @@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
> >  
> >  	zone_size_bytes = segment_size_bytes * segs_per_zone;
> >  	zone_align_start_offset =
> > -		(c.start_sector * c.sector_size +
> > +		((u_int64_t) c.start_sector * c.sector_size +
> >  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
> >  		zone_size_bytes * zone_size_bytes -
> > -		c.start_sector * c.sector_size;
> > +		(u_int64_t) c.start_sector * c.sector_size;
> >  
> >  	set_sb(segment_count, (c.target_sectors * c.sector_size -
> >  				zone_align_start_offset) / segment_size_bytes /
> > diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> > index 0a99a77..f045e23 100644
> > --- a/mkfs/f2fs_format.c
> > +++ b/mkfs/f2fs_format.c
> > @@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
> >  	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
> >  
> >  	zone_align_start_offset =
> > -		(c.start_sector * c.sector_size +
> > +		((u_int64_t) c.start_sector * c.sector_size +
> >  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
> >  		zone_size_bytes * zone_size_bytes -
> > -		c.start_sector * c.sector_size;
> > +		(u_int64_t) c.start_sector * c.sector_size;
> >  
> >  	if (c.start_sector % c.sectors_per_blk) {
> >  		MSG(1, "\t%s: Align start sector number to the page unit\n",
> > 

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

* Re: [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
@ 2018-05-30  2:33     ` Jaegeuk Kim
  0 siblings, 0 replies; 13+ messages in thread
From: Jaegeuk Kim @ 2018-05-30  2:33 UTC (permalink / raw)
  To: Chao Yu; +Cc: yunlong.song, linux-kernel, linux-f2fs-devel, miaoxie

On 05/28, Chao Yu wrote:
> On 2018/5/26 16:09, Yunlong Song wrote:
> > zone_align_start_offset should be u64, but config.start_sector is u32,
> > so it may be overflow when computing zone_align_start_offset.
> 
> Could you rebase this patch on top of "f2fs-tools: fix to match with the
> start_sector"?

Yes, please. I updated dev-test. :P

> 
> Thanks,
> 
> > 
> > Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> > ---
> >  fsck/resize.c      | 7 ++++---
> >  mkfs/f2fs_format.c | 4 ++--
> >  2 files changed, 6 insertions(+), 5 deletions(-)
> > 
> > diff --git a/fsck/resize.c b/fsck/resize.c
> > index d285dd7..8ac7d45 100644
> > --- a/fsck/resize.c
> > +++ b/fsck/resize.c
> > @@ -11,7 +11,8 @@
> >  
> >  static int get_new_sb(struct f2fs_super_block *sb)
> >  {
> > -	u_int32_t zone_size_bytes, zone_align_start_offset;
> > +	u_int32_t zone_size_bytes;
> > +	u_int64_t zone_align_start_offset;
> >  	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
> >  	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
> >  	u_int32_t total_valid_blks_available;
> > @@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
> >  
> >  	zone_size_bytes = segment_size_bytes * segs_per_zone;
> >  	zone_align_start_offset =
> > -		(c.start_sector * c.sector_size +
> > +		((u_int64_t) c.start_sector * c.sector_size +
> >  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
> >  		zone_size_bytes * zone_size_bytes -
> > -		c.start_sector * c.sector_size;
> > +		(u_int64_t) c.start_sector * c.sector_size;
> >  
> >  	set_sb(segment_count, (c.target_sectors * c.sector_size -
> >  				zone_align_start_offset) / segment_size_bytes /
> > diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> > index 0a99a77..f045e23 100644
> > --- a/mkfs/f2fs_format.c
> > +++ b/mkfs/f2fs_format.c
> > @@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
> >  	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
> >  
> >  	zone_align_start_offset =
> > -		(c.start_sector * c.sector_size +
> > +		((u_int64_t) c.start_sector * c.sector_size +
> >  		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
> >  		zone_size_bytes * zone_size_bytes -
> > -		c.start_sector * c.sector_size;
> > +		(u_int64_t) c.start_sector * c.sector_size;
> >  
> >  	if (c.start_sector % c.sectors_per_blk) {
> >  		MSG(1, "\t%s: Align start sector number to the page unit\n",
> > 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* [PATCH rebase] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
  2018-05-26  8:09 ` Yunlong Song
@ 2018-05-30  6:58   ` Yunlong Song
  -1 siblings, 0 replies; 13+ messages in thread
From: Yunlong Song @ 2018-05-30  6:58 UTC (permalink / raw)
  To: jaegeuk, chao, yuchao0, yunlong.song, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

zone_align_start_offset should be u64, but config.start_sector is u32,
so it may be overflow when computing zone_align_start_offset.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 fsck/resize.c      | 7 ++++---
 mkfs/f2fs_format.c | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/fsck/resize.c b/fsck/resize.c
index 649f5d9..3f8b01d 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -11,7 +11,8 @@
 
 static int get_new_sb(struct f2fs_super_block *sb)
 {
-	u_int32_t zone_size_bytes, zone_align_start_offset;
+	u_int32_t zone_size_bytes;
+	u_int64_t zone_align_start_offset;
 	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
 	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
 	u_int32_t total_valid_blks_available;
@@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
 
 	zone_size_bytes = segment_size_bytes * segs_per_zone;
 	zone_align_start_offset =
-		(c.start_sector * DEFAULT_SECTOR_SIZE +
+		((u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * DEFAULT_SECTOR_SIZE;
+		(u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE;
 
 	set_sb(segment_count, (c.target_sectors * c.sector_size -
 				zone_align_start_offset) / segment_size_bytes /
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index e0c3cb8..2350c10 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
 	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
 
 	zone_align_start_offset =
-		(c.start_sector * DEFAULT_SECTOR_SIZE +
+		((u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * DEFAULT_SECTOR_SIZE;
+		(u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE;
 
 	if (c.start_sector % DEFAULT_SECTORS_PER_BLOCK) {
 		MSG(1, "\t%s: Align start sector number to the page unit\n",
-- 
1.8.5.2

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

* [PATCH rebase] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
@ 2018-05-30  6:58   ` Yunlong Song
  0 siblings, 0 replies; 13+ messages in thread
From: Yunlong Song @ 2018-05-30  6:58 UTC (permalink / raw)
  To: jaegeuk, chao, yuchao0, yunlong.song, yunlong.song
  Cc: linux-kernel, linux-f2fs-devel, miaoxie

zone_align_start_offset should be u64, but config.start_sector is u32,
so it may be overflow when computing zone_align_start_offset.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 fsck/resize.c      | 7 ++++---
 mkfs/f2fs_format.c | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/fsck/resize.c b/fsck/resize.c
index 649f5d9..3f8b01d 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -11,7 +11,8 @@
 
 static int get_new_sb(struct f2fs_super_block *sb)
 {
-	u_int32_t zone_size_bytes, zone_align_start_offset;
+	u_int32_t zone_size_bytes;
+	u_int64_t zone_align_start_offset;
 	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
 	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
 	u_int32_t total_valid_blks_available;
@@ -27,10 +28,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
 
 	zone_size_bytes = segment_size_bytes * segs_per_zone;
 	zone_align_start_offset =
-		(c.start_sector * DEFAULT_SECTOR_SIZE +
+		((u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * DEFAULT_SECTOR_SIZE;
+		(u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE;
 
 	set_sb(segment_count, (c.target_sectors * c.sector_size -
 				zone_align_start_offset) / segment_size_bytes /
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index e0c3cb8..2350c10 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -212,10 +212,10 @@ static int f2fs_prepare_super_block(void)
 	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
 
 	zone_align_start_offset =
-		(c.start_sector * DEFAULT_SECTOR_SIZE +
+		((u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * DEFAULT_SECTOR_SIZE;
+		(u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE;
 
 	if (c.start_sector % DEFAULT_SECTORS_PER_BLOCK) {
 		MSG(1, "\t%s: Align start sector number to the page unit\n",
-- 
1.8.5.2


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH rebase] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
  2018-05-30  6:58   ` Yunlong Song
  (?)
@ 2018-05-30 14:30   ` Chao Yu
  -1 siblings, 0 replies; 13+ messages in thread
From: Chao Yu @ 2018-05-30 14:30 UTC (permalink / raw)
  To: Yunlong Song, jaegeuk, yuchao0, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

On 2018/5/30 14:58, Yunlong Song wrote:
> zone_align_start_offset should be u64, but config.start_sector is u32,
> so it may be overflow when computing zone_align_start_offset.
> 
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,

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

end of thread, other threads:[~2018-05-30 14:31 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-26  8:09 [PATCH] f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset Yunlong Song
2018-05-26  8:09 ` Yunlong Song
2018-05-26 11:27 ` [f2fs-dev] " Junling Zheng
2018-05-26 11:27   ` Junling Zheng
2018-05-27 13:41   ` [f2fs-dev] " Yunlong Song
2018-05-27 13:41     ` Yunlong Song
2018-05-28  7:29 ` Chao Yu
2018-05-28  7:29   ` Chao Yu
2018-05-30  2:33   ` Jaegeuk Kim
2018-05-30  2:33     ` Jaegeuk Kim
2018-05-30  6:58 ` [PATCH rebase] " Yunlong Song
2018-05-30  6:58   ` Yunlong Song
2018-05-30 14:30   ` Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.