summaryrefslogtreecommitdiff
path: root/bin/systrace/intercept.c
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2012-08-23 00:08:37 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2012-08-23 00:08:37 +0000
commit0f00c9bf52870a9dbcbd3d7fcc0b9c42b7b8598e (patch)
tree099f2772294f68fa662748353f8106b5ef3d07c9 /bin/systrace/intercept.c
parent1f26125669866612ffdb6de97081736444827832 (diff)
Reopen the systrace file in the process that will actually attach to the
target process(es), so that systrace files can be made unsharable. ok djm@
Diffstat (limited to 'bin/systrace/intercept.c')
-rw-r--r--bin/systrace/intercept.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/bin/systrace/intercept.c b/bin/systrace/intercept.c
index 0c0ffe310ed..3dfb223b716 100644
--- a/bin/systrace/intercept.c
+++ b/bin/systrace/intercept.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: intercept.c,v 1.58 2011/10/18 20:01:28 matthew Exp $ */
+/* $OpenBSD: intercept.c,v 1.59 2012/08/23 00:08:36 guenther Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -266,7 +266,7 @@ intercept_setpid(struct intercept_pid *icpid, uid_t uid, gid_t gid)
}
pid_t
-intercept_run(int bg, int fd, uid_t uid, gid_t gid,
+intercept_run(int bg, int *fdp, uid_t uid, gid_t gid,
char *path, char *const argv[])
{
struct intercept_pid *icpid;
@@ -285,6 +285,13 @@ intercept_run(int bg, int fd, uid_t uid, gid_t gid,
if (ohandler == SIG_ERR)
err(1, "signal");
+ /*
+ * If systrace process will be the child then we must reopen
+ * the fd in the child after the fork
+ */
+ if (bg)
+ close(*fdp);
+
pid = getpid();
cpid = fork();
if (cpid == -1)
@@ -295,9 +302,6 @@ intercept_run(int bg, int fd, uid_t uid, gid_t gid,
* the parent, or vice versa.
*/
if ((!bg && cpid == 0) || (bg && cpid != 0)) {
- /* Needs to be closed */
- close(fd);
-
if (bg) {
/* Wait for child to "detach" */
cpid = wait(&status);
@@ -366,6 +370,10 @@ intercept_run(int bg, int fd, uid_t uid, gid_t gid,
kill(pid, SIGKILL);
err(1, "daemon");
}
+ if ((*fdp = intercept_open()) == -1) {
+ kill(pid, SIGKILL);
+ err(1, "intercept_open");
+ }
}
return (pid);