1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-13 10:02:38 +00:00

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:
Konstantin Belousov 2009-01-15 12:15:46 +00:00
parent 892f21a681
commit 137cf3b682
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=187298

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 {