Skip to contentSkip to conversation

ptrace: fix ptrace_regset() comments and diagnose errors specifically

PATCH In review Suresh Siddha 2 participants 9 messages Feb 22, 2010 – Feb 23, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ptrace: fix ptrace_regset() comments and diagnose errors specifically

Return -EINVAL for the bad size and for unrecognized NT_* type in ptrace_regset() instead of -EIO.

Also update the comments for this ptrace interface with more clarifications.

---
 include/linux/ptrace.h |    5 +++++
 kernel/ptrace.c        |    2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
kernel/ptrace.c +1 -1
Index: tip/kernel/ptrace.c
===================================================================
@@ -537,7 +537,7 @@ static int ptrace_regset(struct task_str
 	int regset_no;
 
 	if (!regset || (kiov->iov_len % regset->size) != 0)
-		return -EIO;
+		return -EINVAL;
 
 	regset_no = regset - view->regsets;
 	kiov->iov_len = min(kiov->iov_len,
include/linux/ptrace.h +5 -0
Index: tip/include/linux/ptrace.h
===================================================================
@@ -30,6 +30,11 @@
 /*
  * Generic ptrace interface that exports the architecture specific regsets
  * using the corresponding NT_* types (which are also used in the core dump).
+ * Please note that the NT_PRSTATUS note type in a core dump contains a full
+ * 'struct elf_prstatus'. But the user_regset for NT_PRSTATUS contains just the
+ * elf_gregset_t that is the pr_reg field of 'struct elf_prstatus'. For all the
+ * other user_regset flavors, the user_regset layout and the ELF core dump note
+ * payload are exactly the same layout.
  *
  * This interface usage is as follows:
  *	struct iovec iov = { buf, len};
#1 lore raw

PATCH 2/3 x86, ptrace: simplify xstateregs_get()

48 bytes (bytes 464..511) of the xstateregs payload come from the kernel defined structure (xstate_fx_sw_bytes). Rest comes from the xstate regs structure in the thread struct. Instead of having multiple user_regset_copyout()'s, simplify the xstateregs_get() by first copying the SW bytes into the xstate regs structure in the thread structure and then using one user_regset_copyout() to copyout the xstateregs.

---
 arch/x86/kernel/i387.c |   30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)
arch/x86/kernel/i387.c +7 -23
Index: tip/arch/x86/kernel/i387.c
===================================================================
@@ -243,34 +243,18 @@ int xstateregs_get(struct task_struct *t
 		return ret;
 
 	/*
-	 * First copy the fxsave bytes 0..463.
+	 * Copy the 48bytes defined by the software first into the xstate
+	 * memory layout in the thread struct, so that we can copy the entire
+	 * xstateregs to the user using one user_regset_copyout().
 	 */
-	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-				  &target->thread.xstate->xsave, 0,
-				  offsetof(struct user_xstateregs,
-					   i387.xstate_fx_sw));
-	if (ret)
-		return ret;
-
-	/*
-	 * Copy the 48bytes defined by software.
-	 */
-	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-				  xstate_fx_sw_bytes,
-				  offsetof(struct user_xstateregs,
-					   i387.xstate_fx_sw),
-				  offsetof(struct user_xstateregs,
-					   xsave_hdr));
-	if (ret)
-		return ret;
+	memcpy(&target->thread.xstate->fxsave.sw_reserved,
+	       xstate_fx_sw_bytes, sizeof(xstate_fx_sw_bytes));
 
 	/*
-	 * Copy the rest of xstate memory layout.
+	 * Copy the xstate memory layout.
 	 */
 	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-				  &target->thread.xstate->xsave.xsave_hdr,
-				  offsetof(struct user_xstateregs,
-					   xsave_hdr), -1);
+				  &target->thread.xstate->xsave, 0, -1);
 	return ret;
 }
 
#3 lore raw

[tip:x86/ptrace] x86, ptrace: Simplify xstateregs_get()

In reply to Suresh Siddha
Commit-ID:  ff7fbc72e0c3ef7e94a27a3a918fd09ec9a30204
Gitweb:     http://git.kernel.org/tip/ff7fbc72e0c3ef7e94a27a3a918fd09ec9a30204
Author:     Suresh Siddha <[email protected]>
AuthorDate: Mon, 22 Feb 2010 14:51:33 -0800
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Tue, 23 Feb 2010 13:45:27 -0800

x86, ptrace: Simplify xstateregs_get()

48 bytes (bytes 464..511) of the xstateregs payload come from the kernel defined structure (xstate_fx_sw_bytes). Rest comes from the xstate regs structure in the thread struct. Instead of having multiple user_regset_copyout()'s, simplify the xstateregs_get() by first copying the SW bytes into the xstate regs structure in the thread structure and then using one user_regset_copyout() to copyout the xstateregs.

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/i387.c |   30 +++++++-----------------------
 1 files changed, 7 insertions(+), 23 deletions(-)
arch/x86/kernel/i387.c +7 -23
index 7a8a193..81e23bf 100644
@@ -243,34 +243,18 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
 		return ret;
 
 	/*
-	 * First copy the fxsave bytes 0..463.
+	 * Copy the 48bytes defined by the software first into the xstate
+	 * memory layout in the thread struct, so that we can copy the entire
+	 * xstateregs to the user using one user_regset_copyout().
 	 */
-	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-				  &target->thread.xstate->xsave, 0,
-				  offsetof(struct user_xstateregs,
-					   i387.xstate_fx_sw));
-	if (ret)
-		return ret;
-
-	/*
-	 * Copy the 48bytes defined by software.
-	 */
-	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-				  xstate_fx_sw_bytes,
-				  offsetof(struct user_xstateregs,
-					   i387.xstate_fx_sw),
-				  offsetof(struct user_xstateregs,
-					   xsave_hdr));
-	if (ret)
-		return ret;
+	memcpy(&target->thread.xstate->fxsave.sw_reserved,
+	       xstate_fx_sw_bytes, sizeof(xstate_fx_sw_bytes));
 
 	/*
-	 * Copy the rest of xstate memory layout.
+	 * Copy the xstate memory layout.
 	 */
 	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-				  &target->thread.xstate->xsave.xsave_hdr,
-				  offsetof(struct user_xstateregs,
-					   xsave_hdr), -1);
+				  &target->thread.xstate->xsave, 0, -1);
 	return ret;
 }
 
#4 lore raw

PATCH 3/3 x86, ptrace: remove set_stopped_child_used_math() in [x]fpregs_set

In reply to Suresh Siddha

init_fpu() already ensures that the used_math() is set for the stopped child. Remove the redundant set_stopped_child_used_math() in [x]fpregs_set()

---
 arch/x86/kernel/i387.c |    4 ----
 1 file changed, 4 deletions(-)
arch/x86/kernel/i387.c +0 -4
Index: tip/arch/x86/kernel/i387.c
===================================================================
@@ -209,8 +209,6 @@ int xfpregs_set(struct task_struct *targ
 	if (ret)
 		return ret;
 
-	set_stopped_child_used_math(target);
-
 	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 				 &target->thread.xstate->fxsave, 0, -1);
 
@@ -471,8 +469,6 @@ int fpregs_set(struct task_struct *targe
 	if (ret)
 		return ret;
 
-	set_stopped_child_used_math(target);
-
 	if (!HAVE_HWFP)
 		return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf);
 
#6 lore raw

[tip:x86/ptrace] x86, ptrace: Remove set_stopped_child_used_math() in [x]fpregs_set

In reply to Suresh Siddha
Commit-ID:  6dbbe14f21368a45aedba7eab0221857b8ad8d16
Gitweb:     http://git.kernel.org/tip/6dbbe14f21368a45aedba7eab0221857b8ad8d16
Author:     Suresh Siddha <[email protected]>
AuthorDate: Mon, 22 Feb 2010 14:51:34 -0800
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Tue, 23 Feb 2010 13:45:27 -0800

x86, ptrace: Remove set_stopped_child_used_math() in [x]fpregs_set

init_fpu() already ensures that the used_math() is set for the stopped child. Remove the redundant set_stopped_child_used_math() in [x]fpregs_set()

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/i387.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)
arch/x86/kernel/i387.c +0 -4
index 81e23bf..c01a2b8 100644
@@ -209,8 +209,6 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
 	if (ret)
 		return ret;
 
-	set_stopped_child_used_math(target);
-
 	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 				 &target->thread.xstate->fxsave, 0, -1);
 
@@ -471,8 +469,6 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
 	if (ret)
 		return ret;
 
-	set_stopped_child_used_math(target);
-
 	if (!HAVE_HWFP)
 		return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf);
 
#8 lore raw

[tip:x86/ptrace] ptrace: Fix ptrace_regset() comments and diagnose errors specifically

In reply to Suresh Siddha
Commit-ID:  c6a0dd7ec6fb2d4927979ed4dc562fc5c122d826
Gitweb:     http://git.kernel.org/tip/c6a0dd7ec6fb2d4927979ed4dc562fc5c122d826
Author:     Suresh Siddha <[email protected]>
AuthorDate: Mon, 22 Feb 2010 14:51:32 -0800
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Tue, 23 Feb 2010 13:45:26 -0800

ptrace: Fix ptrace_regset() comments and diagnose errors specifically

Return -EINVAL for the bad size and for unrecognized NT_* type in ptrace_regset() instead of -EIO.

Also update the comments for this ptrace interface with more clarifications.

LKML-Reference: <[email protected]>

---
 include/linux/ptrace.h |    5 +++++
 kernel/ptrace.c        |    2 +-
 2 files changed, 6 insertions(+), 1 deletions(-)
include/linux/ptrace.h +5 -0
index dbfa821..c5eab89 100644
@@ -30,6 +30,11 @@
 /*
  * Generic ptrace interface that exports the architecture specific regsets
  * using the corresponding NT_* types (which are also used in the core dump).
+ * Please note that the NT_PRSTATUS note type in a core dump contains a full
+ * 'struct elf_prstatus'. But the user_regset for NT_PRSTATUS contains just the
+ * elf_gregset_t that is the pr_reg field of 'struct elf_prstatus'. For all the
+ * other user_regset flavors, the user_regset layout and the ELF core dump note
+ * payload are exactly the same layout.
  *
  * This interface usage is as follows:
  *	struct iovec iov = { buf, len};
kernel/ptrace.c +1 -1
index 13b4554..42ad8ae 100644
@@ -537,7 +537,7 @@ static int ptrace_regset(struct task_struct *task, int req, unsigned int type,
 	int regset_no;
 
 	if (!regset || (kiov->iov_len % regset->size) != 0)
-		return -EIO;
+		return -EINVAL;
 
 	regset_no = regset - view->regsets;
 	kiov->iov_len = min(kiov->iov_len,