Skip to content

Commit

Permalink
Introduce PTRACE_REGS_ALIGN, and on x86, enforce a 16-byte alignment,…
Browse files Browse the repository at this point in the history
… due

to fpregs having fxsave which requires 16-byte alignment.

Reported-by: syzbot+f44d47e617ebf7fda081@syzkaller.appspotmail.com
  • Loading branch information
maxv authored and maxv committed May 30, 2020
1 parent 907d055 commit 4660020
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
8 changes: 7 additions & 1 deletion sys/arch/amd64/include/ptrace.h
@@ -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
Expand Down Expand Up @@ -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));
Expand Down
8 changes: 7 additions & 1 deletion sys/arch/i386/include/ptrace.h
@@ -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.
Expand Down Expand Up @@ -187,6 +187,12 @@ int procfs_machdep_doxmmregs(struct lwp *, struct lwp *,
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_ */
10 changes: 7 additions & 3 deletions sys/kern/sys_ptrace_common.c
@@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -214,6 +214,10 @@ static kcondvar_t ptrace_cv;
# 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)
Expand Down Expand Up @@ -1591,7 +1595,7 @@ static int
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;
Expand Down

0 comments on commit 4660020

Please sign in to comment.