Source-Changes-HG archive

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

[src/trunk]: src/sys/kern PR/55629: Andreas Gustafsson: Don't crash when an e...



details:   https://anonhg.NetBSD.org/src/rev/deec1f26e398
branches:  trunk
changeset: 1013586:deec1f26e398
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Aug 31 19:51:30 2020 +0000

description:
PR/55629: Andreas Gustafsson: Don't crash when an emulation does not provide
e_dtrace_syscall (like compat_netbsd32)

diffstat:

 sys/kern/kern_syscall.c |  21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diffs (59 lines):

diff -r 8e90aaa12210 -r deec1f26e398 sys/kern/kern_syscall.c
--- a/sys/kern/kern_syscall.c   Mon Aug 31 19:09:19 2020 +0000
+++ b/sys/kern/kern_syscall.c   Mon Aug 31 19:51:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_syscall.c,v 1.20 2020/05/23 23:42:43 ad Exp $     */
+/*     $NetBSD: kern_syscall.c,v 1.21 2020/08/31 19:51:30 christos Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.20 2020/05/23 23:42:43 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.21 2020/08/31 19:51:30 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
@@ -236,11 +236,16 @@
 trace_enter(register_t code, const struct sysent *sy, const void *args)
 {
        int error = 0;
+#if defined(PTRACE) || defined(KDTRACE_HOOKS)
+       struct proc *p = curlwp->l_proc;
+#endif
 
 #ifdef KDTRACE_HOOKS
        if (sy->sy_entry) {
-               struct emul *e = curlwp->l_proc->p_emul;
-               (*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args, NULL, 0);
+               struct emul *e = p->p_emul;
+               if (e->e_dtrace_syscall)
+                       (*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args,
+                           NULL, 0);
        }
 #endif
 
@@ -251,7 +256,7 @@
        ktrsyscall(code, args, sy->sy_narg);
 
 #ifdef PTRACE
-       if ((curlwp->l_proc->p_slflag & (PSL_SYSCALL|PSL_TRACED)) ==
+       if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED)) ==
            (PSL_SYSCALL|PSL_TRACED)) {
                proc_stoptrace(TRAP_SCE, code, args, NULL, 0);
                if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) {
@@ -280,8 +285,10 @@
 
 #ifdef KDTRACE_HOOKS
        if (sy->sy_return) {
-               (*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy, args,
-                   rval, error);
+               struct emul *e = p->p_emul;
+               if (e->e_dtrace_syscall)
+                       (*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy,
+                           args, rval, error);
        }
 #endif
 



Home | Main Index | Thread Index | Old Index