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

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

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

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

c 复制代码
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/netdevice.h>

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.o

else
#kdir := /lib/modules/$(shell uname -r)/build
kdir := /usr/src/linux-headers-$(shell uname -r)
pwd := $(shell pwd)

all:
        $(info "1st")
        make -C $(kdir) M=$(pwd) modules

clean:
        rm *.ko *.o *.order *.mod.c *.symvers *.mod
endif

编译并加载内核模块

使用dmesg打印日志

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

相关推荐
huchao_lingo1 个月前
CentOS升级内核
linux·centos·kernel
千里马学框架1 个月前
aosp13/aosp14编译模拟器emulator的kernel源码(保证通过运行,拒绝水文)
android·车载系统·kernel·安卓framework开发·多屏·车机开发·安卓窗口系统
daisy.skye2 个月前
基于Linux的USB-wifi配置流程
linux·wifi·usb·kernel
Youth cowboy2 个月前
Android GWP-Asan使用与实现原理
android·linux·kernel
worthsen3 个月前
Linux kernel 与 设备树
linux·kernel
wmail-yh3 个月前
充电学习—8、Type-C TCPC TCPCI
linux·驱动开发·学习·kernel
wmail-yh3 个月前
Linux的dev/ 和 sys/ 和 proc/ 目录
linux·学习·内核·kernel
Windra63 个月前
RK3588 Android12音频驱动分析全网最全
pcm·kernel·alsa·audiotrack·audiorecord·audioflinger
wmail-yh3 个月前
充电学习—2、开关电源基本原理
linux·驱动开发·学习·内核·kernel
浮沉飘摇3 个月前
【CRASH】freelist异常导致的异常地址访问
linux·memory·crash·kernel