从用户进程的mm_struct或vm_area_struct读取数据
我想知道如何在内核模式下从用户进程的页面复制数据。我可以访问进程的 mm_struct 和所有 vm_area_structs。在 vm_ops 中,我看到了访问方法,但我不确定它是如何工作的。任何帮助将不胜感激。
I was wondering how I would go about copying data from a page of a user process while in kernel mode. I have access to the mm_struct and all the vm_area_structs of the process. In vm_ops I saw the access method but I am unsure of how that works. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可以通过 linux/mm.h 中声明的 access_process_vm 方法来完成(我相信我现在不记得了)。这是访问进程内存的安全方式,需要的是进程的task_struct、要写入/读取的数据的缓冲区、大小、进程在vm空间内的地址以及是否是读/写。这是安全的原因是因为它具有所有适当的锁来处理此问题,并且具有在 get_user_pages 失败时获取用户空间页面的备份方法。返回值是从vm空间读取的字节数。
It can be done via access_process_vm method declared in linux/mm.h (I believe I can't remember at this moment). This is the safe way to access process memory and what is needed is the task_struct of the process, a buffer for the data to be written/read, the size, address within the vm space of the process and whether it is a read/write. The reason this is safe is because it has all the proper locks in place to handle this and has backup methods of obtaining the user space pages if get_user_pages should fail. The return value is the number of bytes read from the vm space.