1dc728923Sopenharmony_ciFrom 27504bcf89193d47d7632cde922a65e0c051be01 Mon Sep 17 00:00:00 2001
2dc728923Sopenharmony_ciFrom: Theodore Ts'o <tytso@mit.edu>
3dc728923Sopenharmony_ciDate: Tue, 9 Aug 2022 11:16:47 -0400
4dc728923Sopenharmony_ciSubject: libext2fs: fix potential integer overflow in bitmap accessors
5dc728923Sopenharmony_ci
6dc728923Sopenharmony_cibmap->cluster_bits has a maximum value of 19, but Coverity doesn't
7dc728923Sopenharmony_ciknow that.  To make it happy, and just in case there is a bug where
8dc728923Sopenharmony_cisomehow the cluster size does get set to an invalid value and the rest
9dc728923Sopenharmony_ciof the library doesn't check it, use 1ULL instead of 1 to avoid the
10dc728923Sopenharmony_ciinteger overflow.
11dc728923Sopenharmony_ci
12dc728923Sopenharmony_ciAddresses-Coverity-Bug: 1500759
13dc728923Sopenharmony_ciAddresses-Coverity-Bug: 1500764
14dc728923Sopenharmony_ciAddresses-Coverity-Bug: 1500771
15dc728923Sopenharmony_ciSigned-off-by: Theodore Ts'o <tytso@mit.edu>
16dc728923Sopenharmony_ci---
17dc728923Sopenharmony_ci lib/ext2fs/gen_bitmap64.c | 6 +++---
18dc728923Sopenharmony_ci 1 file changed, 3 insertions(+), 3 deletions(-)
19dc728923Sopenharmony_ci
20dc728923Sopenharmony_cidiff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
21dc728923Sopenharmony_ciindex d9809084..c860c10e 100644
22dc728923Sopenharmony_ci--- a/lib/ext2fs/gen_bitmap64.c
23dc728923Sopenharmony_ci+++ b/lib/ext2fs/gen_bitmap64.c
24dc728923Sopenharmony_ci@@ -684,7 +684,7 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap gen_bmap,
25dc728923Sopenharmony_ci 
26dc728923Sopenharmony_ci 	/* convert to clusters if necessary */
27dc728923Sopenharmony_ci 	block >>= bmap->cluster_bits;
28dc728923Sopenharmony_ci-	end += (1 << bmap->cluster_bits) - 1;
29dc728923Sopenharmony_ci+	end += (1ULL << bmap->cluster_bits) - 1;
30dc728923Sopenharmony_ci 	end >>= bmap->cluster_bits;
31dc728923Sopenharmony_ci 	num = end - block;
32dc728923Sopenharmony_ci 
33dc728923Sopenharmony_ci@@ -725,7 +725,7 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap gen_bmap,
34dc728923Sopenharmony_ci 
35dc728923Sopenharmony_ci 	/* convert to clusters if necessary */
36dc728923Sopenharmony_ci 	block >>= bmap->cluster_bits;
37dc728923Sopenharmony_ci-	end += (1 << bmap->cluster_bits) - 1;
38dc728923Sopenharmony_ci+	end += (1ULL << bmap->cluster_bits) - 1;
39dc728923Sopenharmony_ci 	end >>= bmap->cluster_bits;
40dc728923Sopenharmony_ci 	num = end - block;
41dc728923Sopenharmony_ci 
42dc728923Sopenharmony_ci@@ -766,7 +766,7 @@ void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap gen_bmap,
43dc728923Sopenharmony_ci 
44dc728923Sopenharmony_ci 	/* convert to clusters if necessary */
45dc728923Sopenharmony_ci 	block >>= bmap->cluster_bits;
46dc728923Sopenharmony_ci-	end += (1 << bmap->cluster_bits) - 1;
47dc728923Sopenharmony_ci+	end += (1ULL << bmap->cluster_bits) - 1;
48dc728923Sopenharmony_ci 	end >>= bmap->cluster_bits;
49dc728923Sopenharmony_ci 	num = end - block;
50dc728923Sopenharmony_ci 
51dc728923Sopenharmony_ci-- 
52dc728923Sopenharmony_cicgit 
53dc728923Sopenharmony_ci
54