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.
Signed-off-by: Chandan Rajendra <[email protected]>
---
fs/ext4/mballoc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index a937ac7..67e6fcb 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -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[16 + 2];
} sg;
group--;
--
2.5.5
On Mon 07-11-16 12:15:41, Chandan Rajendra wrote:
> 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.
>
> Signed-off-by: Chandan Rajendra <[email protected]>
> ---
> fs/ext4/mballoc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index a937ac7..67e6fcb 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -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[16 + 2];
How about using EXT4_MAX_BLOCK_LOG_SIZE + 2? It would be somewhat clearer
what that means... Having a function returning number of buddy counters in
a group info would be even better (and a constant for maximum number of
counters) but that's an independent cleanup...
Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR
On Tuesday, November 08, 2016 10:21:15 AM Jan Kara wrote:
> On Mon 07-11-16 12:15:41, Chandan Rajendra wrote:
> > 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.
> >
> > Signed-off-by: Chandan Rajendra <[email protected]>
> > ---
> > fs/ext4/mballoc.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> > index a937ac7..67e6fcb 100644
> > --- a/fs/ext4/mballoc.c
> > +++ b/fs/ext4/mballoc.c
> > @@ -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[16 + 2];
>
> How about using EXT4_MAX_BLOCK_LOG_SIZE + 2? It would be somewhat clearer
> what that means... Having a function returning number of buddy counters in
> a group info would be even better (and a constant for maximum number of
> counters) but that's an independent cleanup...
Sorry about the late reply. I will send out V2 with the fix. Also, I will work
on the cleanup patch and send it out soon.
--
chandan