mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-29 21:14:27 +01:00
devmem on userland memory...!!!!!!
This commit is contained in:
@@ -30,6 +30,8 @@ where 0x7c7b is the PFN. To get the physical address, just add three zeros back:
|
|||||||
|
|
||||||
0x7c7b000
|
0x7c7b000
|
||||||
|
|
||||||
|
## QEMU monitor xp
|
||||||
|
|
||||||
Examine the physical memory from the QEMU monitor: on host:
|
Examine the physical memory from the QEMU monitor: on host:
|
||||||
|
|
||||||
./qemumonitor
|
./qemumonitor
|
||||||
@@ -41,11 +43,37 @@ Output:
|
|||||||
|
|
||||||
Yes!!! We read the correct value from the physical address.
|
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
|
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
|
#define _XOPEN_SOURCE 700
|
||||||
|
|||||||
@@ -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/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/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 */
|
#include <asm/io.h> /* virt_to_phys */
|
||||||
|
|||||||
5
runqemu
5
runqemu
@@ -8,7 +8,8 @@ debug=false
|
|||||||
debug_qemu=''
|
debug_qemu=''
|
||||||
kgdb=false
|
kgdb=false
|
||||||
nographic=false
|
nographic=false
|
||||||
extra_append=''
|
# norandmaps: reduce randomization to make our lives easier.
|
||||||
|
extra_append='norandmaps'
|
||||||
extra_flags=''
|
extra_flags=''
|
||||||
while getopts a:de:knqt: OPT; do
|
while getopts a:de:knqt: OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
@@ -61,7 +62,7 @@ case "$arch" in
|
|||||||
fi
|
fi
|
||||||
cmd="$qemu_common \
|
cmd="$qemu_common \
|
||||||
-M pc \
|
-M pc \
|
||||||
-append 'root=/dev/vda $extra_append' \
|
-append 'root=/dev/vda nopat $extra_append' \
|
||||||
-device edu \
|
-device edu \
|
||||||
-device lkmc_pci_min \
|
-device lkmc_pci_min \
|
||||||
-drive file=${images_dir}/rootfs.ext2,if=virtio,format=raw \
|
-drive file=${images_dir}/rootfs.ext2,if=virtio,format=raw \
|
||||||
|
|||||||
Reference in New Issue
Block a user