Module Name: src
Committed By: riastradh
Date: Fri Jul 28 17:38:36 UTC 2017
Modified Files:
src/sys/compat/svr4: svr4_signal.c
src/sys/compat/svr4_32: svr4_32_signal.c
Log Message:
Fix indexing of svr4 signals.
>From Ilja Van Sprundel.
To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/compat/svr4/svr4_signal.c
cvs rdiff -u -r1.28 -r1.29 src/sys/compat/svr4_32/svr4_32_signal.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/compat/svr4/svr4_signal.c
diff -u src/sys/compat/svr4/svr4_signal.c:1.66 src/sys/compat/svr4/svr4_signal.c:1.67
--- src/sys/compat/svr4/svr4_signal.c:1.66 Sun Nov 9 18:16:55 2014
+++ src/sys/compat/svr4/svr4_signal.c Fri Jul 28 17:38:35 2017
@@ -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 @@ void native_to_svr4_sigaction(const stru
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 @@ svr4_sys_sigaction(struct lwp *l, const
} */
struct svr4_sigaction nssa, ossa;
struct sigaction nbsa, obsa;
+ int native_signo;
int error;
if (SCARG(uap, nsa)) {
@@ -181,7 +197,12 @@ svr4_sys_sigaction(struct lwp *l, const
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 @@ svr4_sys_signal(struct lwp *l, const str
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 @@ svr4_sys_signal(struct lwp *l, const str
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 @@ svr4_sys_signal(struct lwp *l, const str
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 @@ svr4_sys_signal(struct lwp *l, const str
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 @@ svr4_sys_signal(struct lwp *l, const str
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 @@ svr4_sys_kill(struct lwp *l, const struc
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);
}
Index: src/sys/compat/svr4_32/svr4_32_signal.c
diff -u src/sys/compat/svr4_32/svr4_32_signal.c:1.28 src/sys/compat/svr4_32/svr4_32_signal.c:1.29
--- src/sys/compat/svr4_32/svr4_32_signal.c:1.28 Mon Apr 4 23:07:06 2016
+++ src/sys/compat/svr4_32/svr4_32_signal.c Fri Jul 28 17:38:36 2017
@@ -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 @@ const int svr4_to_native_signo[SVR4_NSIG
};
#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 @@ svr4_32_sys_sigaction(struct lwp *l, con
} */
struct svr4_32_sigaction nssa, ossa;
struct sigaction nbsa, obsa;
+ int native_signo;
int error;
if (SCARG_P32(uap, nsa)) {
@@ -319,8 +335,12 @@ svr4_32_sys_sigaction(struct lwp *l, con
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 @@ svr4_32_sys_signal(struct lwp *l, const
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 @@ svr4_32_sys_kill(struct lwp *l, const st
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);
}