I am trying to read a physical memory address in a device running embedded Linux with our application. The widely suggested method is to use mmap, convert it into virtual address and then read the value.

Now I would like to know if it a man in the midde attack is possible by replacing the standard mmap library with a spurious mmap library? That is, can a hacker prevent me from reading the intended value from the underlying hardware? Is there a secure way to read the physical address?

In other words I am looking to read a physical address and I would like to know the value that I read is from the actual hardware and not a spoofed value.

  • 6
    If someone has access to replace the standard mmap library, then that generally implies that they can also replace/modify any and all parts of your application while it's running and alter it's behavior in totally arbitrary ways. Someone always is the top authority in any system - either you have 100% total control over the system, or someone can override everything your app attempts to do.
    – Peteris
    Nov 6, 2015 at 21:56

3 Answers 3


Don't worry about it. If an attacker can replace system libraries that are being used by your application, then you have been totally compromised and can't trust anything in your app. It's not a situation you can really protect against.


My understanding of your question is that you control the application which will access the device but not the device's OS itself.

In such a case you will not have the capacity to ensure that what is read from the hardware is correct, except if that information is signed by the hardware and you can check the signature elsewhere (not on the device itself).

mmap is just a routine from a library and yes, could be replaced and provide all kind of functions beside the ones provided by mmap, including malicious ones.

If you trust the vendor of your device, you may have the possibility to check if the embedded software is genuine (through some kind of checksum, if such a capacity is provided by the vendor)

  • Thank you. I think signing could be a solution. I will explore on that,
    – Vasu
    Nov 9, 2015 at 3:21

If you want secure access to hardware the only way to do it is a kernel space application (usually known as a driver) which is the "right" way to do it anyway.

  • That just raises the bar slightly, it takes another kernel module to intercept or otherwise interfere with driver memory accesses.
    – Ben Voigt
    Jan 14, 2016 at 3:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .