linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: Clean up all resources when register_fprobe_ips returns an error
@ 2022-10-25  8:06 Chuang Wang
  2022-10-25  9:01 ` Jiri Olsa
  0 siblings, 1 reply; 3+ messages in thread
From: Chuang Wang @ 2022-10-25  8:06 UTC (permalink / raw)
  Cc: Chuang Wang, stable, Song Liu, Jiri Olsa, Alexei Starovoitov,
	Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Steven Rostedt, Masami Hiramatsu, bpf, linux-kernel

When register_fprobe_ips returns an error, bpf_link_cleanup just cleans
up bpf_link_primer's resources and forgets to clean up
bpf_kprobe_multi_link, addrs, cookies.

So, by adding 'goto error', this ensures that all resources are cleaned
up.

Cc: stable@vger.kernel.org
Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
Signed-off-by: Chuang Wang <nashuiliang@gmail.com>
---
 kernel/trace/bpf_trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 1ed08967fb97..5b806ef20857 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2778,7 +2778,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	err = register_fprobe_ips(&link->fp, addrs, cnt);
 	if (err) {
 		bpf_link_cleanup(&link_primer);
-		return err;
+		goto error;
 	}
 
 	return bpf_link_settle(&link_primer);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf: Clean up all resources when register_fprobe_ips returns an error
  2022-10-25  8:06 [PATCH] bpf: Clean up all resources when register_fprobe_ips returns an error Chuang Wang
@ 2022-10-25  9:01 ` Jiri Olsa
  2022-10-25  9:36   ` Chuang W
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2022-10-25  9:01 UTC (permalink / raw)
  To: Chuang Wang
  Cc: stable, Song Liu, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Steven Rostedt,
	Masami Hiramatsu, bpf, linux-kernel

On Tue, Oct 25, 2022 at 04:06:28PM +0800, Chuang Wang wrote:
> When register_fprobe_ips returns an error, bpf_link_cleanup just cleans
> up bpf_link_primer's resources and forgets to clean up
> bpf_kprobe_multi_link, addrs, cookies.
> 
> So, by adding 'goto error', this ensures that all resources are cleaned
> up.
> 
> Cc: stable@vger.kernel.org
> Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
> Signed-off-by: Chuang Wang <nashuiliang@gmail.com>
> ---
>  kernel/trace/bpf_trace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 1ed08967fb97..5b806ef20857 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -2778,7 +2778,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
>  	err = register_fprobe_ips(&link->fp, addrs, cnt);
>  	if (err) {
>  		bpf_link_cleanup(&link_primer);
> -		return err;
> +		goto error;

that should be taken care of bpf_kprobe_multi_link_dealloc,
through the fput path in bpf_link_cleanup

do you see any related memory leak like report in kmemleak?

jirka

>  	}
>  
>  	return bpf_link_settle(&link_primer);
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf: Clean up all resources when register_fprobe_ips returns an error
  2022-10-25  9:01 ` Jiri Olsa
@ 2022-10-25  9:36   ` Chuang W
  0 siblings, 0 replies; 3+ messages in thread
From: Chuang W @ 2022-10-25  9:36 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: stable, Song Liu, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Steven Rostedt,
	Masami Hiramatsu, bpf, linux-kernel

Sorry, I didn't notice this.

On Tue, Oct 25, 2022 at 5:01 PM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Tue, Oct 25, 2022 at 04:06:28PM +0800, Chuang Wang wrote:
> > When register_fprobe_ips returns an error, bpf_link_cleanup just cleans
> > up bpf_link_primer's resources and forgets to clean up
> > bpf_kprobe_multi_link, addrs, cookies.
> >
> > So, by adding 'goto error', this ensures that all resources are cleaned
> > up.
> >
> > Cc: stable@vger.kernel.org
> > Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
> > Signed-off-by: Chuang Wang <nashuiliang@gmail.com>
> > ---
> >  kernel/trace/bpf_trace.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> > index 1ed08967fb97..5b806ef20857 100644
> > --- a/kernel/trace/bpf_trace.c
> > +++ b/kernel/trace/bpf_trace.c
> > @@ -2778,7 +2778,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
> >       err = register_fprobe_ips(&link->fp, addrs, cnt);
> >       if (err) {
> >               bpf_link_cleanup(&link_primer);
> > -             return err;
> > +             goto error;
>
> that should be taken care of bpf_kprobe_multi_link_dealloc,
> through the fput path in bpf_link_cleanup
>
> do you see any related memory leak like report in kmemleak?
>
> jirka
>
> >       }
> >
> >       return bpf_link_settle(&link_primer);
> > --
> > 2.34.1
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-25  9:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25  8:06 [PATCH] bpf: Clean up all resources when register_fprobe_ips returns an error Chuang Wang
2022-10-25  9:01 ` Jiri Olsa
2022-10-25  9:36   ` Chuang W

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).