Lock the semaphore identifier lock during semaphore initialization to

guarantee atomicity of the operation for other semaphore consumers.
In particular, this should guard against access to the semaphore with
not done or partially done MAC label assignment.

Reviewed by:	rwatson
MFC after:	1 month
This commit is contained in:
kib 2009-01-15 12:15:46 +00:00
parent b5dbfe1e63
commit 92e5c3777e

View File

@ -914,6 +914,9 @@ semget(struct thread *td, struct semget_args *uap)
goto done2;
}
DPRINTF(("semid %d is available\n", semid));
mtx_lock(&sema_mtx[semid]);
KASSERT((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0,
("Lost semaphore %d", semid));
sema[semid].u.sem_perm.key = key;
sema[semid].u.sem_perm.cuid = cred->cr_uid;
sema[semid].u.sem_perm.uid = cred->cr_uid;
@ -932,6 +935,7 @@ semget(struct thread *td, struct semget_args *uap)
#ifdef MAC
mac_sysvsem_create(cred, &sema[semid]);
#endif
mtx_unlock(&sema_mtx[semid]);
DPRINTF(("sembase = %p, next = %p\n",
sema[semid].u.sem_base, &sem[semtot]));
} else {