简体   繁体   English

如何为每个线程确定Linux内核任务的堆栈指针?

[英]How is a Linux kernel task's stack pointer determined for each thread?

I'm working on a tool that sometimes hijacks application execution, including working in a different stack. 我正在研究一种有时会劫持应用程序执行的工具,包括在不同的堆栈中工作。

I'm trying to get the kernel to always see the application stack when performing certain system calls, so that it will print the [stack] qualifier in the right place in /proc/pid/maps. 我正在尝试让内核在执行某些系统调用时总是看到应用程序堆栈,这样它就会在/ proc / pid / maps中的正确位置打印[stack]限定符。

However, simply modifying the esp around the system call seems not to be enough. 但是,简单地修改系统调用周围的esp似乎是不够的。 When I use my tool on "cat /proc/self/stat" I'm seeing kstkesp ( entry 29 here ) sometimes has the value I want but sometimes has a different value, corresponding to my alternate stack. 当我在“cat / proc / self / stat”上使用我的工具时,我看到kstkesp( 这里的条目29 )有时具有我想要的值,但有时会有一个不同的值,对应于我的备用堆栈。

I'm trying to understand: 我想了解:

  1. How is the value reflected in /proc/self/stat:29 determined? 如何确定/ proc / self / stat:29中的值?
  2. Can I modify it so that it will reliably have an appropriate value? 我可以修改它,以便它可靠地具有适当的值吗?
  3. If 2 is difficult to answer, where would you recommend that I look to understand why the value is intermittently incorrect? 如果2很难回答,你会建议我在哪里理解为什么这个值间歇性地不正确?

Looks like it's defined eg in line 409 of http://lxr.free-electrons.com/source/fs/proc/array.c?v=3.16 to me. 看起来像是在http://lxr.free-electrons.com/source/fs/proc/array.c?v=3.16的第409行中给我定义的。

There is lots of discussion about the related macro KSTK_ESP over the last few years for example: https://github.com/davet321/rpi-linux/commit/32effd19f64908551f8eff87e7975435edd16624 过去几年有很多关于相关宏KSTK_ESP的讨论,例如: https//github.com/davet321/rpi-linux/commit/32effd19f64908551f8eff87e7975435edd16624

and

http://lists.openwall.net/linux-kernel/2015/01/04/140 http://lists.openwall.net/linux-kernel/2015/01/04/140

From what I gather regarding the intermittent oddness it seems like an NMI or other interrupt hits inside the kernel sometimes and then it doesn't properly walk the stack in that case. 从我收集的有关间歇性奇怪的内容看起来有时NMI或其他中断在内核中命中,然后在这种情况下它不能正确地遍历堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM