Skip to contentSkip to conversation

arm64/ptrace: Preserve previous registers for short regset write

PATCH New Dave P Martin 1 participant 5 messages Jan 18, 2017 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH v2 1/5 arm64/ptrace: Preserve previous registers for short regset write

In reply to a message not in the archive

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.

Cc <[email protected]> # 3.7.x-
Fixes 478fcb2cdb23 ("arm64: Debugging support")
---
 arch/arm64/kernel/ptrace.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/arm64/kernel/ptrace.c +4 -3
index fc35e06..8c0bc34 100644
@@ -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
#2 lore raw

PATCH v2 2/5 arm64/ptrace: Preserve previous registers for short regset write

In reply to a message not in the archive

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.

Cc <[email protected]> # 3.19.x-
Fixes 766a85d7bc5d ("arm64: ptrace: add NT_ARM_SYSTEM_CALL regset")
---
 arch/arm64/kernel/ptrace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/ptrace.c +2 -1
index 8c0bc34..ead36d5 100644
@@ -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
#3 lore raw

PATCH v2 3/5 arm64/ptrace: Preserve previous registers for short regset write

In reply to a message not in the archive

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.

Cc <[email protected]> # 4.3.x-
Fixes 5d220ff9420f ("arm64: Better native ptrace support for compat tasks")
---
 arch/arm64/kernel/ptrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/ptrace.c +1 -1
index ead36d5..91c4719 100644
@@ -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
#5 lore raw

PATCH v2 5/5 arm64/ptrace: Reject attempts to set incomplete hardware breakpoint fields

In reply to a message not in the archive

From: 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.

Cc <[email protected]> # 3.7.x-
Fixes 478fcb2cdb23 ("arm64: Debugging support")
---
 arch/arm64/kernel/ptrace.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm64/kernel/ptrace.c +4 -0
index 91c4719..a22161c 100644
@@ -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
#4 lore raw

PATCH v2 4/5 arm64/ptrace: Avoid uninitialised struct padding in fpr_set()

In reply to a message not in the archive

From: 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.

Cc <[email protected]> # 3.7.x-
Fixes 60ffc30d5652 ("arm64: Exception handling")
---
 arch/arm64/include/uapi/asm/ptrace.h | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/include/uapi/asm/ptrace.h +1 -0
index b5c3933..d1ff83d 100644
@@ -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