mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-04 23:46:39 +07:00
305b152325
Implement write protection for kernel modules text and read-only data sections by implementing set_memory_[ro|rw] on s390. Since s390 has no execute bit in the pte's NX is not supported. set_memory_[ro|rw] will only work on normal pages and not on large pages, so in case a large page should be modified bail out with a warning. Signed-off-by: Jan Glauber <jang@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
56 lines
1.1 KiB
C
56 lines
1.1 KiB
C
/*
|
|
* Copyright IBM Corp. 2011
|
|
* Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
|
|
*/
|
|
#include <linux/module.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/hugetlb.h>
|
|
#include <asm/pgtable.h>
|
|
|
|
static void change_page_attr(unsigned long addr, int numpages,
|
|
pte_t (*set) (pte_t))
|
|
{
|
|
pte_t *ptep, pte;
|
|
pmd_t *pmdp;
|
|
pud_t *pudp;
|
|
pgd_t *pgdp;
|
|
int i;
|
|
|
|
for (i = 0; i < numpages; i++) {
|
|
pgdp = pgd_offset(&init_mm, addr);
|
|
pudp = pud_offset(pgdp, addr);
|
|
pmdp = pmd_offset(pudp, addr);
|
|
if (pmd_huge(*pmdp)) {
|
|
WARN_ON_ONCE(1);
|
|
continue;
|
|
}
|
|
ptep = pte_offset_kernel(pmdp, addr + i * PAGE_SIZE);
|
|
|
|
pte = *ptep;
|
|
pte = set(pte);
|
|
ptep_invalidate(&init_mm, addr + i * PAGE_SIZE, ptep);
|
|
*ptep = pte;
|
|
}
|
|
}
|
|
|
|
int set_memory_ro(unsigned long addr, int numpages)
|
|
{
|
|
change_page_attr(addr, numpages, pte_wrprotect);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(set_memory_ro);
|
|
|
|
int set_memory_rw(unsigned long addr, int numpages)
|
|
{
|
|
change_page_attr(addr, numpages, pte_mkwrite);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(set_memory_rw);
|
|
|
|
/* not possible */
|
|
int set_memory_nx(unsigned long addr, int numpages)
|
|
{
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(set_memory_nx);
|