Source-Changes-HG archive

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

[src/trunk]: src/sys/kern - In sendsig() and sigaction1(), don't hard-code si...



details:   https://anonhg.NetBSD.org/src/rev/ee67459c0a1d
branches:  trunk
changeset: 1024520:ee67459c0a1d
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Oct 27 04:45:42 2021 +0000

description:
- In sendsig() and sigaction1(), don't hard-code signal trampoline
  versions.  Instead, use the version constants from <sys/signal.h>
  and automatically (and correctly) handle cases where multiple versions
  of a particular trampoline flavor exist.  Conditionalize support
  for sigcontext trampolines on __HAVE_STRUCT_SIGCONTEXT.
- aarch64 and amd64 don't use sigcontext natively, but do need to
  support it for 32-bit compatibility; define __HAVE_STRUCT_SIGCONTEXT
  conditionally on _KERNEL.

diffstat:

 sys/arch/aarch64/include/signal.h |  12 ++++++++-
 sys/arch/amd64/include/signal.h   |   7 ++++-
 sys/kern/kern_sig.c               |  15 ++++++----
 sys/kern/sys_sig.c                |  51 ++++++++++++++++++++++----------------
 4 files changed, 55 insertions(+), 30 deletions(-)

diffs (186 lines):

diff -r 653fe94f9572 -r ee67459c0a1d sys/arch/aarch64/include/signal.h
--- a/sys/arch/aarch64/include/signal.h Wed Oct 27 04:15:41 2021 +0000
+++ b/sys/arch/aarch64/include/signal.h Wed Oct 27 04:45:42 2021 +0000
@@ -1,3 +1,13 @@
-/* $NetBSD: signal.h,v 1.2 2018/04/01 04:35:03 ryo Exp $ */
+/* $NetBSD: signal.h,v 1.3 2021/10/27 04:45:42 thorpej Exp $ */
+
+#ifndef _AARCH64_SIGNAL_H_
+#define        _AARCH64_SIGNAL_H_
 
 #include <arm/signal.h>
+
+#ifdef _KERNEL
+/* This is needed to support COMPAT_NETBSD32. */ 
+#define        __HAVE_STRUCT_SIGCONTEXT
+#endif /* _KERNEL */
+
+#endif /* ! _AARCH64_SIGNAL_H_ */
diff -r 653fe94f9572 -r ee67459c0a1d sys/arch/amd64/include/signal.h
--- a/sys/arch/amd64/include/signal.h   Wed Oct 27 04:15:41 2021 +0000
+++ b/sys/arch/amd64/include/signal.h   Wed Oct 27 04:45:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: signal.h,v 1.12 2013/01/02 19:40:23 dsl Exp $  */
+/*     $NetBSD: signal.h,v 1.13 2021/10/27 04:45:42 thorpej Exp $      */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -38,6 +38,11 @@
 
 #include <sys/featuretest.h>
 
+#ifdef _KERNEL
+/* This is needed to support COMPAT_NETBSD32. */
+#define        __HAVE_STRUCT_SIGCONTEXT
+#endif /* _KERNEL */
+
 typedef int sig_atomic_t;
 
 #if defined(_NETBSD_SOURCE)
diff -r 653fe94f9572 -r ee67459c0a1d sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Wed Oct 27 04:15:41 2021 +0000
+++ b/sys/kern/kern_sig.c       Wed Oct 27 04:45:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.399 2021/09/26 17:34:19 thorpej Exp $   */
+/*     $NetBSD: kern_sig.c,v 1.400 2021/10/27 04:45:42 thorpej Exp $   */
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.399 2021/09/26 17:34:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.400 2021/10/27 04:45:42 thorpej Exp $");
 
 #include "opt_execfmt.h"
 #include "opt_ptrace.h"
@@ -2169,14 +2169,17 @@
        sa = curproc->p_sigacts;
 
        switch (sa->sa_sigdesc[sig].sd_vers)  {
-       case 0:
-       case 1:
+       case __SIGTRAMP_SIGCODE_VERSION:
+#ifdef __HAVE_STRUCT_SIGCONTEXT
+       case __SIGTRAMP_SIGCONTEXT_VERSION_MIN ...
+            __SIGTRAMP_SIGCONTEXT_VERSION_MAX:
                /* Compat for 1.6 and earlier. */
                MODULE_HOOK_CALL_VOID(sendsig_sigcontext_16_hook, (ksi, mask),
                    break);
                return;
-       case 2:
-       case 3:
+#endif /* __HAVE_STRUCT_SIGCONTEXT */
+       case __SIGTRAMP_SIGINFO_VERSION_MIN ...
+            __SIGTRAMP_SIGINFO_VERSION_MAX:
                sendsig_siginfo(ksi, mask);
                return;
        default:
diff -r 653fe94f9572 -r ee67459c0a1d sys/kern/sys_sig.c
--- a/sys/kern/sys_sig.c        Wed Oct 27 04:15:41 2021 +0000
+++ b/sys/kern/sys_sig.c        Wed Oct 27 04:45:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_sig.c,v 1.52 2021/09/23 06:58:47 ryo Exp $ */
+/*     $NetBSD: sys_sig.c,v 1.53 2021/10/27 04:45:42 thorpej Exp $     */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.52 2021/09/23 06:58:47 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.53 2021/10/27 04:45:42 thorpej Exp $");
 
 #include "opt_dtrace.h"
 
@@ -394,30 +394,32 @@
        ksiginfo_queue_init(&kq);
 
        /*
-        * Trampoline ABI version 0 is reserved for the legacy kernel
-        * provided on-stack trampoline.  Conversely, if we are using a
-        * non-0 ABI version, we must have a trampoline.  Only validate the
-        * vers if a new sigaction was supplied and there was an actual
-        * handler specified (not SIG_IGN or SIG_DFL), which don't require
-        * a trampoline. Emulations use legacy kernel trampolines with
-        * version 0, alternatively check for that too.
+        * Trampoline ABI version __SIGTRAMP_SIGCODE_VERSION (0) is reserved
+        * for the legacy kernel provided on-stack trampoline.  Conversely,
+        * if we are using a non-0 ABI version, we must have a trampoline.
+        * Only validate the vers if a new sigaction was supplied and there
+        * was an actual handler specified (not SIG_IGN or SIG_DFL), which
+        * don't require a trampoline. Emulations use legacy kernel
+        * trampolines with version 0, alternatively check for that too.
         *
-        * If version < 2, we try to autoload the compat module.  Note
-        * that we interlock with the unload check in compat_modcmd()
-        * using kernconfig_lock.  If the autoload fails, we don't try it
-        * again for this process.
+        * If version < __SIGTRAMP_SIGINFO_VERSION_MIN (usually 2), we try
+        * to autoload the compat module.  Note that we interlock with the
+        * unload check in compat_modcmd() using kernconfig_lock.  If the
+        * autoload fails, we don't try it again for this process.
         */
        if (nsa != NULL && nsa->sa_handler != SIG_IGN
            && nsa->sa_handler != SIG_DFL) {
-               if (__predict_false(vers < 2)) {
-                       if (p->p_flag & PK_32) {
-                               v0v1valid = true;
-                       } else if (vers == 0 &&
+               if (__predict_false(vers < __SIGTRAMP_SIGINFO_VERSION_MIN)) {
+                       if (vers == __SIGTRAMP_SIGCODE_VERSION &&
                            p->p_sigctx.ps_sigcode != NULL) {
                                /*
                                 * if sigcode is used for this emulation,
                                 * version 0 is allowed.
                                 */
+                       }
+#ifdef __HAVE_STRUCT_SIGCONTEXT
+                       else if (p->p_flag & PK_32) {
+                               v0v1valid = true;
                        } else if ((p->p_lflag & PL_SIGCOMPAT) == 0) {
                                kernconfig_lock();
                                (void)module_autoload("compat_16",
@@ -440,30 +442,35 @@
                                mutex_exit(&proc_lock);
                                kernconfig_unlock();
                        }
+#endif /* __HAVE_STRUCT_SIGCONTEXT */
                }
 
                switch (vers) {
-               case 0:
-                       /* sigcontext, kernel supplied trampoline. */
+               case __SIGTRAMP_SIGCODE_VERSION:
+                       /* kernel supplied trampoline. */
                        if (tramp != NULL ||
                            (p->p_sigctx.ps_sigcode == NULL && !v0v1valid)) {
                                return EINVAL;
                        }
                        break;
-               case 1:
+#ifdef __HAVE_STRUCT_SIGCONTEXT
+               case __SIGTRAMP_SIGCONTEXT_VERSION_MIN ...
+                    __SIGTRAMP_SIGCONTEXT_VERSION_MAX:
                        /* sigcontext, user supplied trampoline. */
                        if (tramp == NULL || !v0v1valid) {
                                return EINVAL;
                        }
                        break;
-               case 2:
-               case 3:
+#endif /* __HAVE_STRUCT_SIGCONTEXT */
+               case __SIGTRAMP_SIGINFO_VERSION_MIN ...
+                    __SIGTRAMP_SIGINFO_VERSION_MAX:
                        /* siginfo, user supplied trampoline. */
                        if (tramp == NULL) {
                                return EINVAL;
                        }
                        break;
                default:
+                       /* Invalid trampoline version. */
                        return EINVAL;
                }
        }



Home | Main Index | Thread Index | Old Index