打印指定进程的线性地址段

  • 利用procfs查看进程的线性地址
  • 自定义内核模块读取进程的线性地址
    • 编译并加载内核模块

利用procfs查看进程的线性地址

自定义内核模块读取进程的线性地址

#include #include #include #include #include static int hello_init(void) {struct task_struct *p;struct vm_area_struct *vma;printk(KERN_ALERT "init fishing\n");for_each_process(p) {if (strcmp(p->comm,"a.out") == 0) {printk(KERN_ALERT "%s-->%p\n",p->comm, p->mm);for(vma = p->mm->mmap;vma!=NULL;vma = vma->vm_next) {printk(KERN_ALERT "%lx - %lx\n",vma->vm_start, vma->vm_end);}}}return 0;}static void hello_exit(void) {printk(KERN_ALERT "exit fishing\n");}subsys_initcall(hello_init);module_exit(hello_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("shakespeare");
ifneq ($(KERNELRELEASE),)$(info "2nd")obj-m := fishing.oelse#kdir := /lib/modules/$(shell uname -r)/buildkdir := /usr/src/linux-headers-$(shell uname -r)pwd := $(shell pwd)all:$(info "1st")make -C $(kdir) M=$(pwd) modulesclean:rm *.ko *.o *.order *.mod.c *.symvers *.modendif

编译并加载内核模块

使用dmesg打印日志

通过对比可知,打印的线性地址与系统提供的procfs中的maps一致。