]> git.baikalelectronics.ru Git - kernel.git/commit
RISC-V: Fix out-of-bounds accesses in init_resources()
authorGeert Uytterhoeven <geert@linux-m68k.org>
Fri, 12 Mar 2021 15:46:34 +0000 (16:46 +0100)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Wed, 17 Mar 2021 04:55:11 +0000 (21:55 -0700)
commit234df43c154759a538fbd8d2268aa73d10424909
tree2fefbfccbc44de36c49b97887dfba8fa3a6d102e
parent6849209216549ac0c2bae9aa6617521c34ad9adf
RISC-V: Fix out-of-bounds accesses in init_resources()

init_resources() allocates an array of resources, based on the current
total number of memory regions and reserved memory regions.  However,
allocating this array using memblock_alloc() might increase the number
of reserved memory regions.  If that happens, populating the array later
based on the new number of regions will cause out-of-bounds writes
beyond the end of the allocated array.

Fix this by allocating one more entry, which may or may not be used.

Fixes: f02fdec44409cd1b ("RISC-V: Do not allocate memblock while iterating reserved memblocks")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/kernel/setup.c