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)
commit5eb7086270ef2aac80bb7ed503ece465b58cf986
tree5d79605646cff4f4fdc3aa6a84186f5e89c88f85
parentbfefeac1274ce97976ab7882433edda74906cba1
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.

Commit migrated from https://github.com/dotnet/coreclr/commit/f668a73f4e8dbd819e1d59fe27f23aa6ce229232
src/coreclr/src/pal/src/include/pal/sharedmemory.h
src/coreclr/src/pal/src/include/pal/sharedmemory.inl
src/coreclr/src/pal/src/sharedmemory/sharedmemory.cpp
src/coreclr/src/pal/src/synchobj/mutex.cpp