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

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

利用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一致。

相关推荐
leoufung7 天前
调度算法 HTB 或 CBQ 简介
linux·网络·kernel·driver·qos
hello_yj9 天前
Linux Mem -- ARM8.5-A Memory Tagging Extension
linux·kernel
Once_day10 天前
Linux之kernel(1)系统基础理论(2)
linux·操作系统·kernel
Once_day14 天前
Linux之kernel(4)netlink通信
linux·kernel·netlink
Once_day15 天前
Linux之kernel(1)系统基础理论(1)
linux·操作系统·kernel
plmm烟酒僧2 个月前
香橙派5Plus启动报错bug: spinlock bad magic on cpu#6, systemd-udevd/443
linux·bug·rk3588·kernel·香橙派·orangepi5plus
_hong3 个月前
【kernel】从 /proc/sys/net/ipv4/ip_forward 参数看如何玩转 procfs 内核参数
linux·kernel
ywang_wnlo4 个月前
【Kenel】基于 QEMU 的 Linux 内核编译和安装
linux·qemu·kernel
ywang_wnlo4 个月前
【Kernel】基于 QEMU 的 Linux 内核编译和安装
linux·qemu·kernel
organic5 个月前
linux内核调试痛点之函数参数抓捕记
linux·debug·kernel