foss-for-synopsys-dwc-arc-processors / linux

Helpful resources for users & developers of Linux kernel for ARC
22 stars 13 forks source link

ARC64/kernel: LTP mprotect04 looping #39

Closed vineetgarc closed 3 years ago

vineetgarc commented 3 years ago

I enabled LTP for ARC64 and tried executing this on QEMU. mprotect04 is currently looping - it is working for ARC64 MMUv4 though meaning this is an issue in MMUv6 implementation.

cupertinomiranda commented 3 years ago

Let me know if you need help in this.

vineetgarc commented 3 years ago

this is a kernel bug !

vineetgarc commented 3 years ago

commit 32734eea2cb7f0d4198eee271f4ec3416e86a914 (HEAD -> arc64, gh/arc64) Author: Vineet Gupta vgupta@synopsys.com Date: Fri Feb 19 14:44:02 2021 -0800

ARCv3: mm: fix pte_modify() not clearing exec related bits: _PAGE_NOTEXEC_U

This showed up a LTP mprotect04 looping on same ProtV fault when trying
to exeute self-modifying code after an mprotect(PROT_EXEC)

pte_modify() needs to clear out existing access/permission bits and set
the ones per mprotect(), while leaving the rest of pte bits intact.

The old code used a mask to "keep" existing bits and supposedly cleared
the rest (since it used PAGE_MASK which cleared everything). However in
ARC64, PAGE_MASK misses the high bits NXU and NXK. So invert the mask
strategy - clear out everything not needed explicitly and rely on
newprot to DTRT.

Implementation wise we are clearing AP.RO and AP.UK so it would seem
that we are making them read-write and user-n-kernel but that is just an
intermediate step as OR with newprot brings in any '1' bits - so __P001
will reinstate AP.RO thus DTRT. This is just an implementation detail
worth noting here.

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>