我正在编写一个 char 设备,它使用 ioctl 函数指针和缓冲区指针作为输入。
我想修改用户机器上下文,以便回到用户模式,使用该缓冲区指针指向的新堆栈执行该函数。
但是,如果程序在激活 ASLR 的情况下运行,则分段错误会终止程序,否则没有问题。
这是代码中有趣的部分ioctl
:
struct pt_regs* regs = task_pt_regs(current);
regs->ip = a->func;// func is a function implemented in user space
regs->sp = a->stack;// stack is the buffer allocated in user space with malloc
我的问题是为什么会发生这种情况:ASLR 每次执行时都会更改程序的虚拟地址空间,但是这种随机化如何在随后重新分配堆栈指针时产生问题?
内核版本为 4.14.68