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

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

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

相关推荐
吴烦恼的博客1 天前
RK3588-kernel BringUp记录(二)
linux·kernel
mounter6251 天前
【深度解析】Device Memory TCP:开启高性能网络传输的“零拷贝”新时代
linux·服务器·网络·网络协议·tcp/ip·kernel·devmem
mounter6255 天前
【硬核前沿】CXL 深度解析:重塑数据中心架构的“高速公路”,Linux 内核如何应对挑战?-- CXL 协议详解与 LSF/MM 最新动态
linux·服务器·网络·架构·kernel
mounter62510 天前
【高性能网络】Devmem TCP 深度拆解:打破 100G 网络的“CPU 搬运墙”与延迟瓶颈
网络·网络协议·tcp/ip·kernel·devmem tcp
mounter62519 天前
Linux 7.0 重磅更新:详解 nullfs 如何重塑根文件系统挂载与内核线程隔离
linux·运维·服务器·kernel
mounter6251 个月前
深度解析 RDMA 技术的里程碑:基于 DMA-BUF 的 P2P 直接访问(GPU Direct RDMA 新姿势)
linux·运维·服务器·网络·p2p·kernel
缘友一世1 个月前
ubuntu24.04最新内核6.17.0.19卸载折腾记
linux·kernel
mounter6251 个月前
基于MLX设备的Devlink 工具全指南与核心架构演进
linux·运维·服务器·网络·架构·kernel
wifi chicken1 个月前
Linux wlan 周期性维护终端管理框架详解
linux·kernel·协议栈·wifi驱动
Realdagongzai3 个月前
Python学习过程记录3-操作列表
linux·vscode·python·kernel