devmem on userland memory...!!!!!!

This commit is contained in:
Ciro Santilli
2017-07-16 07:51:04 +01:00
parent 1428e7a3b5
commit 058c759ec9
3 changed files with 34 additions and 4 deletions

View File

@@ -30,6 +30,8 @@ where 0x7c7b is the PFN. To get the physical address, just add three zeros back:
0x7c7b000
## QEMU monitor xp
Examine the physical memory from the QEMU monitor: on host:
./qemumonitor
@@ -41,11 +43,37 @@ Output:
Yes!!! We read the correct value from the physical address.
TODO: why does:
## /dev/mem
Firts up, this requires:
- CONFIG_STRICT_DEVMEM is not set.
- nopat on kernel parameters
see: https://stackoverflow.com/questions/11891979/how-to-access-mmaped-dev-mem-without-crashing-the-linux-kernel
Then:
devmem2 0x7c7b800
fail on the mmap? CONFIG_STRICT_DEVMEM is not set.
Possible output:
Memory mapped at address 0x7ff7dbe01000.
Value at address 0X7C7B800 (0x7ff7dbe01800): 0x12345678
where 0x7ff7dbe01000 is a new virtual address that was mapped
to our physical address and given to the process that mapped /dev/mem.
And finally, let's change the value!
devmem2 0x7c7b800 w 0x9abcdef0
After one second, we see on the screen:
i 9abcdef0
[1]+ Done /usermem.out
so the while loop was exited!
*/
#define _XOPEN_SOURCE 700

View File

@@ -13,6 +13,7 @@ static inline phys_addr_t virt_to_phys(volatile void *address)
- https://stackoverflow.com/questions/5748492/is-there-any-api-for-determining-the-physical-address-from-virtual-address-in-li
- https://stackoverflow.com/questions/43325205/can-we-use-virt-to-phys-for-user-space-memory-in-kernel-module
- https://stackoverflow.com/questions/39134990/mmap-of-dev-mem-fails-with-invalid-argument-but-address-is-page-aligned
*/
#include <asm/io.h> /* virt_to_phys */

View File

@@ -8,7 +8,8 @@ debug=false
debug_qemu=''
kgdb=false
nographic=false
extra_append=''
# norandmaps: reduce randomization to make our lives easier.
extra_append='norandmaps'
extra_flags=''
while getopts a:de:knqt: OPT; do
case "$OPT" in
@@ -61,7 +62,7 @@ case "$arch" in
fi
cmd="$qemu_common \
-M pc \
-append 'root=/dev/vda $extra_append' \
-append 'root=/dev/vda nopat $extra_append' \
-device edu \
-device lkmc_pci_min \
-drive file=${images_dir}/rootfs.ext2,if=virtio,format=raw \