Access permissions of /dev/mem

前端 未结 2 1269
傲寒
傲寒 2021-02-05 08:21

I have a set of questions regarding /dev/mem:

  1. Many articles on the net, seem to refer /dev/mem as the gateway to \"Physical RAM\

相关标签:
2条回答
  • 2021-02-05 08:44

    What does the follow yield:

    cat /dev/mem | wc
    

    I get:

    cat: /dev/mem: Operation not permitted
       1908   11791 1048576
    

    So for me it does stop at 1MB.

    Note that cat uses open, not mmap so its not an identical test.

    Are you sure you're reading beyond 1MB?

    0 讨论(0)
  • 2021-02-05 08:48
    1. Yes, you're right, /dev/mem allows you to map any physical address, including non-RAM memory mapped IO. This can can be useful for a quick and dirty hack to access some hardware device without writing a kernel driver.

    2. CONFIG_STRICT_DEVMEM makes the kernel check addresses in /dev/mem with devmem_is_allowed() in arch/x86/mm/init.c, and the comment there explains:

      * On x86, access has to be given to the first megabyte of ram because that area
      * contains bios code and data regions used by X and dosemu and similar apps.
      * Access has to be given to non-kernel-ram areas as well, these contain the PCI
      * mmio resources as well as potential bios/acpi data regions.
      

      your address 0xFFFF0000 is quite likely to be non-RAM, since BIOSes typically put IO memory just below 4GB, so that's why you're able to map it even with STRICT_DEVMEM.

    0 讨论(0)
提交回复
热议问题