Skip to contentSkip to conversation

arm64: kprobes: check the return value of set_memory_rox()

PATCH Applied Yang Shi 2 participants 2 messages Nov 4, 2025 – Nov 7, 2025 arm64

lore
Share & tools
lore

Yang Shi

author
#0 lore raw

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.

Fixes 195a1b7d8388 ("arm64: kprobes: call set_memory_rox() for kprobe 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
index 8ab6104a4883..43a0361a8bf0 100644
@@ -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
maintainer Applied
#1 lore raw
Quoted 8 lines · Yang Shi

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.

[...]

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