Sharing memory through the direct mapping of physical addresses

Updated: April 19, 2023

Don't do it!

Note: Sharing memory through the direct mapping of physical addresses is extremely dangerous, and you should avoid it.

Let's consider some scenarios.

Scenario 1: communicating using physical addresses

Process A allocates some memory, maps it, determines the physical address, and gives the address to process B so that it can map the memory. Process B uses direct mapping.

What can go wrong in this scenario?

It's a safety and security nightmare!

Scenario 2: mapping into a peer process

Process A allocates memory and uses mmap_peer() to establish a mapping for process B. This scenario isn't as bad as the one above; instead of letting process B map the physical address, process A does it for process B, and then injects the mapping into process B's address space.

What's wrong in this scenario?

At the very least, the processes have to coordinate with each other.