* [PATCH] riscv: ptrace: Initialize cregs before copyin in compat_riscv_gpr_set()
@ 2026-11-18 5:39 Hyunjung Ko
0 siblings, 0 replies; only message in thread
From: Hyunjung Ko @ 2026-11-18 5:39 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
Cc: Oleg Nesterov, Guo Ren, linux-riscv, linux-kernel, stable, Hyunjung Ko
user_regset_copyin() only copies `count` bytes, so a PTRACE_SETREGSET
request with a short (or zero) iov_len leaves the rest of the on-stack
cregs uninitialized. cregs_to_regs() then copies all of it into the
tracee's pt_regs, where the tracer can read it back with
PTRACE_GETREGSET.
Fill cregs from the current register state first, so that a partial
write only updates the registers it covers, as riscv_gpr_set() does.
Fixes: 4608c159594f ("riscv: compat: ptrace: Add compat_arch_ptrace implement")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c
index a005574..32227b7 100644
--- a/arch/riscv/kernel/ptrace.c
+++ b/arch/riscv/kernel/ptrace.c
@@ -584,6 +584,8 @@ static int compat_riscv_gpr_set(struct task_struct *target,
int ret;
struct compat_user_regs_struct cregs;
+ regs_to_cregs(&cregs, task_pt_regs(target));
+
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &cregs, 0, -1);
if (!ret)
cregs_to_regs(&cregs, task_pt_regs(target));
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 5:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 5:39 [PATCH] riscv: ptrace: Initialize cregs before copyin in compat_riscv_gpr_set() Hyunjung Ko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®