Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Mapped files access control classes missing in dotnet core #48793

Closed
Tracked by #64596
ChrisUnityArto opened this issue Feb 20, 2021 · 3 comments
Closed
Tracked by #64596
Labels
area-System.IO needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone

Comments

@ChrisUnityArto
Copy link

Hi!

This Issue #941
And this PR #465
were both closed because no users had requested the ability to set access rules on memory mapped files.

I'm a user, and I'm requesting it now please.

So is this team : https://stackoverflow.com/questions/57085421/sharing-of-global-in-memory-memory-mapped-file

This is a requirement for me as my team have got some bug reports that our existing code which uses MemoryMapped files CreateNew() method is reporting a file not found error on some user's machines.

The fix suggested here which looks like it would work for us
https://stackoverflow.com/questions/20363839/opening-a-memory-mapped-file-causes-filenotfoundexception-when-deployed-in-iis

requires dotnet 4 (or 5) but our software is built on dotnet core 3.1.
Would it be possible to add this feature, which it seems some of your dotnet engineers already have an implementation of, please?
@JeremyKuhne @carlossanlop

Or could anyone suggest a workaround if not?

Cheers,
Chris

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@marcpopMSFT marcpopMSFT self-assigned this Feb 25, 2021
@marcpopMSFT marcpopMSFT transferred this issue from dotnet/sdk Feb 26, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.IO untriaged New issue has not been triaged by the area owner labels Feb 26, 2021
@marcpopMSFT marcpopMSFT removed their assignment Feb 26, 2021
@carlossanlop carlossanlop self-assigned this Mar 11, 2021
@carlossanlop carlossanlop added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed untriaged New issue has not been triaged by the area owner labels Mar 11, 2021
@carlossanlop carlossanlop added this to the 6.0.0 milestone Mar 11, 2021
@adamsitnik adamsitnik modified the milestones: 6.0.0, 7.0.0 Jul 22, 2021
@jeffhandley jeffhandley modified the milestones: 7.0.0, Future Jul 9, 2022
@reejk
Copy link

reejk commented Aug 20, 2024

I ran into the same problem and found a hacky workaround using the MutexSecurity api from System.Threading.AccessControl (Mutex and MemoryMappedFile are both kernel objects).

static void AllowReadWriteAccessToMemoryMappedFile(MemoryMappedFile memoryMappedFile)
{
   const int FILE_MAP_WRITE = 0x0002;
   const int FILE_MAP_READ = 0x0004;

   using var mutex = new Mutex();
   mutex.SafeWaitHandle.Close();
   mutex.SafeWaitHandle = new SafeWaitHandle(memoryMappedFile.SafeMemoryMappedFileHandle.DangerousGetHandle(), false);

   var security = mutex.GetAccessControl();
   security.AddAccessRule(new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.InteractiveSid, null),
      (MutexRights)(FILE_MAP_WRITE | FILE_MAP_READ), AccessControlType.Allow));
   mutex.SetAccessControl(security);
}

Tested on .NET 6 and Windows 11

@ChrisUnityArto
Copy link
Author

Thanks Reejk. Good to know!

Unfortunately the product I was working on has been discontinued and I'm working on something else... !

The version of dotnet we were on is quite old now too so I will close this.

@ChrisUnityArto ChrisUnityArto closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

No branches or pull requests

6 participants