Mprotect () as functionality in the Linux kernel

I am in the Linux kernel module and I am allocating some memory, say vmalloc() . I want the memory to read, write, and execute permission. What is a clean and suitable way to do this? Basically, this is usually the equivalent of calling mprotect() , but in kernel space.

If I browse the page, pgd_offset() , pud_offset() , pmd_offset() , pte_offset_map() and then pte_mkwrite() , I encounter bind errors when I tried it on 2.6.39. In addition, it seems that if I make a page move, it is hacking, and there should be a cleaner and more suitable method.

My kernel module will be a loadable module, so the internal characters are not available to me.

Thanks in advance for your guidance.

+6
source share
2 answers

Have you tried to reference do_mprotect () [the kernel function corresponding to mprotect ()] directly?

0
source

There is a good answer to this question here: https://unix.stackexchange.com/questions/450557/is-there-any-function-analogous-to-mprotect-in-the-linux-kernel .

 asm-generic/set_memory.h:int set_memory_ro(unsigned long addr, int numpages); asm-generic/set_memory.h:int set_memory_rw(unsigned long addr, int numpages); asm-generic/set_memory.h:int set_memory_x(unsigned long addr, int numpages); asm-generic/set_memory.h:int set_memory_nx(unsigned long addr, int numpages); 

they are defined here: https://elixir.bootlin.com/linux/v4.3/source/arch/x86/include/asm/cacheflush.h#L47

0
source

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


All Articles