diff mbox

[1/2] btrfs-progs: btrfs-convert: Prevent accounting blocks beyond end of device

Message ID 1481205380-22978-1-git-send-email-chandan@linux.vnet.ibm.com (mailing list archive)
State Accepted
Headers show

Commit Message

Chandan Rajendra Dec. 8, 2016, 1:56 p.m. UTC
When looping across data block bitmap, __ext2_add_one_block() may add
blocks which do not exist on the underlying disk. This commit prevents
this from happening by checking the block index against the maximum
block count that was present in the ext4 filesystem instance that is
being converted.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
---
 convert/main.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Qu Wenruo Dec. 9, 2016, 1:03 a.m. UTC | #1
Hi Chandan,

Thanks for the patch.

At 12/08/2016 09:56 PM, Chandan Rajendra wrote:
> When looping across data block bitmap, __ext2_add_one_block() may add
> blocks which do not exist on the underlying disk. This commit prevents
> this from happening by checking the block index against the maximum
> block count that was present in the ext4 filesystem instance that is
> being converted.

The patch looks good to me.

Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Just curious about if such image can pass e2fsck.
And would you please upload a minimal image as btrfs-progs test case?

Thanks,
Qu

>
> Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
> ---
>  convert/main.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/convert/main.c b/convert/main.c
> index 4b4cea4..1148a36 100644
> --- a/convert/main.c
> +++ b/convert/main.c
> @@ -1525,6 +1525,9 @@ static int __ext2_add_one_block(ext2_filsys fs, char *bitmap,
>  	offset /= EXT2FS_CLUSTER_RATIO(fs);
>  	offset += group_nr * EXT2_CLUSTERS_PER_GROUP(fs->super);
>  	for (i = 0; i < EXT2_CLUSTERS_PER_GROUP(fs->super); i++) {
> +		if ((i + offset) >= ext2fs_blocks_count(fs->super))
> +			break;
> +
>  		if (ext2fs_test_bit(i, bitmap)) {
>  			u64 start;
>
>


--
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 Dec. 9, 2016, 1:04 a.m. UTC | #2
Hi Chandan,

Thanks for the patch.

At 12/08/2016 09:56 PM, Chandan Rajendra wrote:
> When looping across data block bitmap, __ext2_add_one_block() may add
> blocks which do not exist on the underlying disk. This commit prevents
> this from happening by checking the block index against the maximum
> block count that was present in the ext4 filesystem instance that is
> being converted.

The patch looks good to me.

Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Just curious about if such image can pass e2fsck.
And would you please upload a minimal image as btrfs-progs test case?

Thanks,
Qu

>
> Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
> ---
>  convert/main.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/convert/main.c b/convert/main.c
> index 4b4cea4..1148a36 100644
> --- a/convert/main.c
> +++ b/convert/main.c
> @@ -1525,6 +1525,9 @@ static int __ext2_add_one_block(ext2_filsys fs, char *bitmap,
>  	offset /= EXT2FS_CLUSTER_RATIO(fs);
>  	offset += group_nr * EXT2_CLUSTERS_PER_GROUP(fs->super);
>  	for (i = 0; i < EXT2_CLUSTERS_PER_GROUP(fs->super); i++) {
> +		if ((i + offset) >= ext2fs_blocks_count(fs->super))
> +			break;
> +
>  		if (ext2fs_test_bit(i, bitmap)) {
>  			u64 start;
>
>


--
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
Chandan Rajendra Dec. 9, 2016, 4:36 a.m. UTC | #3
On Friday, December 09, 2016 09:03:57 AM Qu Wenruo wrote:
> Hi Chandan,
> 
> Thanks for the patch.
> 
> At 12/08/2016 09:56 PM, Chandan Rajendra wrote:
> > When looping across data block bitmap, __ext2_add_one_block() may add
> > blocks which do not exist on the underlying disk. This commit prevents
> > this from happening by checking the block index against the maximum
> > block count that was present in the ext4 filesystem instance that is
> > being converted.
> 
> The patch looks good to me.
> 
> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> 
> Just curious about if such image can pass e2fsck.
> And would you please upload a minimal image as btrfs-progs test case?
> 

Hi Qu,

Such an ext4 filesystem can be consistently created on ppc64 with 64k as the
blocksize of the filesystem. Also, the filesystem thus created passes e2fsck.
David Sterba Dec. 14, 2016, 12:38 p.m. UTC | #4
On Fri, Dec 09, 2016 at 09:03:57AM +0800, Qu Wenruo wrote:
> Hi Chandan,
> 
> Thanks for the patch.
> 
> At 12/08/2016 09:56 PM, Chandan Rajendra wrote:
> > When looping across data block bitmap, __ext2_add_one_block() may add
> > blocks which do not exist on the underlying disk. This commit prevents
> > this from happening by checking the block index against the maximum
> > block count that was present in the ext4 filesystem instance that is
> > being converted.
> 
> The patch looks good to me.
> 
> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Applied, thanks.
--
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/convert/main.c b/convert/main.c
index 4b4cea4..1148a36 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -1525,6 +1525,9 @@  static int __ext2_add_one_block(ext2_filsys fs, char *bitmap,
 	offset /= EXT2FS_CLUSTER_RATIO(fs);
 	offset += group_nr * EXT2_CLUSTERS_PER_GROUP(fs->super);
 	for (i = 0; i < EXT2_CLUSTERS_PER_GROUP(fs->super); i++) {
+		if ((i + offset) >= ext2fs_blocks_count(fs->super))
+			break;
+
 		if (ext2fs_test_bit(i, bitmap)) {
 			u64 start;