Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/kern Pull up following revision(s) (requested by chri...



details:   https://anonhg.NetBSD.org/src/rev/e49ac161df16
branches:  netbsd-8
changeset: 434497:e49ac161df16
user:      snj <snj%NetBSD.org@localhost>
date:      Thu Dec 21 19:41:15 2017 +0000

description:
Pull up following revision(s) (requested by christos in ticket #443):
        sys/kern/kern_sig.c: revision 1.339
- Reset ignored or masked traps to avoid infinite loops
- If sigpost fails don't add an SDT_PROBE
ok (and author) chuq

diffstat:

 sys/kern/kern_sig.c |  54 ++++++++++++++++++++++++++++------------------------
 1 files changed, 29 insertions(+), 25 deletions(-)

diffs (104 lines):

diff -r a0e43475565c -r e49ac161df16 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Thu Dec 21 19:33:15 2017 +0000
+++ b/sys/kern/kern_sig.c       Thu Dec 21 19:41:15 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.336 2017/04/21 15:10:35 christos Exp $  */
+/*     $NetBSD: kern_sig.c,v 1.336.4.1 2017/12/21 19:41:15 snj Exp $   */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.336 2017/04/21 15:10:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.336.4.1 2017/12/21 19:41:15 snj Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -903,9 +903,10 @@
        mask = &l->l_sigmask;
        ps = p->p_sigacts;
 
-       if ((p->p_slflag & PSL_TRACED) == 0 &&
-           sigismember(&p->p_sigctx.ps_sigcatch, signo) &&
-           !sigismember(mask, signo)) {
+       const bool traced = (p->p_slflag & PSL_TRACED) != 0;
+       const bool caught = sigismember(&p->p_sigctx.ps_sigcatch, signo);
+       const bool masked = sigismember(mask, signo);
+       if (!traced && caught && !masked) {
                mutex_exit(proc_lock);
                l->l_ru.ru_nsignals++;
                kpsendsig(l, ksi, mask);
@@ -920,11 +921,28 @@
                                    SIGACTION_PS(ps, signo).sa_handler,
                                    mask, ksi);
                }
-       } else {
-               kpsignal2(p, ksi);
-               mutex_exit(p->p_lock);
-               mutex_exit(proc_lock);
+               return;
        }
+
+       /*
+        * If the signal is masked or ignored, then unmask it and
+        * reset it to the default action so that the process or
+        * its tracer will be notified.
+        */
+       const bool ignored = SIGACTION_PS(ps, signo).sa_handler == SIG_IGN;
+       if (masked || ignored) {
+               mutex_enter(&ps->sa_mutex);
+               sigdelset(mask, signo); 
+               sigdelset(&p->p_sigctx.ps_sigcatch, signo);
+               sigdelset(&p->p_sigctx.ps_sigignore, signo);
+               sigdelset(&SIGACTION_PS(ps, signo).sa_mask, signo);
+               SIGACTION_PS(ps, signo).sa_handler = SIG_DFL;
+               mutex_exit(&ps->sa_mutex);
+       }
+
+       kpsignal2(p, ksi);
+       mutex_exit(p->p_lock);
+       mutex_exit(proc_lock);
 }
 
 /*
@@ -1215,7 +1233,6 @@
 kpsignal2(struct proc *p, ksiginfo_t *ksi)
 {
        int prop, signo = ksi->ksi_signo;
-       struct sigacts *sa;
        struct lwp *l = NULL;
        ksiginfo_t *kp;
        lwpid_t lid;
@@ -1275,20 +1292,6 @@
                                goto out;
                }
        } else {
-               /*
-                * If the signal was the result of a trap and is not being
-                * caught, then reset it to default action so that the
-                * process dumps core immediately.
-                */
-               if (KSI_TRAP_P(ksi)) {
-                       sa = p->p_sigacts;
-                       mutex_enter(&sa->sa_mutex);
-                       if (!sigismember(&p->p_sigctx.ps_sigcatch, signo)) {
-                               sigdelset(&p->p_sigctx.ps_sigignore, signo);
-                               SIGACTION(p, signo).sa_handler = SIG_DFL;
-                       }
-                       mutex_exit(&sa->sa_mutex);
-               }
 
                /*
                 * If the signal is being ignored, then drop it.  Note: we
@@ -1365,7 +1368,8 @@
                        if ((error = sigput(&l->l_sigpend, p, kp)) != 0)
                                goto out;
                        membar_producer();
-                       (void)sigpost(l, action, prop, kp->ksi_signo);
+                       if (sigpost(l, action, prop, kp->ksi_signo) != 0)
+                               signo = -1;
                }
                goto out;
        }



Home | Main Index | Thread Index | Old Index