linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [v2 PATCH] arm64: kprobes: check the return value of set_memory_rox()
@ 2025-11-04 21:49 Yang Shi
  2025-11-07 15:53 ` Will Deacon
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Shi @ 2025-11-04 21:49 UTC (permalink / raw)
  To: catalin.marinas, will, ryan.roberts, dev.jain, punit.agrawal
  Cc: yang, linux-arm-kernel, linux-kernel

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")
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Signed-off-by: Yang Shi <yang@os.amperecomputing.com>
---
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(-)

diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 8ab6104a4883..43a0361a8bf0 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -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;
 }
 
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [v2 PATCH] arm64: kprobes: check the return value of set_memory_rox()
  2025-11-04 21:49 [v2 PATCH] arm64: kprobes: check the return value of set_memory_rox() Yang Shi
@ 2025-11-07 15:53 ` Will Deacon
  0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2025-11-07 15:53 UTC (permalink / raw)
  To: catalin.marinas, ryan.roberts, dev.jain, punit.agrawal, Yang Shi
  Cc: kernel-team, Will Deacon, linux-arm-kernel, linux-kernel

On Tue, 04 Nov 2025 13:49:47 -0800, Yang Shi wrote:
> 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,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-07 15:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-04 21:49 [v2 PATCH] arm64: kprobes: check the return value of set_memory_rox() Yang Shi
2025-11-07 15:53 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).