[PATCH -next v17 16/20] riscv: prevent stack corruption by reserving task_pt_regs(p) early
Heiko Stübner
heiko at sntech.de
Fri Mar 31 06:38:41 PDT 2023
Am Montag, 27. März 2023, 18:49:36 CEST schrieb Andy Chiu:
> From: Greentime Hu <greentime.hu at sifive.com>
>
> Early function calls, such as setup_vm(), relocate_enable_mmu(),
> soc_early_init() etc, are free to operate on stack. However,
> PT_SIZE_ON_STACK bytes at the head of the kernel stack are purposedly
> reserved for the placement of per-task register context pointed by
> task_pt_regs(p). Those functions may corrupt task_pt_regs if we overlap
> the $sp with it. In fact, we had accidentally corrupted sstatus.VS in some
> tests, treating the kernel to save V context before V was actually
> allocated, resulting in a kernel panic.
>
> Thus, we should skip PT_SIZE_ON_STACK for $sp before making C function
> calls from the top-level assembly.
>
> Co-developed-by: ShihPo Hung <shihpo.hung at sifive.com>
> Signed-off-by: ShihPo Hung <shihpo.hung at sifive.com>
> Co-developed-by: Vincent Chen <vincent.chen at sifive.com>
> Signed-off-by: Vincent Chen <vincent.chen at sifive.com>
> Signed-off-by: Greentime Hu <greentime.hu at sifive.com>
> Signed-off-by: Andy Chiu <andy.chiu at sifive.com>
> Reviewed-by: Conor Dooley <conor.dooley at microchip.com>
Reviewed-by: Heiko Stuebner <heiko.stuebner at vrull.eu>
Tested-by: Heiko Stuebner <heiko.stuebner at vrull.eu>
More information about the linux-riscv
mailing list