diff mbox series

powerpc/kprobes: Handle error returned by set_memory_rox()

Message ID b4907cf4339bd086abc40430d91311436cb0c18e.1708078401.git.christophe.leroy@csgroup.eu (mailing list archive)
State Accepted
Commit f7f18e30b468458b2611ca65d745b50edcda9f43
Headers show
Series powerpc/kprobes: Handle error returned by set_memory_rox() | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 6 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 23 jobs.

Commit Message

Christophe Leroy Feb. 16, 2024, 10:13 a.m. UTC
set_memory_rox() can fail.

In case it fails, free allocated memory and return NULL.

Link: https://github.com/KSPP/linux/issues/7
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/powerpc/kernel/kprobes.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Michael Ellerman March 13, 2024, 1:19 p.m. UTC | #1
On Fri, 16 Feb 2024 11:13:28 +0100, Christophe Leroy wrote:
> set_memory_rox() can fail.
> 
> In case it fails, free allocated memory and return NULL.
> 
> 

Applied to powerpc/next.

[1/1] powerpc/kprobes: Handle error returned by set_memory_rox()
      https://git.kernel.org/powerpc/c/f7f18e30b468458b2611ca65d745b50edcda9f43

cheers
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index b20ee72e873a..bbca90a5e2ec 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -134,10 +134,16 @@  void *alloc_insn_page(void)
 	if (!page)
 		return NULL;
 
-	if (strict_module_rwx_enabled())
-		set_memory_rox((unsigned long)page, 1);
+	if (strict_module_rwx_enabled()) {
+		int err = set_memory_rox((unsigned long)page, 1);
 
+		if (err)
+			goto error;
+	}
 	return page;
+error:
+	module_memfree(page);
+	return NULL;
 }
 
 int arch_prepare_kprobe(struct kprobe *p)