Commit 47e684aa authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Linus Torvalds

lib/stackdepot.c: use flex_array_size() helper in memcpy()

Make use of the flex_array_size() helper to calculate the size of a
flexible array member within an enclosing structure.

This helper offers defense-in-depth against potential integer overflows,
while at the same time makes it explicitly clear that we are dealing with
a flexible array member.

Link: https://lkml.kernel.org/r/186e37fe07196ee41a0e562fa8a8cb7a01112ec5.1601565471.git.gustavoars@kernel.orgSigned-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3a2b67e6
...@@ -135,7 +135,7 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size, ...@@ -135,7 +135,7 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size,
stack->handle.slabindex = depot_index; stack->handle.slabindex = depot_index;
stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN; stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN;
stack->handle.valid = 1; stack->handle.valid = 1;
memcpy(stack->entries, entries, size * sizeof(unsigned long)); memcpy(stack->entries, entries, flex_array_size(stack, entries, size));
depot_offset += required_size; depot_offset += required_size;
return stack; return stack;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment