Re: How to create a kernel virtual mapping for physical addresses.

From: Arnd Bergmann
Date: Thu Apr 21 2011 - 15:37:18 EST


On Thursday 21 April 2011 20:46:00 brace@xxxxxxxxxxxxxxxxxx wrote:
> Thanks for your reply.
>
> I have a block of highmem that I want to map into my 32bit driver.
> This block is 256M in size.

If you have highmem enabled, there probably is not enough space
to map all of this at once into the vmalloc area. If you had
that much virtual address space, you would not need highmem ;-)

> I get the physical address and want to create a contiguous virtual buffer.
> I have been investigating vmap() as a possible solution.
>
> I build up an array of pages as follows.
> pfn = physical_address >> PAGE_SHIFT
> for (i = 0; i < num_pages; i++) {
> page = pfn_to_page(pfn);
> page_array[i] = page;
> ++pfn
> }
>
> map = vmap(page_array, num_pages, VM_IOREMAP, PAGE_KERNEL);
>
> Using the above method, I can memset the block of memory using
> map as my virtual address.
>
> However, later, I get the following error message:
>
> kernel tried to execute NX-protected page - exploit attempt? (uid: 0)
> BUG: unable to handle kernel paging request at virtual address c5000840
>
> The address 0xc5000840 is within the range of vmap()ed memory.

Maybe you have overwritten a kernel module and the kernel now
tries to execute within the mapped area?

> What should I be doing instead?

It's not clear at all what you are actually trying to do. Which driver
is this? If it's out-of-tree code, please post it here.

Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/