diff mbox series

[v4,1/4] bootconfig: init: Fix memblock leak in xbc_make_cmdline()

Message ID 163177339181.682366.8713781325929549256.stgit@devnote2 (mailing list archive)
State New
Headers show
Series bootconfig: Fixes to bootconfig memory management etc. | expand

Commit Message

Masami Hiramatsu (Google) Sept. 16, 2021, 6:23 a.m. UTC
Free unused memblock in a error case to fix memblock leak
in xbc_make_cmdline().

Fixes: 51887d03aca1 ("bootconfig: init: Allow admin to use bootconfig for kernel command line")
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 init/main.c |    1 +
 1 file changed, 1 insertion(+)

Comments

Steven Rostedt Oct. 7, 2021, 1:02 a.m. UTC | #1
On Thu, 16 Sep 2021 15:23:12 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Free unused memblock in a error case to fix memblock leak
> in xbc_make_cmdline().
> 
> Fixes: 51887d03aca1 ("bootconfig: init: Allow admin to use bootconfig for kernel command line")
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  init/main.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/init/main.c b/init/main.c
> index 3f7216934441..0b054fff8e92 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -382,6 +382,7 @@ static char * __init xbc_make_cmdline(const char *key)
>  	ret = xbc_snprint_cmdline(new_cmdline, len + 1, root);
>  	if (ret < 0 || ret > len) {
>  		pr_err("Failed to print extra kernel cmdline.\n");
> +		memblock_free_ptr(new_cmdline, len + 1);
>  		return NULL;
>  	}
>  

Hmm, looking at my patch queue, I noticed that this did not get
applied. I'm thinking I may have been confused with the other memory
freeing that was put into the xbc_destroy(), thinking this was part of
that. But now that I look at this patch in the context of the code, it
looks like this patch is required, as "new_cmdline" never gets exposed
on this error.

Masami, I just want to confirm, that this patch is still relevant, right?

Thanks!

-- Steve
Masami Hiramatsu (Google) Oct. 7, 2021, 1:43 a.m. UTC | #2
On Wed, 6 Oct 2021 21:02:16 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Thu, 16 Sep 2021 15:23:12 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
> > Free unused memblock in a error case to fix memblock leak
> > in xbc_make_cmdline().
> > 
> > Fixes: 51887d03aca1 ("bootconfig: init: Allow admin to use bootconfig for kernel command line")
> > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> > ---
> >  init/main.c |    1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/init/main.c b/init/main.c
> > index 3f7216934441..0b054fff8e92 100644
> > --- a/init/main.c
> > +++ b/init/main.c
> > @@ -382,6 +382,7 @@ static char * __init xbc_make_cmdline(const char *key)
> >  	ret = xbc_snprint_cmdline(new_cmdline, len + 1, root);
> >  	if (ret < 0 || ret > len) {
> >  		pr_err("Failed to print extra kernel cmdline.\n");
> > +		memblock_free_ptr(new_cmdline, len + 1);
> >  		return NULL;
> >  	}
> >  
> 
> Hmm, looking at my patch queue, I noticed that this did not get
> applied. I'm thinking I may have been confused with the other memory
> freeing that was put into the xbc_destroy(), thinking this was part of
> that. But now that I look at this patch in the context of the code, it
> looks like this patch is required, as "new_cmdline" never gets exposed
> on this error.
> 
> Masami, I just want to confirm, that this patch is still relevant, right?

Yes, with other 2 patches in this series ([1/4]-[3/4]), I thought you already
queued it in your tree as you said in [1];

> I'm going to leave this patch out, and just review and accept the first three patches
> in the series.

[1] https://lore.kernel.org/all/20210916164805.32592423@gandalf.local.home/T/#u

So, my next cleanup series [2] (including xbc_destroy_all() -> xbc_exit()) was
based on the [1]'s first 3 patches.

[2] https://lore.kernel.org/all/163187294400.2366983.7393164788107844569.stgit@devnote2/T/#u

If it helps, I can make these series to one series and rebase on top of your
for-next (or ftrace/core) branch.


Thank you,

> 
> Thanks!
> 
> -- Steve
Steven Rostedt Oct. 7, 2021, 1:49 a.m. UTC | #3
On Thu, 7 Oct 2021 10:43:57 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> On Wed, 6 Oct 2021 21:02:16 -0400
> Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> > On Thu, 16 Sep 2021 15:23:12 +0900
> > Masami Hiramatsu <mhiramat@kernel.org> wrote:
> >   
> > > Free unused memblock in a error case to fix memblock leak
> > > in xbc_make_cmdline().
> > > 
> > > Fixes: 51887d03aca1 ("bootconfig: init: Allow admin to use bootconfig for kernel command line")
> > > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> > > ---
> > >  init/main.c |    1 +
> > >  1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/init/main.c b/init/main.c
> > > index 3f7216934441..0b054fff8e92 100644
> > > --- a/init/main.c
> > > +++ b/init/main.c
> > > @@ -382,6 +382,7 @@ static char * __init xbc_make_cmdline(const char *key)
> > >  	ret = xbc_snprint_cmdline(new_cmdline, len + 1, root);
> > >  	if (ret < 0 || ret > len) {
> > >  		pr_err("Failed to print extra kernel cmdline.\n");
> > > +		memblock_free_ptr(new_cmdline, len + 1);
> > >  		return NULL;
> > >  	}
> > >    
> > 
> > Hmm, looking at my patch queue, I noticed that this did not get
> > applied. I'm thinking I may have been confused with the other memory
> > freeing that was put into the xbc_destroy(), thinking this was part of
> > that. But now that I look at this patch in the context of the code, it
> > looks like this patch is required, as "new_cmdline" never gets exposed
> > on this error.
> > 
> > Masami, I just want to confirm, that this patch is still relevant, right?  
> 
> Yes, with other 2 patches in this series ([1/4]-[3/4]), I thought you already
> queued it in your tree as you said in [1];
> 
> > I'm going to leave this patch out, and just review and accept the first three patches
> > in the series.  
> 
> [1] https://lore.kernel.org/all/20210916164805.32592423@gandalf.local.home/T/#u

Bah, doing all my rebases with Linus's "nack" probably caused me to
accidentally drop this one.

> 
> So, my next cleanup series [2] (including xbc_destroy_all() -> xbc_exit()) was
> based on the [1]'s first 3 patches.
> 
> [2] https://lore.kernel.org/all/163187294400.2366983.7393164788107844569.stgit@devnote2/T/#u
> 

I just went through my queue from as far back as August, to pick up
everything that I left behind to worry about Linux Plumbers and Open
Source Summit, and found this set in that queue. I'll be processing all
these patches in the next few days.


> If it helps, I can make these series to one series and rebase on top of your
> for-next (or ftrace/core) branch.

No, this patch should be added to my urgent tree and pushed onto Linus
(and stable).

I'm working on those patches first, then will move on to my for-next
tree.

Thanks,

-- Steve
diff mbox series

Patch

diff --git a/init/main.c b/init/main.c
index 3f7216934441..0b054fff8e92 100644
--- a/init/main.c
+++ b/init/main.c
@@ -382,6 +382,7 @@  static char * __init xbc_make_cmdline(const char *key)
 	ret = xbc_snprint_cmdline(new_cmdline, len + 1, root);
 	if (ret < 0 || ret > len) {
 		pr_err("Failed to print extra kernel cmdline.\n");
+		memblock_free_ptr(new_cmdline, len + 1);
 		return NULL;
 	}