File btrfs-progs-convert-prevent-accounting-blocks-beyond-end-of-device.patch of Package btrfsprogs.11414

From: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Subject: btrfs-progs: convert: Prevent accounting blocks beyond end of device
Git-commit: 8583b613095a46b000e5ee333d6bf58cad0c2248
Patch-mainline: v4.9-rc2
References: bsc#1042369

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>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Acked-by: Jeff Mahoney <jeffm@suse.com>
---
 btrfs-convert.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/btrfs-convert.c b/convert/main.c
index 4b4cea42..1148a369 100644
--- a/btrfs-convert.c
+++ b/btrfs-convert.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;
 

openSUSE Build Service is sponsored by