kern/166706: sem_open incorrectly returns the already opened named
semaphore handle when O_EXCL is used
Ion Gaztañaga
igaztanaga at gmail.com
Fri Apr 6 21:10:01 UTC 2012
>Number: 166706
>Category: kern
>Synopsis: sem_open incorrectly returns the already opened named semaphore handle when O_EXCL is used
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri Apr 06 21:10:01 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator: Ion Gaztañaga
>Release: 9.0 RELEASE
>Organization:
>Environment:
FreeBSD pcbsd-5366 9.0 RELEASE FreeBSD 9.0 RELEASE (...) PCBSD amd64
>Description:
POSIX states that if O_EXCL and O_CREAT are set, sem_open() fails if the semaphore name exists, even if the semaphore was already opened by the current process. The following test case shows the problem:
#include <semaphore.h>
#include <fcntl.h>
#include <stdio.h>
#include <semaphore.h>
#include <fcntl.h>
#include <stdio.h>
int main()
{
sem_t *sem1, *sem2;
sem_unlink("/testsem");
sem1 = sem_open("/testsem", O_CREAT|O_EXCL, 0644, 1);
if(sem1 == SEM_FAILED){
return 1;
}
sem2 = sem_open("/testsem", O_CREAT|O_EXCL, 0644, 1);
if(sem2 != SEM_FAILED){
printf("ERROR: semaphore already created O_EXCL should fail\n");
sem_close(sem2);
sem_unlink("/testsem");
return 1;
}
printf("OK: semaphore already created, O_EXCL has failed\n");
sem_close(sem1);
sem_unlink("/testsem");
return 0;
}
In FreeBSD 9 the test fails, whereas in FreeBSD 8 (FreeBSD pcbsd-4080 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 (...) PCBSD i386) the test passes.
>How-To-Repeat:
Run the test case
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list