Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Introduce PTRACE_REGS_ALIGN, and on x86, enforce a ...



details:   https://anonhg.NetBSD.org/src/rev/ef7415c949ac
branches:  trunk
changeset: 933746:ef7415c949ac
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat May 30 08:41:22 2020 +0000

description:
Introduce PTRACE_REGS_ALIGN, and on x86, enforce a 16-byte alignment, due
to fpregs having fxsave which requires 16-byte alignment.

Reported-by: syzbot+f44d47e617ebf7fda081%syzkaller.appspotmail.com@localhost

diffstat:

 sys/arch/amd64/include/ptrace.h |   8 +++++++-
 sys/arch/i386/include/ptrace.h  |   8 +++++++-
 sys/kern/sys_ptrace_common.c    |  10 +++++++---
 3 files changed, 21 insertions(+), 5 deletions(-)

diffs (82 lines):

diff -r 9826fab1e82f -r ef7415c949ac sys/arch/amd64/include/ptrace.h
--- a/sys/arch/amd64/include/ptrace.h   Sat May 30 04:11:21 2020 +0000
+++ b/sys/arch/amd64/include/ptrace.h   Sat May 30 08:41:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.21 2020/01/08 17:21:38 mgorny Exp $       */
+/*     $NetBSD: ptrace.h,v 1.22 2020/05/30 08:41:22 maxv Exp $ */
 
 /*
  * Copyright (c) 1993 Christopher G. Demetriou
@@ -101,6 +101,12 @@
 int process_machdep_doxstate(struct lwp *, struct lwp *, struct uio *);
 int process_machdep_validfpu(struct proc *);
 
+/*
+ * The fpregs structure contains an fxsave area, which must have 16-byte
+ * alignment.
+ */
+#define PTRACE_REGS_ALIGN __aligned(16)
+
 #include <sys/module_hook.h>
 MODULE_HOOK(netbsd32_process_doxmmregs_hook, int,
     (struct lwp *, struct lwp *, void *, bool));
diff -r 9826fab1e82f -r ef7415c949ac sys/arch/i386/include/ptrace.h
--- a/sys/arch/i386/include/ptrace.h    Sat May 30 04:11:21 2020 +0000
+++ b/sys/arch/i386/include/ptrace.h    Sat May 30 08:41:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.25 2020/01/09 10:46:31 kamil Exp $        */
+/*     $NetBSD: ptrace.h,v 1.26 2020/05/30 08:41:23 maxv Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -187,6 +187,12 @@
            struct pfsnode *, struct uio *);
 int    procfs_machdep_validxmmregs(struct lwp *, struct mount *);
 
+/*
+ * The fpregs structure contains an fxsave area, which must have 16-byte
+ * alignment.
+ */
+#define PTRACE_REGS_ALIGN __aligned(16)
+
 #endif /* _KERNEL */
 
 #endif /* _I386_PTRACE_H_ */
diff -r 9826fab1e82f -r ef7415c949ac sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c      Sat May 30 04:11:21 2020 +0000
+++ b/sys/kern/sys_ptrace_common.c      Sat May 30 08:41:22 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_ptrace_common.c,v 1.82 2020/05/26 23:08:56 kamil Exp $     */
+/*     $NetBSD: sys_ptrace_common.c,v 1.83 2020/05/30 08:41:22 maxv Exp $      */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.82 2020/05/26 23:08:56 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.83 2020/05/30 08:41:22 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -214,6 +214,10 @@
 # define PT_REGISTERS
 #endif
 
+#ifndef PTRACE_REGS_ALIGN
+#define PTRACE_REGS_ALIGN /* nothing */
+#endif
+
 static int
 ptrace_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
     void *arg0, void *arg1, void *arg2, void *arg3)
@@ -1591,7 +1595,7 @@
 proc_regio(struct lwp *l, struct uio *uio, size_t ks, regrfunc_t r,
     regwfunc_t w)
 {
-       char buf[1024];
+       char buf[1024] PTRACE_REGS_ALIGN;
        int error;
        char *kv;
        size_t kl;



Home | Main Index | Thread Index | Old Index