title: Detecting and controlling unauthorized shared memory reads
body: <p>I was wondering - are there any known techniques to control access to a shared memory object from anywhere but an authorized program?</p>
  
  <p>For instance, lets say I create a shared memory segment for use in a program P, to be accessed by Q, and I make it Read-Write. I can access it using Q because I've given it (Q) the required permissions to do so (running as a particular user with groups, etc).</p>
  
  <p>However, I'm guessing there are instances where someone could potentially access this shared memory from a program R - simply attaching to it and modifying it. To stop this, you could make the memory segment read only - but now program R could still <em>read</em> what was in the memory. </p>
  
  <p>My question is in parts - </p>
  
  <ol>
  <li><p>Is there a way to,</p>
  
  <p>a) allow only Q to access the shared memory?</p>
  
  <p>b) figure whether a read was done by someone apart from Q - and who did it? [Is this even possible?] For bonus points, could this be done cross-platform? [Probably not, but no harm trying :)]</p></li>
  <li><p>Under what circumstances could a rogue program attach to the shared memory? I presume one way is if a user is able to exploit OS holes and become the user that started the program. Any others?</p></li>
  </ol>