Skip to contentSkip to conversation

riscv/kprobe: reclaim insn_slot on kprobe unregistration

PATCH Superseded Liao Chang 2 participants 3 messages May 23, 2022 – May 25, 2022 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Liao Chang

author
#0 lore raw

PATCH 1/1 riscv/kprobe: reclaim insn_slot on kprobe unregistration

On kprobe registration kernel allocate one insn_slot for new kprobe, but it forget to reclaim the insn_slot on unregistration, leading to a potential leakage.

This bug reported by Chen Guokai <[email protected]>.

---
 arch/riscv/kernel/probes/kprobes.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kernel/probes/kprobes.c +4 -0
index e6e950b7cf32..f12eb1fbb52c 100644
@@ -110,6 +110,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)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Liao Chang

On kprobe registration kernel allocate one insn_slot for new kprobe, but it forget to reclaim the insn_slot on unregistration, leading to a potential leakage.

+ Guo Ren

Nice catch! I think csky needs the fix as well.

Quoted 2 lines

This bug reported by Chen Guokai <[email protected]>.

This needs a "Reported-by: ..." tag

Quoted 29 lines
---
 arch/riscv/kernel/probes/kprobes.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kernel/probes/kprobes.c +4 -0
index e6e950b7cf32..f12eb1fbb52c 100644
@@ -110,6 +110,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)
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#2 lore raw
Quoted 5 lines · Jisheng Zhang
Quoted 3 lines · Liao Chang

On kprobe registration kernel allocate one insn_slot for new kprobe, but it forget to reclaim the insn_slot on unregistration, leading to a potential leakage.

Quoted 8 lines

+ Guo Ren

Nice catch! I think csky needs the fix as well.

Quoted 2 lines

This bug reported by Chen Guokai <[email protected]>.

This needs a "Reported-by: ..." tag

Thanks for comment.

Quoted 31 lines
Quoted 30 lines
---
 arch/riscv/kernel/probes/kprobes.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kernel/probes/kprobes.c +4 -0
index e6e950b7cf32..f12eb1fbb52c 100644
@@ -110,6 +110,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)
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

.

Signature · 2 lines
BR,
Liao, Chang