lkml.org 
[lkml]   [2021]   [Jun]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [patch V2 15/52] x86/fpu: Use copy_uabi_xstate_to_membuf() in xfpregs_get()
On Thu, Jun 17, 2021 at 10:59:55AM +0200, Borislav Petkov wrote:
> manpage says "PTRACE_GETREGS and PTRACE_GETFPREGS are not present on all
> architectures." which could explain why. I wonder if we should add some
> stupid test cases so that we can at least exercise this...

How's this rough thing?

What I'd do in the final version is verify the values we preset in
fpstate_init_fstate() and in fpstate_init_fxstate() with what this test
reads and this way we'll catch any changes in that area.

diff --git a/tools/testing/selftests/x86/ptrace_syscall.c b/tools/testing/selftests/x86/ptrace_syscall.c
index 12aaa063196e..ac73cca7300f 100644
--- a/tools/testing/selftests/x86/ptrace_syscall.c
+++ b/tools/testing/selftests/x86/ptrace_syscall.c
@@ -407,7 +407,62 @@ static void test_restart_under_ptrace(void)
err(1, "waitpid");
}

-int main()
+static void test_ptrace_a_bit(void)
+{
+ struct user_fpregs_struct regs;
+ int status;
+ pid_t chld;
+
+ printf("[RUN]\tTest some ptrace(2) requests\n");
+
+ chld = fork();
+ if (chld < 0)
+ err(1, "fork");
+
+ if (!chld) {
+ if (ptrace(PTRACE_TRACEME, 0, 0, 0) != 0)
+ err(1, "PTRACE_TRACEME");
+
+ pid_t pid = getpid(), tid = syscall(SYS_gettid);
+
+ printf("\tChild will take a nap until signaled\n");
+ setsigign(SIGUSR1, SA_RESTART);
+ syscall(SYS_tgkill, pid, tid, SIGSTOP);
+
+ syscall(SYS_pause, 0, 0, 0, 0, 0, 0);
+ _exit(0);
+ }
+
+ /* Wait for SIGSTOP. */
+ if (waitpid(chld, &status, 0) != chld || !WIFSTOPPED(status))
+ err(1, "waitpid");
+
+ printf("[RUN]\tGETFPREGS\n");
+ if (ptrace(PTRACE_GETFPREGS, chld, 0, &regs) != 0)
+ err(1, "PTRACE_GETFPREGS");
+
+#ifdef __i386__
+ printf("__i386__\n");
+ printf("cwd: 0x%lx, swd: 0x%lx\n", regs.cwd, regs.swd);
+ printf("twd: 0x%lx, fip: 0x%lx\n", regs.twd, regs.fip);
+ printf("fcs: 0x%lx, foo: 0x%lx\n", regs.fcs, regs.foo);
+ printf("fos: 0x%lx, st_space[0]: 0x%lx\n", regs.fos, regs.st_space[0]);
+#else
+ printf("__x86_64__\n");
+ printf("cwd: 0x%x, swd: 0x%x\n", regs.cwd, regs.swd);
+ printf("ftw: 0x%x, fop: 0x%x\n", regs.ftw, regs.fop);
+ printf("rip: 0x%llx, rdp: 0x%llx\n", regs.rip, regs.rdp);
+ /* Yeah, it is mxcr_mask - sys/user.h has a typo :-) */
+ printf("mxcsr: 0x%x, mxcsr_mask: 0x%x\n", regs.mxcsr, regs.mxcr_mask);
+#endif
+
+ /* Kill it. */
+ kill(chld, SIGKILL);
+ if (waitpid(chld, &status, 0) != chld)
+ err(1, "waitpid");
+}
+
+int main(void)
{
printf("[RUN]\tCheck int80 return regs\n");
test_sys32_regs(do_full_int80);
@@ -426,5 +481,7 @@ int main()

test_restart_under_ptrace();

+ test_ptrace_a_bit();
+
return 0;
}
--
Regards/Gruss,
Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg

\
 
 \ /
  Last update: 2021-06-18 13:20    [W:0.083 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site