Skip to content

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

Closed as not planned

Description

@ChrisUnityArto

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

Activity

  1. self-assigned this
    on Feb 25, 2021
  2. transferred this issue fromdotnet/sdkon Feb 26, 2021
  3. ghost added
    untriaged
    on Feb 26, 2021
  4. removed their assignment
    on Feb 26, 2021
  5. self-assigned this
    on Mar 11, 2021
  6. added
    needs-further-triage
    and removed
    untriaged
    on Mar 11, 2021
  7. added this to the 6.0.0 milestone on Mar 11, 2021
  8. modified the milestones: 6.0.0, 7.0.0 on Jul 22, 2021
  9. modified the milestones: 7.0.0, Future on Jul 9, 2022
  10. reejk commented on Aug 20, 2024

    @reejk

    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

  11. ChrisUnityArto commented on Aug 21, 2024

    @ChrisUnityArto
    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.

  12. locked and limited conversation to collaborators on Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IOneeds-further-triage

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions