ARM: Support KFENCE feature
Subsystems (2)
v2 cover ARM: Support KFENCE feature
This patchset supports Kfence feature, tested the kfence_test on ARM QEMU with or without ARM_LPAE and all passed.
V2 Resend:
- adjust is_write_fault() position in patch2 not patch3, sugguested Alexander
- Add ACKed from Marco
- rebased on v5.16-rc1
V2:
- drop patch4 in v1, which is used a new way to skip kfence test see commit c40c6e593bf9 ("kfence: test: fail fast if disabled at boot")
- fix some issue about NO MMU
- drop useless set_memory_valid() under no mmu
- fix implicit declaration of function ‘is_write_fault’ if no mmu
- make KFENCE depends on !XIP_KERNEL, no tested with xip
v1:
https://lore.kernel.org/linux-arm-kernel/[email protected]/
Kefeng Wang (3):
ARM: mm: Provide set_memory_valid()
ARM: mm: Provide is_write_fault()
ARM: Support KFENCE for ARM
arch/arm/Kconfig | 1 + arch/arm/include/asm/kfence.h | 53 +++++++++++++++++++++++++++++++ arch/arm/include/asm/set_memory.h | 1 + arch/arm/mm/fault.c | 16 ++++++++-- arch/arm/mm/pageattr.c | 42 ++++++++++++++++++------ 5 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 arch/arm/include/asm/kfence.h
Signature · 7 lines
2.26.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH RESEND v2 1/3 ARM: mm: Provide set_memory_valid()
This function validates and invalidates PTE entries, it will be used in the later patch.
--- arch/arm/include/asm/set_memory.h | 1 + arch/arm/mm/pageattr.c | 42 +++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-)
arch/arm/include/asm/set_memory.h +1 -0
@@ -11,6 +11,7 @@ int set_memory_ro(unsigned long addr, int numpages);int set_memory_rw (unsigned long addr,int numpages);int set_memory_x (unsigned long addr,int numpages);int set_memory_nx (unsigned long addr,int numpages); +int set_memory_valid (unsigned long addr,int numpages,int enable);#else static inline int set_memory_ro (unsigned long addr,int numpages) {return 0 ; }static inline int set_memory_rw (unsigned long addr,int numpages) {return 0 ; }
arch/arm/mm/pageattr.c +32 -10
63 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH RESEND v2 2/3 ARM: mm: Provide is_write_fault()
In reply to Kefeng WangThe function will check whether the fault is caused by a write access, it will be called in die_kernel_fault() too in next patch, so put it before the function of die_kernel_fault().
--- arch/arm/mm/fault.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm/mm/fault.c +6 -1
@@ -99,6 +99,11 @@ void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr) { }#endif /* CONFIG_MMU */ +static inline bool is_write_fault (unsigned int fsr) +{ +return (fsr &FSR_WRITE ) && !(fsr &FSR_CM ); +} +static void die_kernel_fault (const char *msg,struct mm_struct *mm,unsigned long addr,unsigned int fsr,struct pt_regs *regs)
@@ -261,7 +266,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)if (user_mode (regs)) flags |=FAULT_FLAG_USER ; -if ((fsr &FSR_WRITE ) && !(fsr &FSR_CM )) { +if (is_write_fault (fsr)) { flags |=FAULT_FLAG_WRITE ; vm_flags =VM_WRITE ; }
Signature · 7 lines
2.26.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH RESEND v2 3/3 ARM: Support KFENCE for ARM
In reply to Kefeng WangAdd architecture specific implementation details for KFENCE and enable KFENCE on ARM. In particular, this implements the required interface in
<asm/kfence.h>.
KFENCE requires that attributes for pages from its memory pool can individually be set. Therefore, force the kfence pool to be mapped at page granularity.
Testing this patch using the testcases in kfence_test.c and all passed with or without ARM_LPAE.
--- arch/arm/Kconfig | 1 + arch/arm/include/asm/kfence.h | 53 +++++++++++++++++++++++++++++++++++ arch/arm/mm/fault.c | 9 ++++-- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 arch/arm/include/asm/kfence.h
arch/arm/Kconfig +1 -0
@@ -69,6 +69,7 @@ config ARM select HAVE_ARCH_AUDITSYSCALL if AEABI && !OABI_COMPAT select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6 select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU + select HAVE_ARCH_KFENCE if MMU && !XIP_KERNEL select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL select HAVE_ARCH_MMAP_RND_BITS if MMU
arch/arm/include/asm/kfence.h new file +53 -0
53 lines not on this page · raw message
arch/arm/mm/fault.c +7 -2
@@ -17,6 +17,7 @@#include <linux/sched/debug.h> #include <linux/highmem.h> #include <linux/perf_event.h> +#include <linux/kfence.h> #include <asm/system_misc.h> #include <asm/system_info.h>
@@ -136,10 +137,14 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,/* * No handler, we'll have to terminate things with extreme prejudice. */ -if (addr <PAGE_SIZE ) +if (addr <PAGE_SIZE ) { msg ="NULL pointer dereference" ; -else + }else { +if (kfence_handle_page_fault (addr,is_write_fault (fsr), regs)) +return ; + msg ="paging request" ; + }die_kernel_fault (msg, mm, addr, fsr, regs); }
Signature · 7 lines
2.26.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Russell,
Could I send this to ARM patch system if no more comments,
what about your opinion, thanks.
Quoted 24 lines · Kefeng Wang
This patchset supports Kfence feature, tested the
kfence_teston ARM QEMU with or withoutARM_LPAEand all passed.V2 Resend:
- adjustis_write_fault()position in patch2 not patch3, sugguested Alexander
- Add ACKed from Marco
- rebased on v5.16-rc1V2:
- drop patch4 in v1, which is used a new way to skip kfence test see commitc40c6e593bf9("kfence: test: fail fast if disabled at boot")
- fix some issue about NO MMU
- drop uselessset_memory_valid()under no mmu
- fix implicit declaration of function ‘is_write_fault’ if no mmu
- make KFENCE depends on !XIP_KERNEL, no tested with xipv1:
https://lore.kernel.org/linux-arm-kernel/[email protected]/Kefeng Wang (3):
ARM: mm: Provideset_memory_valid()
ARM: mm: Provideis_write_fault()
ARM: Support KFENCE for ARM
Quoted 8 lines
arch/arm/Kconfig | 1 + arch/arm/include/asm/kfence.h | 53 +++++++++++++++++++++++++++++++ arch/arm/include/asm/set_memory.h | 1 + arch/arm/mm/fault.c | 16 ++++++++-- arch/arm/mm/pageattr.c | 42 ++++++++++++++++++------ 5 files changed, 100 insertions(+), 13 deletions(-)create mode 100644
arch/arm/include/asm/kfence.h
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel