0
votes

I am trying to use the mamp() functionality provided in linux-kernel. As we call mmap() in user-space we try to map virtual memory area of user-space process to the memory in the kernel-space.

the definition of mamp() inside kernel is done in my kernel module which try to allocate some memory in pages & maps it during mmap system call. The memory content of this kernel-space memory could be filled by this module.

The question i want to ask is that after memory mapping the user-space process could access the mapped memory directly with-out any extra kernel overload so there will be no system-call like read() but if the memory(allocated inside kernel-space & mapped in the kernel-space) is containing the pointer to other memory(not mapped) allocated inside the kernel-space then could the user-space process be able to access this unmapped memory with the help of mapped memory's content which are pointer to this unmapped memory.

3

3 Answers

1
votes

No, userspace can't chase pointers in mapped memory that point to unmapped kernel memory.

0
votes

No user-space process can not be able to access the unmapped memory. Kernel wont allow you to access that memory. You are able to access only that portion of memory which is mapped via mmap. I think use can use remap_pfn_range function explicitly to remapping the region.

From Linux mmap man page

The effect of changing the size of the underlying file of a mapping on the pages that correspond to added or removed regions of the file is unspecified.

0
votes

No,you can't.

However,If your purpose is to change your mmaped area on the fly,Here are some options:

A. In user space, you can use mremap which expands (or shrinks) an existing memory mapping.

B. In kernel space,in your driver, you need to implement nopage() method or remap_pfn_range,but remap_pfn_range has its limitation which Linux only gives the reserved pages and you even cant remap normal address,such as the one allocated by get_free_page()