4

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. 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.

I can get page list using get_user_pages for desired memory regions, but what next? Should I map pages somehow into kernel and then try to read them as continuous memory region or there are better solutions?

4
  • 2
    Not an answer since I can't currently verify the details, but I suggest you take a look at mm/memory.c, at the implementation of access_process_vm. Commented Jan 14, 2013 at 18:47
  • Looks like access_process_vm calls copy_from_user_page. I don't want to copy userspace pages unless it's the only solution available. Commented Jan 15, 2013 at 7:33
  • copy_from_user_page seems to be a simple memcpy() most of the time, some arch/platform implementations appear to handle D/I cache first. I'd recommend caution unless you know that you're running on x86 or similar. Commented Jan 16, 2013 at 10:57
  • Here is an answer to a similar question from Robert Love, the author of Linux Kernel Development: quora.com/Linux-Kernel-How-does-copy_to_user-work Commented Dec 28, 2019 at 0:00

1 Answer 1

1

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. In fact, it may be entirely swapped out to disk, running on another CPU, in the middle of it's own kernel call, etc.

Linux Kernel: copy_from_user - struct with pointers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.