I am writing a char device that takes as input with ioctl a function pointer and a buffer pointer.
I want to modify the user machine context so that back in user mode, that function is executed with a new stack pointed by that buffer pointer.
However if the program is run with ASLR activated a segmentation fault terminates the program, otherwise there are no problems.
This is the interesting part of the code inside the 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
My question is why this happens: ASLR changes the virtual address space of the program every time it is executed, but how can this randomization create problem with the subsequent reassignment of the stack pointer?
The kernel version is 4.14.68