Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/kprobes: Handle error returned by set_memory_rox()

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>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/b4907cf4339bd086abc40430d91311436cb0c18e.1708078401.git.christophe.leroy@csgroup.eu

authored by

Christophe Leroy and committed by
Michael Ellerman
f7f18e30 09ca1b11

+8 -2
+8 -2
arch/powerpc/kernel/kprobes.c
··· 134 134 if (!page) 135 135 return NULL; 136 136 137 - if (strict_module_rwx_enabled()) 138 - set_memory_rox((unsigned long)page, 1); 137 + if (strict_module_rwx_enabled()) { 138 + int err = set_memory_rox((unsigned long)page, 1); 139 139 140 + if (err) 141 + goto error; 142 + } 140 143 return page; 144 + error: 145 + module_memfree(page); 146 + return NULL; 141 147 } 142 148 143 149 int arch_prepare_kprobe(struct kprobe *p)