Skip to contentSkip to conversation

ext4: ext4_mb_seq_groups_show: Fix stack memory corruption

PATCH Applied Chandan Rajendra 3 participants 3 messages Nov 10, 2016 – Nov 15, 2016 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ext4: ext4_mb_seq_groups_show: Fix stack memory corruption

The number of 'counters' elements needed in 'struct sg' is super_block->s_blocksize_bits + 2. Presently we have 16 'counters' elements in the array. This is insufficient for block sizes >= 32k. In such cases the memcpy operation performed in ext4_mb_seq_groups_show() would cause stack memory corruption.

---
Changelog:
v1->v2: Use EXT4_MAX_BLOCK_LOG_SIZE instead of the integer constant 16.

 fs/ext4/mballoc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/mballoc.c +1 -1
index a937ac7..7ae43c5 100644
@@ -2287,7 +2287,7 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
 	struct ext4_group_info *grinfo;
 	struct sg {
 		struct ext4_group_info info;
-		ext4_grpblk_t counters[16];
+		ext4_grpblk_t counters[EXT4_MAX_BLOCK_LOG_SIZE + 2];
 	} sg;
 
 	group--;
Signature · 1 line
2.5.5
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Chandan Rajendra

The number of 'counters' elements needed in 'struct sg' is super_block->s_blocksize_bits + 2. Presently we have 16 'counters' elements in the array. This is insufficient for block sizes >= 32k. In such cases the memcpy operation performed in ext4_mb_seq_groups_show() would cause stack memory corruption.

Looks good. You can add:

Honza

Quoted 23 lines

---
Changelog:
v1->v2: Use EXT4_MAX_BLOCK_LOG_SIZE instead of the integer constant 16.

 fs/ext4/mballoc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/mballoc.c +1 -1
index a937ac7..7ae43c5 100644
@@ -2287,7 +2287,7 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
 	struct ext4_group_info *grinfo;
 	struct sg {
 		struct ext4_group_info info;
-		ext4_grpblk_t counters[16];
+		ext4_grpblk_t counters[EXT4_MAX_BLOCK_LOG_SIZE + 2];
 	} sg;
 
 	group--;
Signature · 1 line
2.5.5
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#2 lore raw
Quoted 7 lines · Jan Kara
Quoted 6 lines · Chandan Rajendra

The number of 'counters' elements needed in 'struct sg' is super_block->s_blocksize_bits + 2. Presently we have 16 'counters' elements in the array. This is insufficient for block sizes >= 32k. In such cases the memcpy operation performed in ext4_mb_seq_groups_show() would cause stack memory corruption.

Quoted 5 lines
Quoted 1 line

Looks good. You can add:

Applied, thanks!

- Ted