Accessing user space from kernel space - get_user_pages

I would like to pass a pointer from user space to a function in my kernel module. I do not want to use copy_from_user. I read that I have to use a function get_user_pages.

For example, one page.

struct page **pages;
pages = kmalloc(1 * sizeof(*pages), GFP_KERNEL);

down_read(&current->mm->mmap_sem);
get_user_pages(current,current->mm,uaddr, 1, 1, 0,pages,NULL);
up_read(&current->mm->mmap_sem);

uaddr is the address in user space.

  • After that, am I allowed to pass and pass a uaddrkernel module to my function? Or maybe I need to use these in some way struct pages?
  • Why should I use read / read?
  • After all I need to use SetPageDirty()and page_cache_release()functions?
+3
source share
4 answers

, get_user_pages ( - uaddr ).

copy_from_user , void __user * copy_from_user.

+2

, , Scatter/Gather DMA . . , copy_to/from , . ?

+2
  • , uaddr. , ​​ , . , , , uaddr.
  • , , .
  • , get_user_pages(), "" .
+2

Once you get a valid user space address, use get_user_pages to get a pointer to the structure page. after receiving the page structure pointer, in order to access it in kernel mode, you need to map it to the kernel virtual address using kmap. hope that helps

0
source

Source: https://habr.com/ru/post/1724988/


All Articles