Get userspace RBP register from kernel syscall

孤者浪人 提交于 2021-02-11 15:01:31

问题


I am writing a kernel system call and I want to read the base pointer register (RBP) of the user. Maybe I can do that using the pt_regs struct that is passed for parameter, isn't it?

Example code:

unsigned long int data;
asmlinkage int my_read(int d)
{
    get_rbp_of_userStack(&data);#or somthing like that 

}

I know this data saved somewhere for the context switch, how can I get to it?

this is my user code

 void rar()
{//rbp here should be rsp when it call so it basically the return addres of the main
  char t[10];
getchar();
 }
 
int main()
{
  rar();
}

回答1:


You can use the task_pt_regs() macro to get the current task's user registers (saved at the moment of syscall entry):

#include <asm/processor.h>

SYSCALL_DEFINE1(foo, int, d)
{
    const struct pt_regs *user_regs = task_pt_regs(current);
    unsigned long rbp = user_regs->bp;

    / * Do whatever you need... */

    return 0;
}


来源:https://stackoverflow.com/questions/64577963/get-userspace-rbp-register-from-kernel-syscall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!