Skip to content

Commit c0232ae

Browse files
Lin Fengtorvalds
Lin Feng
authored andcommitted
mm: memblock: fix wrong memmove size in memblock_merge_regions()
The memmove span covers from (next+1) to the end of the array, and the index of next is (i+1), so the index of (next+1) is (i+2). So the size of remaining array elements is (type->cnt - (i + 2)). Since the remaining elements of the memblock array are move forward by one element and there is only one additional element caused by this bug. So there won't be any write overflow here but read overflow. It may read one more element out of the array address if the array happens to be full. Commonly it doesn't matter at all but if the array happens to be located at the end a memblock, it may cause a invalid read operation for the physical address doesn't exist. There are 2 *happens to be* here, so I think the probability is quite low, I don't know if any guy is haunted by this bug before. Mostly I think it's user-invisible. Signed-off-by: Lin Feng <[email protected]> Acked-by: Tejun Heo <[email protected]> Reviewed-by: Wanpeng Li <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 552f0cc commit c0232ae

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mm/memblock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ static void __init_memblock memblock_merge_regions(struct memblock_type *type)
314314
}
315315

316316
this->size += next->size;
317-
memmove(next, next + 1, (type->cnt - (i + 1)) * sizeof(*next));
317+
/* move forward from next + 1, index of which is i + 2 */
318+
memmove(next, next + 1, (type->cnt - (i + 2)) * sizeof(*next));
318319
type->cnt--;
319320
}
320321
}

0 commit comments

Comments
 (0)