Source-Changes-HG archive

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

[src/trunk]: src/sys/compat Fix indexing of svr4 signals.



details:   https://anonhg.NetBSD.org/src/rev/65b54b5c4518
branches:  trunk
changeset: 825717:65b54b5c4518
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Jul 28 17:38:35 2017 +0000

description:
Fix indexing of svr4 signals.

>From Ilja Van Sprundel.

diffstat:

 sys/compat/svr4/svr4_signal.c       |  55 ++++++++++++++++++++++++++++--------
 sys/compat/svr4_32/svr4_32_signal.c |  46 ++++++++++++++++++++++++------
 2 files changed, 79 insertions(+), 22 deletions(-)

diffs (245 lines):

diff -r 2825aa9ae612 -r 65b54b5c4518 sys/compat/svr4/svr4_signal.c
--- a/sys/compat/svr4/svr4_signal.c     Fri Jul 28 17:14:04 2017 +0000
+++ b/sys/compat/svr4/svr4_signal.c     Fri Jul 28 17:38:35 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svr4_signal.c,v 1.66 2014/11/09 18:16:55 maxv Exp $     */
+/*     $NetBSD: svr4_signal.c,v 1.67 2017/07/28 17:38:35 riastradh Exp $        */
 
 /*-
  * Copyright (c) 1994, 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_signal.c,v 1.66 2014/11/09 18:16:55 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_signal.c,v 1.67 2017/07/28 17:38:35 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -72,6 +72,21 @@
 extern const int native_to_svr4_signo[];
 extern const int svr4_to_native_signo[];
 
+static int
+svr4_decode_signum(int signum, int *native_signo, int *sigcall)
+{
+
+       if (SVR4_SIGNO(signum) >= SVR4_NSIG)
+               return EINVAL;
+
+       if (native_signo)
+               *native_signo = svr4_to_native_signo[SVR4_SIGNO(signum)];
+       if (sigcall)
+               *sigcall = SVR4_SIGCALL(signum);
+
+       return 0;
+}
+
 static inline void
 svr4_sigfillset(svr4_sigset_t *s)
 {
@@ -173,6 +188,7 @@
        } */
        struct svr4_sigaction nssa, ossa;
        struct sigaction nbsa, obsa;
+       int native_signo;
        int error;
 
        if (SCARG(uap, nsa)) {
@@ -181,7 +197,12 @@
                        return (error);
                svr4_to_native_sigaction(&nssa, &nbsa);
        }
-       error = sigaction1(l, svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))],
+
+       error = svr4_decode_signum(SCARG(uap, signum), &native_signo, NULL);
+       if (error)
+               return error;
+
+       error = sigaction1(l, native_signo,
            SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
            NULL, 0);
        if (error)
@@ -216,16 +237,18 @@
                syscallarg(int) signum;
                syscallarg(svr4_sig_t) handler;
        } */
-       int signum = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))];
+       int native_signo, sigcall;
        struct proc *p = l->l_proc;
        struct sigaction nbsa, obsa;
        sigset_t ss;
        int error;
 
-       if (signum <= 0 || signum >= SVR4_NSIG)
-               return (EINVAL);
+       error = svr4_decode_signum(SCARG(uap, signum), &native_signo,
+           &sigcall);
+       if (error)
+               return error;
 
-       switch (SVR4_SIGCALL(SCARG(uap, signum))) {
+       switch (sigcall) {
        case SVR4_SIGDEFER_MASK:
                if (SCARG(uap, handler) == SVR4_SIG_HOLD)
                        goto sighold;
@@ -235,7 +258,7 @@
                nbsa.sa_handler = (sig_t)SCARG(uap, handler);
                sigemptyset(&nbsa.sa_mask);
                nbsa.sa_flags = 0;
-               error = sigaction1(l, signum, &nbsa, &obsa, NULL, 0);
+               error = sigaction1(l, native_signo, &nbsa, &obsa, NULL, 0);
                if (error)
                        return (error);
                *retval = (u_int)(u_long)obsa.sa_handler;
@@ -244,7 +267,7 @@
        case SVR4_SIGHOLD_MASK:
        sighold:
                sigemptyset(&ss);
-               sigaddset(&ss, signum);
+               sigaddset(&ss, native_signo);
                mutex_enter(p->p_lock);
                error = sigprocmask1(l, SIG_BLOCK, &ss, 0);
                mutex_exit(p->p_lock);
@@ -252,7 +275,7 @@
 
        case SVR4_SIGRELSE_MASK:
                sigemptyset(&ss);
-               sigaddset(&ss, signum);
+               sigaddset(&ss, native_signo);
                mutex_enter(p->p_lock);
                error = sigprocmask1(l, SIG_UNBLOCK, &ss, 0);
                mutex_exit(p->p_lock);
@@ -262,11 +285,11 @@
                nbsa.sa_handler = SIG_IGN;
                sigemptyset(&nbsa.sa_mask);
                nbsa.sa_flags = 0;
-               return (sigaction1(l, signum, &nbsa, 0, NULL, 0));
+               return (sigaction1(l, native_signo, &nbsa, 0, NULL, 0));
 
        case SVR4_SIGPAUSE_MASK:
                ss = l->l_sigmask;      /* XXXAD locking */
-               sigdelset(&ss, signum);
+               sigdelset(&ss, native_signo);
                return (sigsuspend1(l, &ss));
 
        default:
@@ -392,9 +415,15 @@
                syscallarg(int) signum;
        } */
        struct sys_kill_args ka;
+       int native_signo;
+       int error;
+
+       error = svr4_decode_signum(SCARG(uap, signum), &native_signo, NULL);
+       if (error)
+               return error;
 
        SCARG(&ka, pid) = SCARG(uap, pid);
-       SCARG(&ka, signum) = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))];
+       SCARG(&ka, signum) = native_signo;
        return sys_kill(l, &ka, retval);
 }
 
diff -r 2825aa9ae612 -r 65b54b5c4518 sys/compat/svr4_32/svr4_32_signal.c
--- a/sys/compat/svr4_32/svr4_32_signal.c       Fri Jul 28 17:14:04 2017 +0000
+++ b/sys/compat/svr4_32/svr4_32_signal.c       Fri Jul 28 17:38:35 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svr4_32_signal.c,v 1.28 2016/04/04 23:07:06 christos Exp $      */
+/*     $NetBSD: svr4_32_signal.c,v 1.29 2017/07/28 17:38:36 riastradh Exp $     */
 
 /*-
  * Copyright (c) 1994, 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_32_signal.c,v 1.28 2016/04/04 23:07:06 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_32_signal.c,v 1.29 2017/07/28 17:38:36 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_svr4.h"
@@ -208,6 +208,21 @@
 };
 #endif
 
+static int
+svr4_32_decode_signum(int signum, int *native_signo, int *sigcall)
+{
+
+       if (SVR4_SIGNO(signum) >= SVR4_NSIG)
+               return EINVAL;
+
+       if (native_signo)
+               *native_signo = svr4_to_native_signo[SVR4_SIGNO(signum)];
+       if (sigcall)
+               *sigcall = SVR4_SIGCALL(signum);
+
+       return 0;
+}
+
 static inline void
 svr4_32_sigfillset(svr4_32_sigset_t *s)
 {
@@ -310,6 +325,7 @@
        } */
        struct svr4_32_sigaction nssa, ossa;
        struct sigaction nbsa, obsa;
+       int native_signo;
        int error;
 
        if (SCARG_P32(uap, nsa)) {
@@ -319,8 +335,12 @@
                        return (error);
                svr4_32_to_native_sigaction(&nssa, &nbsa);
        }
-       error = sigaction1(l,
-                          svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))],
+
+       error = svr4_32_decode_signum(SCARG(uap, signum), &native_signo, NULL);
+       if (error)
+               return error;
+
+       error = sigaction1(l, native_signo,
            SCARG_P32(uap, nsa) ? &nbsa : 0, SCARG_P32(uap, osa) ? &obsa : 0,
            NULL, 0);
        if (error)
@@ -357,15 +377,17 @@
                syscallarg(svr4_32_sig_t) handler;
        } */
        struct proc *p = l->l_proc;
-       int signum = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))];
+       int native_signo, sigcall;
        struct sigaction nbsa, obsa;
        sigset_t ss;
        int error;
 
-       if (signum <= 0 || signum >= SVR4_NSIG)
-               return (EINVAL);
+       error = svr4_32_decode_signum(SCARG(uap, signum), &native_signo,
+           &sigcall);
+       if (error)
+               return error;
 
-       switch (SVR4_SIGCALL(SCARG(uap, signum))) {
+       switch (sigcall) {
        case SVR4_SIGDEFER_MASK:
                if (SCARG(uap, handler) == SVR4_SIG_HOLD)
                        goto sighold;
@@ -536,9 +558,15 @@
                syscallarg(int) signum;
        } */
        struct sys_kill_args ka;
+       int native_signo;
+       int error;
+
+       error = svr4_32_decode_signum(SCARG(uap, signum), &native_signo, NULL);
+       if (error)
+               return error;
 
        SCARG(&ka, pid) = SCARG(uap, pid);
-       SCARG(&ka, signum) = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))];
+       SCARG(&ka, signum) = native_signo;
        return sys_kill(l, &ka, retval);
 }
 



Home | Main Index | Thread Index | Old Index