diff mbox series

riscv/kprobe: reclaim insn_slot on kprobe unregistration

Message ID 20220523015124.98743-1-liaochang1@huawei.com (mailing list archive)
State New
Headers show
Series riscv/kprobe: reclaim insn_slot on kprobe unregistration | expand

Commit Message

Liao Chang May 23, 2022, 1:51 a.m. UTC
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 <chenguokai17@mails.ucas.ac.cn>.

Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
 arch/riscv/kernel/probes/kprobes.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Jisheng Zhang May 24, 2022, 3:12 p.m. UTC | #1
On Mon, May 23, 2022 at 09:51:24AM +0800, Liao Chang wrote:
> 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.

> 
> This bug reported by Chen Guokai <chenguokai17@mails.ucas.ac.cn>.

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

> 
> Signed-off-by: Liao Chang <liaochang1@huawei.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 e6e950b7cf32..f12eb1fbb52c 100644
> --- a/arch/riscv/kernel/probes/kprobes.c
> +++ b/arch/riscv/kernel/probes/kprobes.c
> @@ -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)
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
Liao Chang May 25, 2022, 1:24 a.m. UTC | #2
在 2022/5/24 23:12, Jisheng Zhang 写道:
> On Mon, May 23, 2022 at 09:51:24AM +0800, Liao Chang wrote:
>> 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.
> 
>>
>> This bug reported by Chen Guokai <chenguokai17@mails.ucas.ac.cn>.
> 
> This needs a "Reported-by: ..." tag

Thanks for comment.

> 
>>
>> Signed-off-by: Liao Chang <liaochang1@huawei.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 e6e950b7cf32..f12eb1fbb52c 100644
>> --- a/arch/riscv/kernel/probes/kprobes.c
>> +++ b/arch/riscv/kernel/probes/kprobes.c
>> @@ -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)
>> -- 
>> 2.17.1
>>
>>
>> _______________________________________________
>> linux-riscv mailing list
>> linux-riscv@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-riscv
> .
diff mbox series

Patch

diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c
index e6e950b7cf32..f12eb1fbb52c 100644
--- a/arch/riscv/kernel/probes/kprobes.c
+++ b/arch/riscv/kernel/probes/kprobes.c
@@ -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)