From: Jisheng Zhang Date: Sat, 29 Oct 2022 11:34:50 +0000 (+0800) Subject: riscv: process: fix kernel info leakage X-Git-Tag: v6.1-rc5~15^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6510c78490c490a6636e48b61eeaa6fb65981f4b;p=platform%2Fkernel%2Flinux-starfive.git riscv: process: fix kernel info leakage thread_struct's s[12] may contain random kernel memory content, which may be finally leaked to userspace. This is a security hole. Fix it by clearing the s[12] array in thread_struct when fork. As for kthread case, it's better to clear the s[12] array as well. Fixes: 7db91e57a0ac ("RISC-V: Task implementation") Signed-off-by: Jisheng Zhang Tested-by: Guo Ren Link: https://lore.kernel.org/r/20221029113450.4027-1-jszhang@kernel.org Reviewed-by: Guo Ren Link: https://lore.kernel.org/r/CAJF2gTSdVyAaM12T%2B7kXAdRPGS4VyuO08X1c7paE-n4Fr8OtRA@mail.gmail.com/ Signed-off-by: Palmer Dabbelt --- diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index b0c63e8..8955f24 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -164,6 +164,8 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) unsigned long tls = args->tls; struct pt_regs *childregs = task_pt_regs(p); + memset(&p->thread.s, 0, sizeof(p->thread.s)); + /* p->thread holds context to be restored by __switch_to() */ if (unlikely(args->fn)) { /* Kernel thread */