简体   繁体   English

从Linux上的内核直接访问用户内存

[英]Direct access user memory from kernel on Linux

I've got a user-mode process and kernel module. 我有一个用户模式进程和内核模块。 Now I want to read certain regions of usermode process from kernel, but there's one catch: no copying of usermode memory and simple access by VA. 现在我想从内核读取usermode进程的某些区域,但有一个问题:没有复制用户模式内存和VA的简单访问。 So what we have: task_struct for target process, other related structs (like mm_struct, vma_struct) and virtual address like 0x0070abcd that I want to read or rather map somehow to my kernel module. 所以我们拥有:目标进程的task_struct,其他相关结构(如mm_struct,vma_struct)和虚拟地址,如0x0070abcd,我想要读取或者更确切地映射到我的内核模块。

I can get page list using get_user_pages for desired memory regions, but what next? 我可以使用get_user_pages获取所需内存区域的页面列表,但下一步是什么? Should I map pages somehow into kernel and then try to read them as continuous memory region or there are better solutions? 我应该以某种方式将页面映射到内核中,然后尝试将它们作为连续内存区域读取,还是有更好的解决方案?

The problem is that "looking" at user-space requires locking a ton of stuff. 问题是“寻找”用户空间需要锁定大量的东西。 So it's better that you do a short copy than leave everything locked for arbitrary amounts of time. 所以你做一个简短的副本比把所有东西锁定任意时间更好。 Your user-space process may not be VM-mapped into the current CPU. 您的用户空间进程可能未被VM映射到当前CPU。 In fact, it may be entirely swapped out to disk, running on another CPU, in the middle of it's own kernel call, etc. 实际上,它可能完全被换成磁盘,在另一个CPU上运行,在它自己的内核调用中等。

Linux Kernel: copy_from_user - struct with pointers Linux内核:copy_from_user - 带指针的struct

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

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