summaryrefslogtreecommitdiffstats
path: root/sys/kern/uipc_sem.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-04-07 15:26:09 +0000
committerjilles <jilles@FreeBSD.org>2013-04-07 15:26:09 +0000
commitfd361c8faa4d088e398aecb3ed9d37552daae541 (patch)
tree6064a4b99420c0dc0525bd6f0aef8ee1284a7dc9 /sys/kern/uipc_sem.c
parentc29caa8936b8a2ba20b7c6109b82059b8da0dd36 (diff)
downloadFreeBSD-src-fd361c8faa4d088e398aecb3ed9d37552daae541.zip
FreeBSD-src-fd361c8faa4d088e398aecb3ed9d37552daae541.tar.gz
mqueue,ksem,shm: Fix race condition with setting UF_EXCLOSE.
POSIX mqueue, compatibility ksem and POSIX shm create a file descriptor that has close-on-exec set. However, they do this incorrectly, leaving a window where a thread may fork and exec while the flag has not been set yet. The race is easily reproduced on a multicore system with one thread doing shm_open and close and another thread doing posix_spawnp and waitpid. Set UF_EXCLOSE via falloc()'s flags argument instead. This also simplifies the code. MFC after: 1 week
Diffstat (limited to 'sys/kern/uipc_sem.c')
-rw-r--r--sys/kern/uipc_sem.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/sys/kern/uipc_sem.c b/sys/kern/uipc_sem.c
index 2de3409..509f32e 100644
--- a/sys/kern/uipc_sem.c
+++ b/sys/kern/uipc_sem.c
@@ -485,7 +485,7 @@ ksem_create(struct thread *td, const char *name, semid_t *semidp, mode_t mode,
fdp = td->td_proc->p_fd;
mode = (mode & ~fdp->fd_cmask) & ACCESSPERMS;
- error = falloc(td, &fp, &fd, 0);
+ error = falloc(td, &fp, &fd, O_CLOEXEC);
if (error) {
if (name == NULL)
error = ENOSPC;
@@ -578,10 +578,6 @@ ksem_create(struct thread *td, const char *name, semid_t *semidp, mode_t mode,
finit(fp, FREAD | FWRITE, DTYPE_SEM, ks, &ksem_ops);
- FILEDESC_XLOCK(fdp);
- if (fdp->fd_ofiles[fd].fde_file == fp)
- fdp->fd_ofiles[fd].fde_flags |= UF_EXCLOSE;
- FILEDESC_XUNLOCK(fdp);
fdrop(fp, td);
return (0);
OpenPOWER on IntegriCloud