2022-05-25 13:52:44

by Liao, Chang

[permalink] [raw]
Subject: [PATCH] csky/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.

Reported-by: Chen Guokai <[email protected]>
Signed-off-by: Liao Chang <[email protected]>
---
arch/csky/kernel/probes/kprobes.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/arch/csky/kernel/probes/kprobes.c b/arch/csky/kernel/probes/kprobes.c
index 42920f25e73c..661da54b418f 100644
--- a/arch/csky/kernel/probes/kprobes.c
+++ b/arch/csky/kernel/probes/kprobes.c
@@ -124,6 +124,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



2022-05-26 20:58:04

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH] csky/kprobe: reclaim insn_slot on kprobe unregistration

On Wed, 25 May 2022 16:02:41 +0800
Liao Chang <[email protected]> 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.
>
> Reported-by: Chen Guokai <[email protected]>
> Signed-off-by: Liao Chang <[email protected]>

This looks good to me too. I think this should go through csky tree.

Reviewed-by: Masami Hiramatsu (Google) <[email protected]>

Thank you,


> ---
> arch/csky/kernel/probes/kprobes.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/csky/kernel/probes/kprobes.c b/arch/csky/kernel/probes/kprobes.c
> index 42920f25e73c..661da54b418f 100644
> --- a/arch/csky/kernel/probes/kprobes.c
> +++ b/arch/csky/kernel/probes/kprobes.c
> @@ -124,6 +124,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
>


--
Masami Hiramatsu (Google) <[email protected]>

2022-05-28 18:47:26

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH] csky/kprobe: reclaim insn_slot on kprobe unregistration

On Thu, May 26, 2022 at 11:30 PM Masami Hiramatsu <[email protected]> wrote:
>
> On Wed, 25 May 2022 16:02:41 +0800
> Liao Chang <[email protected]> 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.
> >
> > Reported-by: Chen Guokai <[email protected]>
> > Signed-off-by: Liao Chang <[email protected]>
>
> This looks good to me too. I think this should go through csky tree.
Okay, I would add the Fix line and put it into Linux-5.19-rc2.

>
> Reviewed-by: Masami Hiramatsu (Google) <[email protected]>
>
> Thank you,
>
>
> > ---
> > arch/csky/kernel/probes/kprobes.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/arch/csky/kernel/probes/kprobes.c b/arch/csky/kernel/probes/kprobes.c
> > index 42920f25e73c..661da54b418f 100644
> > --- a/arch/csky/kernel/probes/kprobes.c
> > +++ b/arch/csky/kernel/probes/kprobes.c
> > @@ -124,6 +124,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
> >
>
>
> --
> Masami Hiramatsu (Google) <[email protected]>



--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/