Re: Verify Kernel Pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




mem_map is an array of page structure, each element of this array is
of "page" structure type. Actually mem_map is used for reverse
mappeing of physical memory of system. This array represents the
physical memory interms of page sturcture. Lets say for simplicity we
have total physical memory of 256K and one one physical page of 4K,
then in taht case mem_map will have 256/4 = 64 enteries and max_mapnr
will be set to 64.

So as per the kernel sources (file: include/asm-i386/page.h)
#define pfn_valid(pfn)          ((pfn) < max_mapnr)
#define virt_addr_valid(kaddr)  pfn_valid(__pa(kaddr) >> PAGE_SHIFT)

virt_addr_valid() macro only tells whether the given virtual address
can be mapped to any physical page or not. __pa() macro gives the
physical address for a given virtual address just by subracting the
PAGE_OFFSET from given virtual address. Now then we right shift that
physical address by page size which gives us the page number in which
our physical adress falls and then we look if this page number is less
than the total number of physical pages in system, if yes then it
means we can mapped this virtual address to some physical address else
our given virtual address can not be mapped to any physical address
in system.

I think I get it. You don't have more pages than RAM frames (can't the kernel swap its own pages?) so all this check does is make sure the address falls in a page you are allowed to use.


So if we go back to Talib's original question, the only thing he can do is traverse the page table tree to see if the address is indeed valid.
I think this is what virt_to_page(addr) does.

Having understood all this, and applying this information to the
actual problem of verifying the virtual address, we can use this macro
to just make sure that the kernel virtual address passed by user space
back to kernel falls in kernel virtual address space but, we can not
be sure if the given address is the same as we passed it to user space
earlier, for that as mentioned by some one we need to user some
ginature in the structure being pointed by this virtual address.

You have to check first that the virtual address is mapped to real a frame, or you'll get a kernel panic. no?

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux