howto set some kernel pages to readonly?
Peter Wächtler
pwaechtler at mac.com
Thu Apr 7 15:13:48 EDT 2011
Am Donnerstag, 7. April 2011, 20:26:36 schrieb Peter Wächtler:
> Hello Linux ARM developers,
>
> on Linux x86 there is infrastructure to set rodata to, aeh, readonly. ;)
>
> I also want to protect some pages to readonly as a guard.
> So if some kernel code writes to the memory the kernel panics.
>
> I tried the following without success:
>
> And I have to admit that I don't understand all the macros for
> manipulating the page table entries ;(
> Any clue what's wrong?
>
>
> int set_page_ro(unsigned long addr)
> {
> pte_t new_pte;
> unsigned long pfn;
> pte_t *pte;
> pgd_t *pgd;
> pmd_t *pmd;
>
> pgd = pgd_offset_k(addr);
> pmd = pmd_offset(pgd, addr);
>
> pfn = __phys_to_pfn(virt_to_phys((void*)addr));
>
> pte = pte_offset_kernel(pmd, addr);
> new_pte = pfn_pte(pfn, __pgprot(pgprot_val(pgprot_kernel) |
> (__PAGE_READONLY)) );
>
> set_pte_ext(pte, new_pte, 0);
>
> return 0;
> }
>
>
> set_page_ro( (unsigned long)pa );
> flush_tlb_kernel_page((long)pa);
>
While the variable is named "pa" - it's actually a virtual address.
The code has to run on a SMP box - ARM 1136 multi core (ARMv6).
More information about the linux-arm-kernel
mailing list