summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-01-20 11:27:53 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-01-20 11:27:53 +0000
commitb1debdf727116f16170aa85959010013dd34583e (patch)
treeb2f6cee252eb75c2e5b8874177dcccb398a63941 /sys/kern
parent5553da18201980ea91c0445a3120d60334ec5ae5 (diff)
When a process is exec:ing mark it with a flag. Check that flag in ptrace
and procfs (and possibly more places in the future) and simply refuse to fiddle with the execing process. This is an ugly hack, but this far we haven't been successful in creating a race-free exec.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_exec.c11
-rw-r--r--sys/kern/sys_process.c5
2 files changed, 14 insertions, 2 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 6bec610b8e2..b8b6b6d479a 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exec.c,v 1.62 2001/12/19 08:58:06 art Exp $ */
+/* $OpenBSD: kern_exec.c,v 1.63 2002/01/20 11:27:52 art Exp $ */
/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */
/*-
@@ -250,6 +250,12 @@ sys_execve(p, v, retval)
extern struct emul emul_native;
/*
+ * Cheap solution to complicated problems.
+ * Mark this process as "leave me alone, I'm execing".
+ */
+ p->p_flag |= P_INEXEC;
+
+ /*
* figure out the maximum size of an exec header, if necessary.
* XXX should be able to keep LKM code from modifying exec switch
* when we're still using it, but...
@@ -614,6 +620,7 @@ sys_execve(p, v, retval)
if (KTRPOINT(p, KTR_EMUL))
ktremul(p, p->p_emul->e_name);
#endif
+ p->p_flag &= ~P_INEXEC;
return (0);
bad:
@@ -632,6 +639,7 @@ bad:
freehdr:
free(pack.ep_hdr, M_EXEC);
+ p->p_flag &= ~P_INEXEC;
return (error);
exec_abort:
@@ -655,6 +663,7 @@ free_pack_abort:
exit1(p, -1);
/* NOTREACHED */
+ p->p_flag &= ~P_INEXEC;
return (0);
}
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index e20fedf045d..2e27b3d46ea 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_process.c,v 1.15 2002/01/02 02:38:42 art Exp $ */
+/* $OpenBSD: sys_process.c,v 1.16 2002/01/20 11:27:52 art Exp $ */
/* $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $ */
/*-
@@ -107,6 +107,9 @@ sys_ptrace(p, v, retval)
return (ESRCH);
}
+ if ((t->p_flag & P_INEXEC) != 0)
+ return (EAGAIN);
+
/* Make sure we can operate on it. */
switch (SCARG(uap, req)) {
case PT_TRACE_ME: