Source-Changes-HG archive

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

[src/trunk]: src/sys/kern - Reset ignored or masked traps to avoid infinite l...



details:   https://anonhg.NetBSD.org/src/rev/b70dc08b1caf
branches:  trunk
changeset: 828303:b70dc08b1caf
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Dec 07 19:49:43 2017 +0000

description:
- 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 d2f087ded531 -r b70dc08b1caf sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Thu Dec 07 19:48:12 2017 +0000
+++ b/sys/kern/kern_sig.c       Thu Dec 07 19:49:43 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.338 2017/10/25 08:12:39 maya Exp $      */
+/*     $NetBSD: kern_sig.c,v 1.339 2017/12/07 19:49:43 christos 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.338 2017/10/25 08:12:39 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.339 2017/12/07 19:49:43 christos 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