diff options
author | 2020-12-04 15:16:45 +0000 | |
---|---|---|
committer | 2020-12-04 15:16:45 +0000 | |
commit | f75b2ed9477738f86094e848e910734b4a913d14 (patch) | |
tree | 4260c302ff6d1fc898688a8b19e10e08b83309ea /sys/kern/kern_fork.c | |
parent | Reference count prefixes added to a pftable. This allows to export (diff) | |
download | wireguard-openbsd-f75b2ed9477738f86094e848e910734b4a913d14.tar.xz wireguard-openbsd-f75b2ed9477738f86094e848e910734b4a913d14.zip |
Prevent a TOCTOU race in single_thread_set() by extending the scope of the lock.
Make sure `ps_single' is set only once by checking then updating it without
releasing the lock.
Analyzed by and ok claudio@
Diffstat (limited to 'sys/kern/kern_fork.c')
-rw-r--r-- | sys/kern/kern_fork.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 6d5f56091f2..169c7a05a64 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_fork.c,v 1.228 2020/12/02 22:35:32 mpi Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.229 2020/12/04 15:16:45 mpi Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* @@ -516,7 +516,7 @@ thread_fork(struct proc *curp, void *stack, void *tcb, pid_t *tidptr, struct proc *p; pid_t tid; vaddr_t uaddr; - int error; + int s, error; if (stack == NULL) return EINVAL; @@ -563,10 +563,12 @@ thread_fork(struct proc *curp, void *stack, void *tcb, pid_t *tidptr, * if somebody else wants to take us to single threaded mode, * count ourselves in. */ + SCHED_LOCK(s); if (pr->ps_single) { atomic_inc_int(&pr->ps_singlecount); atomic_setbits_int(&p->p_flag, P_SUSPSINGLE); } + SCHED_UNLOCK(s); /* * Return tid to parent thread and copy it out to userspace |