* [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration
@ 2022-05-25 1:44 Liao Chang
2022-05-25 6:23 ` Guo Ren
2022-05-26 15:33 ` Masami Hiramatsu
0 siblings, 2 replies; 5+ messages in thread
From: Liao Chang @ 2022-05-25 1:44 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, mhiramat, rostedt, peterz,
naveen.n.rao, jszhang, guoren
Cc: linux-riscv, linux-kernel
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 <chenguokai17@mails.ucas.ac.cn>
Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
v2:
Add Reported-by tag
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration
2022-05-25 1:44 [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration Liao Chang
@ 2022-05-25 6:23 ` Guo Ren
2022-05-25 7:59 ` liaochang (A)
2022-05-25 13:33 ` Jisheng Zhang
2022-05-26 15:33 ` Masami Hiramatsu
1 sibling, 2 replies; 5+ messages in thread
From: Guo Ren @ 2022-05-25 6:23 UTC (permalink / raw)
To: Liao Chang
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Masami Hiramatsu,
Steven Rostedt, Peter Zijlstra, Naveen Rao, jszhang, linux-riscv,
Linux Kernel Mailing List
On Wed, May 25, 2022 at 9:46 AM Liao Chang <liaochang1@huawei.com> 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 <chenguokai17@mails.ucas.ac.cn>
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> ---
> v2:
> Add Reported-by tag
>
> 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;
> + }
Thx reviewed-by: Guo Ren <guoren@kernel.org>
You also could give a fixup patch to csky, thx:
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)
> }
>
> static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
> --
> 2.17.1
>
--
Best Regards
Guo Ren
ML: https://lore.kernel.org/linux-csky/
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration
2022-05-25 6:23 ` Guo Ren
@ 2022-05-25 7:59 ` liaochang (A)
2022-05-25 13:33 ` Jisheng Zhang
1 sibling, 0 replies; 5+ messages in thread
From: liaochang (A) @ 2022-05-25 7:59 UTC (permalink / raw)
To: Guo Ren
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Masami Hiramatsu,
Steven Rostedt, Peter Zijlstra, Naveen Rao, jszhang, linux-riscv,
Linux Kernel Mailing List
在 2022/5/25 14:23, Guo Ren 写道:
> On Wed, May 25, 2022 at 9:46 AM Liao Chang <liaochang1@huawei.com> 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 <chenguokai17@mails.ucas.ac.cn>
>> Signed-off-by: Liao Chang <liaochang1@huawei.com>
>> ---
>> v2:
>> Add Reported-by tag
>>
>> 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;
>> + }
> Thx reviewed-by: Guo Ren <guoren@kernel.org>
>
> You also could give a fixup patch to csky, thx:
>
> 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;
> + }
> }
Sure, I will, thanks.
>
> static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
>
>> }
>>
>> static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
>> --
>> 2.17.1
>>
>
>
--
BR,
Liao, Chang
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration
2022-05-25 6:23 ` Guo Ren
2022-05-25 7:59 ` liaochang (A)
@ 2022-05-25 13:33 ` Jisheng Zhang
1 sibling, 0 replies; 5+ messages in thread
From: Jisheng Zhang @ 2022-05-25 13:33 UTC (permalink / raw)
To: Guo Ren
Cc: Liao Chang, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Masami Hiramatsu, Steven Rostedt, Peter Zijlstra, Naveen Rao,
linux-riscv, Linux Kernel Mailing List
On Wed, May 25, 2022 at 02:23:50PM +0800, Guo Ren wrote:
> On Wed, May 25, 2022 at 9:46 AM Liao Chang <liaochang1@huawei.com> 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 <chenguokai17@mails.ucas.ac.cn>
> > Signed-off-by: Liao Chang <liaochang1@huawei.com>
Reviewed-by: Jisheng Zhang <jszhang@kernel.org>
> > ---
> > v2:
> > Add Reported-by tag
> >
> > 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;
> > + }
> Thx reviewed-by: Guo Ren <guoren@kernel.org>
>
> You also could give a fixup patch to csky, thx:
>
> 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)
>
> > }
> >
> > static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
> > --
> > 2.17.1
> >
>
>
> --
> Best Regards
> Guo Ren
>
> ML: https://lore.kernel.org/linux-csky/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration
2022-05-25 1:44 [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration Liao Chang
2022-05-25 6:23 ` Guo Ren
@ 2022-05-26 15:33 ` Masami Hiramatsu
1 sibling, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2022-05-26 15:33 UTC (permalink / raw)
To: Liao Chang
Cc: paul.walmsley, palmer, aou, rostedt, peterz, naveen.n.rao,
jszhang, guoren, linux-riscv, linux-kernel
On Wed, 25 May 2022 09:44:24 +0800
Liao Chang <liaochang1@huawei.com> 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 <chenguokai17@mails.ucas.ac.cn>
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
Looks good to me.
Fixes: c22b0bcb1dd0 ("riscv: Add kprobes supported")
Cc: stable@vger.kernel.org
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thank you,
> ---
> v2:
> Add Reported-by tag
>
> 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
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-05-26 15:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 1:44 [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration Liao Chang
2022-05-25 6:23 ` Guo Ren
2022-05-25 7:59 ` liaochang (A)
2022-05-25 13:33 ` Jisheng Zhang
2022-05-26 15:33 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).