Skip to contentSkip to conversation

riscv: process: fix kernel info leakage

PATCH Applied Jisheng Zhang 5 participants 5 messages Oct 29, 2022 – Nov 10, 2022 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")

---

Previously, it's one of the series of "riscv: entry: further clean up and VMAP_STACK fix". This is a fix, so I move it out of the series and send it separately

 arch/riscv/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/kernel/process.c +2 -0
index ceb9ebab6558..52002d54b163 100644
@@ -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 */
Signature · 1 line
2.37.2
Tested-by on v1 1/1
#1 lore raw
Quoted 23 lines · Jisheng Zhang

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")

---

Previously, it's one of the series of "riscv: entry: further clean up and VMAP_STACK fix". This is a fix, so I move it out of the series and send it separately

 arch/riscv/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/kernel/process.c +0 -0
index ceb9ebab6558..52002d54b163 100644

arch/riscv/kernel/process.c int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) · line 167

Quoted 4 lines
arch/riscv/kernel/process.c +1 -0
@@ -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));
Quoted 7 lines
arch/riscv/kernel/process.c +1 -1
+
        /* p->thread holds context to be restored by __switch_to() */
        if (unlikely(args->fn)) {
                /* Kernel thread */
--

2.37.2

Signature · 2 lines
Best Regards
 Guo Ren
#2 lore raw
In reply to Jisheng Zhang
Quoted 6 lines · Jisheng Zhang

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.

Quoted 7 lines
Fixes 7db91e57a0ac ("RISC-V: Task implementation")

---

Previously, it's one of the series of "riscv: entry: further clean up and VMAP_STACK fix". This is a fix, so I move it out of the series and send it separately

Should this not be carrying a R-b from Guo Ren from that series?
https://lore.kernel.org/linux-riscv/CAJF2gTSdVyAaM12T+7kXAdRPGS4VyuO08X1c7paE-n4Fr8OtRA@mail.gmail.com/

Quoted 20 lines
 arch/riscv/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/kernel/process.c +2 -0
index ceb9ebab6558..52002d54b163 100644
@@ -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 */
Signature · 1 line
2.37.2
#3 lore raw
In reply to Jisheng Zhang
Quoted 8 lines · Jisheng Zhang

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.

[...]

Applied, thanks!

[1/1] riscv: process: fix kernel info leakage

      https://git.kernel.org/palmer/c/6510c78490c4

Best regards,

Signature · 1 line
Palmer Dabbelt <[email protected]>
#4 lore raw
In reply to Jisheng Zhang
This patch was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <[email protected]>:

Quoted 10 lines · On Sat, 29 Oct 2022 19:34:50 +0800 you wrote:

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")

[...]

Here is the summary with links:
- riscv: process: fix kernel info leakage

    https://git.kernel.org/riscv/c/6510c78490c4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html