Skip to contentSkip to conversation

vmdk: Widen before shifting 32 bit header field

PATCH Applied Fam Zheng 3 participants 3 messages Apr 27, 2015 – Apr 28, 2015 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 vmdk: Widen before shifting 32 bit header field

Coverity spotted this.

The field is 32 bits, but if it's possible to overflow in 32 bit left shift.

---
 block/vmdk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/vmdk.c +1 -1
index 8410a15..d72a6e8 100644
@@ -523,7 +523,7 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
     }
     ret = vmdk_add_extent(bs, file, false,
                           le32_to_cpu(header.disk_sectors),
-                          le32_to_cpu(header.l1dir_offset) << 9,
+                          (int64_t)le32_to_cpu(header.l1dir_offset) << 9,
                           0,
                           le32_to_cpu(header.l1dir_size),
                           4096,
Signature · 1 line
1.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Fam Zheng

Coverity spotted this.

The field is 32 bits, but if it's possible to overflow in 32 bit left shift.

---
  block/vmdk.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
block/vmdk.c +0 -0
index 8410a15..d72a6e8 100644

block/vmdk.c static int vmdk_open_vmfs_sparse(BlockDriverState *bs, · line 529

Quoted 8 lines
block/vmdk.c +1 -1
@@ -523,7 +523,7 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
      }
      ret = vmdk_add_extent(bs, file, false,
                            le32_to_cpu(header.disk_sectors),
-                          le32_to_cpu(header.l1dir_offset) << 9,
+                          (int64_t)le32_to_cpu(header.l1dir_offset) << 9,
                            0,
                            le32_to_cpu(header.l1dir_size),
                            4096,
Applied
#2 lore raw

Am 27.04.2015 um 19:07 hat John Snow geschrieben:

Quoted 13 lines · Fam Zheng
Quoted 10 lines

Coverity spotted this.

The field is 32 bits, but if it's possible to overflow in 32 bit left shift.

---
 block/vmdk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 6 lines
block/vmdk.c +0 -0
index 8410a15..d72a6e8 100644

block/vmdk.c static int vmdk_open_vmfs_sparse(BlockDriverState *bs, · line 529

Quoted 8 lines
block/vmdk.c +1 -1
@@ -523,7 +523,7 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
     }
     ret = vmdk_add_extent(bs, file, false,
                           le32_to_cpu(header.disk_sectors),
-                          le32_to_cpu(header.l1dir_offset) << 9,
+                          (int64_t)le32_to_cpu(header.l1dir_offset) << 9,
                           0,
                           le32_to_cpu(header.l1dir_size),
                           4096,

Thanks, applied to the block branch.

Kevin