-SUS says that a successful call to setcontext(2) does not return. This
implies that _UC_CPU must be set in the context passed. Check for this and return EINVAL if not; this gives a cheap test for corrupted ucontexts eg on a signal handler stack which would go unnoticed otherwise. -Don't ckeck for NULL ucontext pointers explicitely. This is an error, except in the swapcontext() case where it can be easily caught in userland.
This commit is contained in:
parent
f499cd524a
commit
b1af2cb9b9
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: netbsd32_signal.c,v 1.17 2006/03/15 09:09:47 cube Exp $ */
|
||||
/* $NetBSD: netbsd32_signal.c,v 1.18 2006/11/08 20:18:32 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
|
@ -29,7 +29,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.17 2006/03/15 09:09:47 cube Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.18 2006/11/08 20:18:32 drochner Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -399,10 +399,13 @@ netbsd32_setcontext(struct lwp *l, void *v, register_t *retval)
|
|||
void *p;
|
||||
|
||||
p = NETBSD32PTR64(SCARG(uap, ucp));
|
||||
if (p == NULL)
|
||||
exit1(l, W_EXITCODE(0, 0));
|
||||
else if ((error = copyin(p, &uc, sizeof (uc))) != 0 ||
|
||||
(error = setucontext32(l, &uc)) != 0)
|
||||
error = copyin(p, &uc, sizeof (uc));
|
||||
if (error)
|
||||
return (error);
|
||||
if (!(uc.uc_flags & _UC_CPU))
|
||||
return (EINVAL);
|
||||
error = setucontext32(l, &uc);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
return (EJUSTRETURN);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kern_sig.c,v 1.238 2006/11/03 19:46:03 ad Exp $ */
|
||||
/* $NetBSD: kern_sig.c,v 1.239 2006/11/08 20:18:33 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1989, 1991, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.238 2006/11/03 19:46:03 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.239 2006/11/08 20:18:33 drochner Exp $");
|
||||
|
||||
#include "opt_coredump.h"
|
||||
#include "opt_ktrace.h"
|
||||
|
@ -2382,10 +2382,13 @@ sys_setcontext(struct lwp *l, void *v, register_t *retval)
|
|||
ucontext_t uc;
|
||||
int error;
|
||||
|
||||
if (SCARG(uap, ucp) == NULL) /* i.e. end of uc_link chain */
|
||||
exit1(l, W_EXITCODE(0, 0));
|
||||
else if ((error = copyin(SCARG(uap, ucp), &uc, sizeof (uc))) != 0 ||
|
||||
(error = setucontext(l, &uc)) != 0)
|
||||
error = copyin(SCARG(uap, ucp), &uc, sizeof (uc));
|
||||
if (error)
|
||||
return (error);
|
||||
if (!(uc.uc_flags & _UC_CPU))
|
||||
return (EINVAL);
|
||||
error = setucontext(l, &uc);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
return (EJUSTRETURN);
|
||||
|
|
Loading…
Reference in New Issue