summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2002-07-22 04:02:40 +0000
committerNiels Provos <provos@cvs.openbsd.org>2002-07-22 04:02:40 +0000
commit81b0d63380ec42b89f3d3b64eeed80d690c29e9e (patch)
treeda048a0e841f4210cfdc5c186c9b702207e99631
parent009c89bfaa234731e5d31d4afe61de09f95877d5 (diff)
add seqnr to message from kernel, userland needs to quote correct seqnr.
avoids problems where tsleep has been interrupted by a signal.
-rw-r--r--bin/systrace/intercept.c12
-rw-r--r--bin/systrace/intercept.h12
-rw-r--r--bin/systrace/openbsd-syscalls.c28
-rw-r--r--sys/dev/systrace.c9
-rw-r--r--sys/dev/systrace.h4
5 files changed, 41 insertions, 24 deletions
diff --git a/bin/systrace/intercept.c b/bin/systrace/intercept.c
index 2d726d39a5e..3a2d3de4989 100644
--- a/bin/systrace/intercept.c
+++ b/bin/systrace/intercept.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: intercept.c,v 1.17 2002/07/19 14:38:57 itojun Exp $ */
+/* $OpenBSD: intercept.c,v 1.18 2002/07/22 04:02:39 provos Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -552,8 +552,8 @@ intercept_filename(int fd, pid_t pid, void *addr, int userp)
}
void
-intercept_syscall(int fd, pid_t pid, int policynr, const char *name, int code,
- const char *emulation, void *args, int argsize)
+intercept_syscall(int fd, pid_t pid, u_int16_t seqnr, int policynr,
+ const char *name, int code, const char *emulation, void *args, int argsize)
{
short action, flags = 0;
struct intercept_syscall *sc;
@@ -609,11 +609,11 @@ intercept_syscall(int fd, pid_t pid, int policynr, const char *name, int code,
}
/* Resume execution of the process */
- intercept.answer(fd, pid, action, error, flags);
+ intercept.answer(fd, pid, seqnr, action, error, flags);
}
void
-intercept_syscall_result(int fd, pid_t pid, int policynr,
+intercept_syscall_result(int fd, pid_t pid, u_int16_t seqnr, int policynr,
const char *name, int code, const char *emulation, void *args, int argsize,
int result, void *rval)
{
@@ -644,7 +644,7 @@ intercept_syscall_result(int fd, pid_t pid, int policynr,
}
out:
/* Resume execution of the process */
- intercept.answer(fd, pid, 0, 0, 0);
+ intercept.answer(fd, pid, seqnr, 0, 0, 0);
}
int
diff --git a/bin/systrace/intercept.h b/bin/systrace/intercept.h
index 9ccc6eb0f4e..01a86e092ad 100644
--- a/bin/systrace/intercept.h
+++ b/bin/systrace/intercept.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: intercept.h,v 1.8 2002/07/19 14:38:57 itojun Exp $ */
+/* $OpenBSD: intercept.h,v 1.9 2002/07/22 04:02:39 provos Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -49,7 +49,7 @@ struct intercept_system {
int (*restcwd)(int);
int (*io)(int, pid_t, int, void *, u_char *, size_t);
int (*getarg)(int, void *, int, void **);
- int (*answer)(int, pid_t, short, int, short);
+ int (*answer)(int, pid_t, u_int32_t, short, int, short);
int (*newpolicy)(int);
int (*assignpolicy)(int, pid_t, int);
int (*policy)(int, int, int, short);
@@ -164,9 +164,9 @@ int intercept_existpids(void);
char *intercept_get_string(int, pid_t, void *);
char *intercept_filename(int, pid_t, void *, int);
-void intercept_syscall(int, pid_t, int, const char *, int, const char *,
- void *, int);
-void intercept_syscall_result(int, pid_t, int, const char *, int, const char *,
- void *, int, int, void *);
+void intercept_syscall(int, pid_t, u_int16_t, int, const char *, int,
+ const char *, void *, int);
+void intercept_syscall_result(int, pid_t, u_int16_t, int, const char *, int,
+ const char *, void *, int, int, void *);
#endif /* _INTERCEPT_H_ */
diff --git a/bin/systrace/openbsd-syscalls.c b/bin/systrace/openbsd-syscalls.c
index 93fac028415..42eda506892 100644
--- a/bin/systrace/openbsd-syscalls.c
+++ b/bin/systrace/openbsd-syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: openbsd-syscalls.c,v 1.8 2002/07/19 14:38:58 itojun Exp $ */
+/* $OpenBSD: openbsd-syscalls.c,v 1.9 2002/07/22 04:02:39 provos Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -126,7 +126,7 @@ static int obsd_syscall_number(const char *, const char *);
static short obsd_translate_policy(short);
static short obsd_translate_flags(short);
static int obsd_translate_errno(int);
-static int obsd_answer(int, pid_t, short, int, short);
+static int obsd_answer(int, pid_t, u_int32_t, short, int, short);
static int obsd_newpolicy(int);
static int obsd_assignpolicy(int, pid_t, int);
static int obsd_modifypolicy(int, int, int, short);
@@ -350,11 +350,13 @@ obsd_translate_errno(int errno)
}
static int
-obsd_answer(int fd, pid_t pid, short policy, int errno, short flags)
+obsd_answer(int fd, pid_t pid, u_int32_t seqnr, short policy, int errno,
+ short flags)
{
struct systrace_answer ans;
ans.stra_pid = pid;
+ ans.stra_seqnr = seqnr;
ans.stra_policy = obsd_translate_policy(policy);
ans.stra_flags = obsd_translate_flags(flags);
ans.stra_error = obsd_translate_errno(errno);
@@ -515,6 +517,8 @@ obsd_read(int fd)
char name[SYSTR_EMULEN+1];
const char *sysname;
+ u_int16_t seqnr;
+ pid_t pid;
int code;
if (read(fd, &msg, sizeof(msg)) != sizeof(msg))
@@ -526,13 +530,15 @@ obsd_read(int fd)
data = icpid->data;
current = data->current;
-
+
+ seqnr = msg.msg_seqnr;
+ pid = msg.msg_pid;
switch (msg.msg_type) {
case SYSTR_MSG_ASK:
code = msg.msg_data.msg_ask.code;
- sysname = obsd_syscall_name(msg.msg_pid, code);
+ sysname = obsd_syscall_name(pid, code);
- intercept_syscall(fd, msg.msg_pid, msg.msg_policy,
+ intercept_syscall(fd, pid, seqnr, msg.msg_policy,
sysname, code, current->name,
(void *)msg.msg_data.msg_ask.args,
msg.msg_data.msg_ask.argsize);
@@ -540,14 +546,14 @@ obsd_read(int fd)
case SYSTR_MSG_RES:
code = msg.msg_data.msg_ask.code;
- sysname = obsd_syscall_name(msg.msg_pid, code);
+ sysname = obsd_syscall_name(pid, code);
/* Switch emulation around at the right time */
if (data->commit != NULL) {
current = obsd_switch_emulation(data);
}
- intercept_syscall_result(fd, msg.msg_pid, msg.msg_policy,
+ intercept_syscall_result(fd, pid, seqnr, msg.msg_policy,
sysname, code, current->name,
(void *)msg.msg_data.msg_ask.args,
msg.msg_data.msg_ask.argsize,
@@ -559,7 +565,7 @@ obsd_read(int fd)
memcpy(name, msg.msg_data.msg_emul.emul, SYSTR_EMULEN);
name[SYSTR_EMULEN] = '\0';
- if (obsd_set_emulation(msg.msg_pid, name) == -1)
+ if (obsd_set_emulation(pid, name) == -1)
errx(1, "%s:%d: set_emulation(%s)",
__func__, __LINE__, name);
@@ -570,13 +576,13 @@ obsd_read(int fd)
current = obsd_switch_emulation(data);
intercept_syscall_result(fd,
- msg.msg_pid, msg.msg_policy,
+ pid, seqnr, msg.msg_policy,
"execve", 0, current->name,
NULL, 0, 0, NULL);
break;
}
- if (obsd_answer(fd, msg.msg_pid, 0, 0, 0) == -1)
+ if (obsd_answer(fd, pid, seqnr, 0, 0, 0) == -1)
err(1, "%s:%d: answer", __func__, __LINE__);
break;
diff --git a/sys/dev/systrace.c b/sys/dev/systrace.c
index 3113e2d07fc..f3b964f0661 100644
--- a/sys/dev/systrace.c
+++ b/sys/dev/systrace.c
@@ -85,6 +85,7 @@ struct str_policy {
#define STR_PROC_WAITANSWER 0x02
#define STR_PROC_SYSCALLRES 0x04
#define STR_PROC_REPORT 0x08 /* Report emulation */
+#define STR_PROC_NEEDSEQNR 0x10 /* Answer must quote seqnr */
struct str_process {
TAILQ_ENTRY(str_process) next;
@@ -101,6 +102,7 @@ struct str_process {
int flags;
short answer;
short error;
+ u_int16_t seqnr; /* expected reply sequence number */
struct str_message msg;
};
@@ -782,6 +784,12 @@ systrace_answer(struct str_process *strp, struct systrace_answer *ans)
goto out;
}
+ /* Check if answer is in sync with us */
+ if (ans->stra_seqnr != strp->seqnr) {
+ error = ESRCH;
+ goto out;
+ }
+
if ((error = systrace_processready(strp)) != 0)
goto out;
@@ -1306,6 +1314,7 @@ systrace_make_msg(struct str_process *strp, int type)
struct proc *p = strp->proc;
int st;
+ msg->msg_seqnr = ++strp->seqnr;
msg->msg_type = type;
msg->msg_pid = strp->pid;
if (strp->policy)
diff --git a/sys/dev/systrace.h b/sys/dev/systrace.h
index bd1bd369597..d4bd99b6e83 100644
--- a/sys/dev/systrace.h
+++ b/sys/dev/systrace.h
@@ -69,8 +69,8 @@ struct str_msg_child {
struct str_message {
int msg_type;
pid_t msg_pid;
+ u_int16_t msg_seqnr; /* answer has to match seqnr */
short msg_policy;
- short reserved;
union {
struct str_msg_emul msg_emul;
struct str_msg_ask msg_ask;
@@ -80,6 +80,8 @@ struct str_message {
struct systrace_answer {
pid_t stra_pid;
+ u_int16_t stra_seqnr;
+ short reserved;
int stra_policy;
int stra_error;
int stra_flags;