|
|
393826 |
From 21e41eeef968941c1ee0126852fdb705967730ea Mon Sep 17 00:00:00 2001
|
|
|
393826 |
From: Theodore Ts'o <tytso@mit.edu>
|
|
|
393826 |
Date: Fri, 8 Nov 2019 11:58:10 -0500
|
|
|
393826 |
Subject: [PATCH 05/10] libext2fs: verify the block numbers for the allocation
|
|
|
393826 |
bitmaps are valid
|
|
|
393826 |
|
|
|
393826 |
This avoids a potential UBsan failure when we multiply an insanely
|
|
|
393826 |
high block number with the block size and we get a multiplication
|
|
|
393826 |
overflow.
|
|
|
393826 |
|
|
|
393826 |
Google-Bug-Id: 128130353
|
|
|
393826 |
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
|
|
393826 |
---
|
|
|
393826 |
lib/ext2fs/rw_bitmaps.c | 14 ++++++++------
|
|
|
393826 |
1 file changed, 8 insertions(+), 6 deletions(-)
|
|
|
393826 |
|
|
|
393826 |
diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c
|
|
|
393826 |
index e092cab0..d80c9eb8 100644
|
|
|
393826 |
--- a/lib/ext2fs/rw_bitmaps.c
|
|
|
393826 |
+++ b/lib/ext2fs/rw_bitmaps.c
|
|
|
393826 |
@@ -306,9 +306,10 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
|
|
|
393826 |
for (i = 0; i < fs->group_desc_count; i++) {
|
|
|
393826 |
if (block_bitmap) {
|
|
|
393826 |
blk = ext2fs_block_bitmap_loc(fs, i);
|
|
|
393826 |
- if (csum_flag &&
|
|
|
393826 |
- ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) &&
|
|
|
393826 |
- ext2fs_group_desc_csum_verify(fs, i))
|
|
|
393826 |
+ if ((csum_flag &&
|
|
|
393826 |
+ ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) &&
|
|
|
393826 |
+ ext2fs_group_desc_csum_verify(fs, i)) ||
|
|
|
393826 |
+ (blk >= ext2fs_blocks_count(fs->super)))
|
|
|
393826 |
blk = 0;
|
|
|
393826 |
if (blk) {
|
|
|
393826 |
retval = io_channel_read_blk64(fs->io, blk,
|
|
|
393826 |
@@ -340,9 +341,10 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
|
|
|
393826 |
}
|
|
|
393826 |
if (inode_bitmap) {
|
|
|
393826 |
blk = ext2fs_inode_bitmap_loc(fs, i);
|
|
|
393826 |
- if (csum_flag &&
|
|
|
393826 |
- ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) &&
|
|
|
393826 |
- ext2fs_group_desc_csum_verify(fs, i))
|
|
|
393826 |
+ if ((csum_flag &&
|
|
|
393826 |
+ ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) &&
|
|
|
393826 |
+ ext2fs_group_desc_csum_verify(fs, i)) ||
|
|
|
393826 |
+ (blk >= ext2fs_blocks_count(fs->super)))
|
|
|
393826 |
blk = 0;
|
|
|
393826 |
if (blk) {
|
|
|
393826 |
retval = io_channel_read_blk64(fs->io, blk,
|
|
|
393826 |
--
|
|
|
393826 |
2.21.1
|
|
|
393826 |
|