Is there any way to revoke write permissions to shared memory by the process who created that shared object, s.t. any other process who has mapped the shared memory to its virtual space with write permissions will fail when trying to actually write after the permissions were revoked?
At first I actually expected when revoking write permissions with fchmod() on a shared memory object created with shm_open(), that all subsequent writes by other processes who had the shared memory object already mapped with PROT_WRITE via mmap() will cause a segfault. But this is not the case.
Now I was wondering, if there is any other approach (syscall, shared memory API..) how to achieve my desired behavior?
I need the write permissions when registering the shared memory object for RDMA usage while bootstrapping my application. However, eventually I'd like to ensure that the local process is not able to write to the shared memory object.
shm_open()is usually implemented as nothing more thanmmap()of a file in a prescribed directory, and the memory page permissions are set atmmap()time so changing the file permissions afterwards won't change the memory permissions. Sys V shared memory (shmget()/shmat()) might do what you need - a Sys V shared memory segment has permission modes similar to file modes, and those modes can be changed at runtime. That might do what you need - allow your "other" processes write access via group membership, then have your master process remove write access for the group.