[Devel] [PATCH hci-8.1 v7 2/8] block/blk-cbt: shift the block size as unsigned
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Wed Oct 28 13:11:23 MSK 2026
cbt_ioc_init() accepts any power of two block size, so block_bits can be
31, and then 1 << block_bits overflows int. In blk_cbt_add() and
cbt_ioc_set() the sign extended block size then makes the rounded up
block counts wrong. Shift an unsigned one explicitly everywhere the
block size is computed.
https://virtuozzo.atlassian.net/browse/VSTOR-149268
Feature: cbt: changed block tracking (for backup)
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
block/blk-cbt.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/block/blk-cbt.c b/block/blk-cbt.c
index f4ee0a664156e..850a78da1dc24 100644
--- a/block/blk-cbt.c
+++ b/block/blk-cbt.c
@@ -229,7 +229,7 @@ static void blk_cbt_add(struct cbt_info *cbt, blkcnt_t start, blkcnt_t len)
if (unlikely(test_bit(CBT_ERROR, &cbt->flags)))
return;
- end = DIV_ROUND_UP(start + len, 1 << cbt->block_bits);
+ end = DIV_ROUND_UP(start + len, 1UL << cbt->block_bits);
start >>= cbt->block_bits;
len = end - start;
if (unlikely(test_bit(CBT_NOCACHE, &cbt->flags))) {
@@ -575,7 +575,7 @@ static void blk_cbt_update_cbt_size(struct cbt_info *cbt, loff_t new_sz)
unsigned bsz;
int in_use = 0;
- bsz = 1 << cbt->block_bits;
+ bsz = 1U << cbt->block_bits;
if (DIV_ROUND_UP(new_sz, bsz) <= cbt->block_max)
return;
@@ -964,7 +964,7 @@ static int cbt_ioc_set(struct block_device *bdev, struct blk_user_cbt_info __use
struct cbt_extent ex;
ex.start = cur_ex->ce_physical >> cbt->block_bits;
- ex.len = DIV_ROUND_UP(cur_ex->ce_length, 1 << cbt->block_bits);
+ ex.len = DIV_ROUND_UP(cur_ex->ce_length, 1UL << cbt->block_bits);
if (ex.start > cbt->block_max ||
ex.start + ex.len > cbt->block_max ||
ex.len == 0) {
--
2.55.0
More information about the Devel
mailing list