arm64: kprobes: check the return value of set_memory_rox()
PATCH v2 1/1 arm64: kprobes: check the return value of set_memory_rox()
Since commit a166563e7ec3 ("arm64: mm: support large block mapping when rodata=full"), __change_memory_common has more chance to fail due to memory allocation failure when splitting page table. So check the return value of set_memory_rox(), then bail out if it fails otherwise we may have RW memory mapping for kprobes insn page.
---
v2: Fixed the typo per Punit Agrawal
Collected the R-bs
arch/arm64/kernel/probes/kprobes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/kernel/probes/kprobes.c +4 -1
@@ -49,7 +49,10 @@ void *alloc_insn_page(void) addr =execmem_alloc (EXECMEM_KPROBES ,PAGE_SIZE );if (!addr)return NULL ; -set_memory_rox ((unsigned long )addr,1 ); +if (set_memory_rox ((unsigned long )addr,1 )) { +execmem_free (addr); +return NULL ; + }return addr; }
Signature · 1 line
2.47.0
Quoted 8 lines · Yang Shi
Since commit
a166563e7ec3("arm64: mm: support large block mapping when rodata=full"),__change_memory_commonhas more chance to fail due to memory allocation failure when splitting page table. So check the return value ofset_memory_rox(), then bail out if it fails otherwise we may have RW memory mapping for kprobes insn page.[...]
Applied to arm64 (for-next/fixes), thanks!
[1/1] arm64: kprobes: check the return value of set_memory_rox()
https://git.kernel.org/arm64/c/0ec364c0c95f
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev