The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] riscv: kprobes: free insn slot in arch_remove_kprobe() to avoid memory leak
       [not found] <20260731100940.2330-1-yuanxiaofeng@eswincomputing.com>
@ 2026-08-05  8:23 ` Xiaofeng Yuan
  0 siblings, 0 replies; only message in thread
From: Xiaofeng Yuan @ 2026-08-05  8:23 UTC (permalink / raw)
  To: linux-kernel; +Cc: yuanxiaofeng

When a kprobe is removed, arch_remove_kprobe() does not free the
instruction slot allocated by arch_prepare_kprobe(). This causes
a memory leak every time a kprobe is unregistered.

Other architectures such as arm64, x86, and powerpc all free
the slot in their arch_remove_kprobe() implementations. Add
the missing free_insn_slot() call for RISC-V.

Signed-off-by: Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com>
---
 arch/riscv/kernel/probes/kprobes.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c
index 9e2afabf94..a76eab2972 100644
--- a/arch/riscv/kernel/probes/kprobes.c
+++ b/arch/riscv/kernel/probes/kprobes.c
@@ -128,6 +128,10 @@ void __kprobes arch_disarm_kprobe(struct kprobe *p)
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
 {
+	if (p->ainsn.api.insn) {
+		free_insn_slot(p->ainsn.api.insn, 0);
+		p->ainsn.api.insn = NULL;
+	}
 }
 
 static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-05  8:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260731100940.2330-1-yuanxiaofeng@eswincomputing.com>
2026-08-05  8:23 ` [PATCH] riscv: kprobes: free insn slot in arch_remove_kprobe() to avoid memory leak Xiaofeng Yuan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox