I have a set of questions regarding /dev/mem
:
Many articles on the net, seem to refer
/dev/mem
as the gateway to"Physical RAM"
. But if I am right,/dev/mem
is the gateway to the"Physical Address Space"
of the processor which might include control registers of many HW peripherals and not just the RAM? Please, correct me if I am wrong!In order to prevent attackers from misusing
/dev/mem
and altering kernel memory, a flagCONFIG_STRICT_DEVMEM
needs to be enabled which will prevent user apps from accessing physical address space beyond 1MB. I checked the config file on my PC (Ubuntu) and found thatCONFIG_STRICT_DEVMEM = y
. And I wrote a program which tries to read to physical memory beyond 1 MB and I was able to read! No segmentation fault or anyOperation NOT Permitted
error. How is this possible?
My program roughly looks like this:
fd = open ( "/dev/mem", O_RDWR);
ptr = (int*) mmap(0, MAP_SIZE, PROT_READ, fd, myAddress & (~MAP_MASK));
printf("%d", *ptr);