Fix shm directory creation for named mutexes
authorKoundinya Veluri <kouvel@microsoft.com>
Tue, 24 May 2016 21:16:57 +0000 (14:16 -0700)
committerKoundinya Veluri <kouvel@microsoft.com>
Wed, 25 May 2016 14:26:14 +0000 (07:26 -0700)
commitf668a73f4e8dbd819e1d59fe27f23aa6ce229232
tree4a08fffe22cfe9ed9d1cc82d3cb18baf560caa16
parente172a238e2400fd8b8d1b96678bacbc43a2d033b
Fix shm directory creation for named mutexes

- Creating a directory involves mkdir and chmod. Due to this, there could be a race where one process running as one user creates the directory but does not update permissions for all uses to have access, and at that point another process tries to use the directory.
- Fixed by creating a temp directory using mkdtemp(), chmod to set appropriate permissions for all users, and rename the directory. This is only done when a global lock is not held during the directory creation operation (applies only to /tmp/.dotnet and /tmp/.dotnet/shm).
- Tested manually by adding sleeps at the race points with a second process running as a different user, to make sure it works in any order.
src/pal/src/include/pal/sharedmemory.h
src/pal/src/include/pal/sharedmemory.inl
src/pal/src/sharedmemory/sharedmemory.cpp
src/pal/src/synchobj/mutex.cpp