Sample Header Ad - 728x90

Manually set NX bit of specific PTE

2 votes
1 answer
932 views
On Ubuntu with kernel 4.16.7 I am writing a custom system call and, I want to set the NX bit of a specific Page Table Entry. So far I have this piece of code, where I am doing a page table walk to get the PTE I want and then try to set its NX bit: pgd = pgd_offset(mm, addr); if (pgd_none(*pgd) || pgd_bad(*pgd)){ printk("Invalid pgd"); return -1; } p4d = p4d_offset(pgd, addr); if (p4d_none(*p4d) || p4d_bad(*p4d)){ printk("Invalid p4d"); return -1; } pud = pud_offset(p4d, addr); if (pud_none(*pud) || pud_bad(*pud)){ printk("Invalid pud"); return -1; } pmd = pmd_offset(pud, addr); if (pmd_none(*pmd) || pmd_bad(*pmd)){ printk("Invalid pmd"); return -1; } ptep = pte_offset_map(pmd, addr); if (!ptep){ printk("Invalid ptep"); return -1; } pte = *ptep; if (pte_present(pte)){ printk("pte_set_flags"); printk("NX bit before: %d", pte_exec(pte)); // pte_set_flags(pte, _PAGE_NX); // printk("NX bit after : %d", pte_exec(pte)); printk("pte_clear_flags"); // pte_clear_flags(pte, _PAGE_NX); // Same as pte_mkexec() pte_mkexec(pte); printk("NX bit after : %d", pte_exec(pte)); page = pte_page(pte); if (page){ printk("Page frame struct is @ %p", page); } pte_unmap(ptep); } but it doesn't work. All the printk commands show the same result. Any insight?
Asked by Mar Tsan (21 rep)
Aug 8, 2018, 09:05 AM
Last activity: Dec 20, 2018, 06:55 AM