arm64/ptrace: Preserve previous registers for short regset write
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/5 arm64/ptrace: Preserve previous registers for short regset write
From: Dave Martin <[email protected]>
Ensure that if userspace supplies insufficient data to PTRACE_SETREGSET to fill all the registers, the thread's old registers are preserved.
--- arch/arm64/kernel/ptrace.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/arm64/kernel/ptrace.c +4 -3
@@ -596,7 +596,7 @@ static int gpr_set(struct task_struct *target, const struct user_regset *regset, const void *kbuf, const void __user *ubuf) { int ret; -struct user_pt_regs newregs; +struct user_pt_regs newregs =task_pt_regs (target)->user_regs; ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &newregs,0 ,-1 );if (ret)
@@ -626,7 +626,8 @@ static int fpr_set(struct task_struct *target, const struct user_regset *regset, const void *kbuf, const void __user *ubuf) { int ret; -struct user_fpsimd_state newstate; +struct user_fpsimd_state newstate = + target->thread.fpsimd_state.user_fpsimd; ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &newstate,0 ,-1 );if (ret)
@@ -650,7 +651,7 @@ static int tls_set(struct task_struct *target, const struct user_regset *regset, const void *kbuf, const void __user *ubuf) { int ret; -unsigned long tls; +unsigned long tls = target->thread.tp_value; ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &tls,0 ,-1 );if (ret)
Signature · 1 line
2.1.4
PATCH v2 2/5 arm64/ptrace: Preserve previous registers for short regset write
In reply to a message not in the archiveFrom: Dave Martin <[email protected]>
Ensure that if userspace supplies insufficient data to PTRACE_SETREGSET to fill all the registers, the thread's old registers are preserved.
--- arch/arm64/kernel/ptrace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/ptrace.c +2 -1
@@ -677,7 +677,8 @@ static int system_call_set(struct task_struct *target, unsigned int pos, unsigned int count, const void *kbuf, const void __user *ubuf) { - int syscallno, ret; + int syscallno = task_pt_regs(target)->syscallno; +int ret; ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &syscallno,0 ,-1 );if (ret)
Signature · 1 line
2.1.4
PATCH v2 3/5 arm64/ptrace: Preserve previous registers for short regset write
In reply to a message not in the archiveFrom: Dave Martin <[email protected]>
Ensure that if userspace supplies insufficient data to PTRACE_SETREGSET to fill all the registers, the thread's old registers are preserved.
--- arch/arm64/kernel/ptrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/ptrace.c +1 -1
@@ -950,7 +950,7 @@ static int compat_tls_set(struct task_struct *target, const void __user *ubuf) {int ret; -compat_ulong_t tls; +compat_ulong_t tls = target->thread.tp_value; ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &tls,0 ,-1 );if (ret)
Signature · 1 line
2.1.4
PATCH v2 4/5 arm64/ptrace: Avoid uninitialised struct padding in fpr_set()
In reply to a message not in the archiveFrom: Dave Martin <[email protected]>
This patch adds an explicit __reserved[] field to user_fpsimd_state to replace what was previously unnamed padding.
This ensures that data in this region are propagated across assignment rather than being left possibly uninitialised at the destination.
--- arch/arm64/include/uapi/asm/ptrace.h | 1 + 1 file changed, 1 insertion(+)
arch/arm64/include/uapi/asm/ptrace.h +1 -0
@@ -77,6 +77,7 @@ struct user_fpsimd_state {__uint128_t vregs[32 ];__u32 fpsr;__u32 fpcr; +__u32 __reserved[2 ]; };struct user_hwdebug_state {
Signature · 1 line
2.1.4
PATCH v2 5/5 arm64/ptrace: Reject attempts to set incomplete hardware breakpoint fields
In reply to a message not in the archiveFrom: Dave Martin <[email protected]>
We cannot preserve partial fields for hardware breakpoints, because the values written by userspace to the hardware breakpoint registers can't subsequently be recovered intact from the hardware.
So, just reject attempts to write incomplete fields with -EINVAL.
--- arch/arm64/kernel/ptrace.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/kernel/ptrace.c +4 -0
@@ -551,6 +551,8 @@ static int hw_break_set(struct task_struct *target,/* (address, ctrl) registers */ limit = regset->n * regset->size;while (count && offset < limit) { +if (count <PTRACE_HBP_ADDR_SZ ) +return -EINVAL ; ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &addr, offset, offset +PTRACE_HBP_ADDR_SZ );if (ret)
@@ -560,6 +562,8 @@ static int hw_break_set(struct task_struct *target,return ret; offset +=PTRACE_HBP_ADDR_SZ ; +if (!count) +break ; ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &ctrl, offset, offset +PTRACE_HBP_CTRL_SZ );if (ret)
Signature · 1 line
2.1.4