lib/cmdline: release cl when cmdline exit

Message ID 20210831022844.18057-1-zhihongx.peng@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series lib/cmdline: release cl when cmdline exit |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing fail Testing issues

Commit Message

Peng, ZhihongX Aug. 31, 2021, 2:28 a.m. UTC
  From: Zhihong Peng <zhihongx.peng@intel.com>

Malloc cl in the cmdline_stdin_new function, so release in the
cmdline_stdin_exit function is logical, so that cl will not be
released alone.

Fixes: af75078fece3 (first public release)
Cc: stable@dpdk.org

Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
---
 lib/cmdline/cmdline_socket.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Stephen Hemminger Aug. 31, 2021, 4:59 p.m. UTC | #1
On Tue, 31 Aug 2021 10:28:44 +0800
zhihongx.peng@intel.com wrote:

> From: Zhihong Peng <zhihongx.peng@intel.com>
> 
> Malloc cl in the cmdline_stdin_new function, so release in the
> cmdline_stdin_exit function is logical, so that cl will not be
> released alone.
> 
> Fixes: af75078fece3 (first public release)
> Cc: stable@dpdk.org
> 
> Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
> ---
>  lib/cmdline/cmdline_socket.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/cmdline/cmdline_socket.c b/lib/cmdline/cmdline_socket.c
> index 998e8ade25..ebd5343754 100644
> --- a/lib/cmdline/cmdline_socket.c
> +++ b/lib/cmdline/cmdline_socket.c
> @@ -53,4 +53,5 @@ cmdline_stdin_exit(struct cmdline *cl)
>  		return;
>  
>  	terminal_restore(cl);
> +	cmdline_free(cl);
>  }

How did you find this? valgrind? address-sanitizer?
  
Dmitry Kozlyuk Aug. 31, 2021, 5:52 p.m. UTC | #2
2021-08-31 10:28 (UTC+0800), zhihongx.peng@intel.com:
> From: Zhihong Peng <zhihongx.peng@intel.com>
> 
> Malloc cl in the cmdline_stdin_new function, so release in the
> cmdline_stdin_exit function is logical, so that cl will not be
> released alone.
> 
> Fixes: af75078fece3 (first public release)
> Cc: stable@dpdk.org
> 
> Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
> ---
>  lib/cmdline/cmdline_socket.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/cmdline/cmdline_socket.c b/lib/cmdline/cmdline_socket.c
> index 998e8ade25..ebd5343754 100644
> --- a/lib/cmdline/cmdline_socket.c
> +++ b/lib/cmdline/cmdline_socket.c
> @@ -53,4 +53,5 @@ cmdline_stdin_exit(struct cmdline *cl)
>  		return;
>  
>  	terminal_restore(cl);
> +	cmdline_free(cl);
>  }

Now cmdline_free() may not be called after cmdline_stdin_exit().
User code that does so needs to be changed to avoid double-free.
This behavior change must be documented in the release notes.
I'm not sure it should be backported because of the above.
  
Peng, ZhihongX Sept. 6, 2021, 5:45 a.m. UTC | #3
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Wednesday, September 1, 2021 12:59 AM
> To: Peng, ZhihongX <zhihongx.peng@intel.com>
> Cc: olivier.matz@6wind.com; dev@dpdk.org; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when cmdline exit
> 
> On Tue, 31 Aug 2021 10:28:44 +0800
> zhihongx.peng@intel.com wrote:
> 
> > From: Zhihong Peng <zhihongx.peng@intel.com>
> >
> > Malloc cl in the cmdline_stdin_new function, so release in the
> > cmdline_stdin_exit function is logical, so that cl will not be
> > released alone.
> >
> > Fixes: af75078fece3 (first public release)
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
> > ---
> >  lib/cmdline/cmdline_socket.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/lib/cmdline/cmdline_socket.c
> > b/lib/cmdline/cmdline_socket.c index 998e8ade25..ebd5343754 100644
> > --- a/lib/cmdline/cmdline_socket.c
> > +++ b/lib/cmdline/cmdline_socket.c
> > @@ -53,4 +53,5 @@ cmdline_stdin_exit(struct cmdline *cl)
> >  		return;
> >
> >  	terminal_restore(cl);
> > +	cmdline_free(cl);
> >  }
> 
> How did you find this? valgrind? address-sanitizer?
Use address-sanitizer.
  
Peng, ZhihongX Sept. 6, 2021, 5:51 a.m. UTC | #4
> -----Original Message-----
> From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> Sent: Wednesday, September 1, 2021 1:52 AM
> To: Peng, ZhihongX <zhihongx.peng@intel.com>
> Cc: olivier.matz@6wind.com; dev@dpdk.org; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when cmdline exit
> 
> 2021-08-31 10:28 (UTC+0800), zhihongx.peng@intel.com:
> > From: Zhihong Peng <zhihongx.peng@intel.com>
> >
> > Malloc cl in the cmdline_stdin_new function, so release in the
> > cmdline_stdin_exit function is logical, so that cl will not be
> > released alone.
> >
> > Fixes: af75078fece3 (first public release)
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
> > ---
> >  lib/cmdline/cmdline_socket.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/lib/cmdline/cmdline_socket.c
> > b/lib/cmdline/cmdline_socket.c index 998e8ade25..ebd5343754 100644
> > --- a/lib/cmdline/cmdline_socket.c
> > +++ b/lib/cmdline/cmdline_socket.c
> > @@ -53,4 +53,5 @@ cmdline_stdin_exit(struct cmdline *cl)
> >  		return;
> >
> >  	terminal_restore(cl);
> > +	cmdline_free(cl);
> >  }
> 
> Now cmdline_free() may not be called after cmdline_stdin_exit().
> User code that does so needs to be changed to avoid double-free.
> This behavior change must be documented in the release notes.
> I'm not sure it should be backported because of the above.
Using the asan tool, I found that many dpdk apps did not call cmdline_free, only one app called.
  
Dmitry Kozlyuk Sept. 6, 2021, 7:33 a.m. UTC | #5
2021-09-06 05:51 (UTC+0000), Peng, ZhihongX:
> > -----Original Message-----
> > From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > Sent: Wednesday, September 1, 2021 1:52 AM
> > To: Peng, ZhihongX <zhihongx.peng@intel.com>
> > Cc: olivier.matz@6wind.com; dev@dpdk.org; stable@dpdk.org
> > Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when cmdline exit
> > 
> > 2021-08-31 10:28 (UTC+0800), zhihongx.peng@intel.com:  
> > > From: Zhihong Peng <zhihongx.peng@intel.com>
> > >
> > > Malloc cl in the cmdline_stdin_new function, so release in the
> > > cmdline_stdin_exit function is logical, so that cl will not be
> > > released alone.
> > >
> > > Fixes: af75078fece3 (first public release)
> > > Cc: stable@dpdk.org
> > >
> > > Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
> > > ---
> > >  lib/cmdline/cmdline_socket.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/lib/cmdline/cmdline_socket.c
> > > b/lib/cmdline/cmdline_socket.c index 998e8ade25..ebd5343754 100644
> > > --- a/lib/cmdline/cmdline_socket.c
> > > +++ b/lib/cmdline/cmdline_socket.c
> > > @@ -53,4 +53,5 @@ cmdline_stdin_exit(struct cmdline *cl)
> > >  		return;
> > >
> > >  	terminal_restore(cl);
> > > +	cmdline_free(cl);
> > >  }  
> > 
> > Now cmdline_free() may not be called after cmdline_stdin_exit().
> > User code that does so needs to be changed to avoid double-free.
> > This behavior change must be documented in the release notes.
> > I'm not sure it should be backported because of the above.  
> Using the asan tool, I found that many dpdk apps did not call cmdline_free, only one app called.

I mean external programs that use DPDK, not DPDK bundled apps only.
If some of them use a stable DPDK branch and the change is backported,
a double-free will be introduced by upgrading DPDK to a minor version.
Users of current DPDK version that call cmdline_free() after
cmdline_stdin_exit() will have to upgrade their code,
release notes are the place to inform them about this need.
The patch itself is good and now it is the right time for it.
  
Peng, ZhihongX Sept. 30, 2021, 6:53 a.m. UTC | #6
> -----Original Message-----
> From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> Sent: Monday, September 6, 2021 3:34 PM
> To: Peng, ZhihongX <zhihongx.peng@intel.com>
> Cc: olivier.matz@6wind.com; dev@dpdk.org; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when cmdline exit
> 
> 2021-09-06 05:51 (UTC+0000), Peng, ZhihongX:
> > > -----Original Message-----
> > > From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > > Sent: Wednesday, September 1, 2021 1:52 AM
> > > To: Peng, ZhihongX <zhihongx.peng@intel.com>
> > > Cc: olivier.matz@6wind.com; dev@dpdk.org; stable@dpdk.org
> > > Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when cmdline
> > > exit
> > >
> > > 2021-08-31 10:28 (UTC+0800), zhihongx.peng@intel.com:
> > > > From: Zhihong Peng <zhihongx.peng@intel.com>
> > > >
> > > > Malloc cl in the cmdline_stdin_new function, so release in the
> > > > cmdline_stdin_exit function is logical, so that cl will not be
> > > > released alone.
> > > >
> > > > Fixes: af75078fece3 (first public release)
> > > > Cc: stable@dpdk.org
> > > >
> > > > Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
> > > > ---
> > > >  lib/cmdline/cmdline_socket.c | 1 +
> > > >  1 file changed, 1 insertion(+)
> > > >
> > > > diff --git a/lib/cmdline/cmdline_socket.c
> > > > b/lib/cmdline/cmdline_socket.c index 998e8ade25..ebd5343754 100644
> > > > --- a/lib/cmdline/cmdline_socket.c
> > > > +++ b/lib/cmdline/cmdline_socket.c
> > > > @@ -53,4 +53,5 @@ cmdline_stdin_exit(struct cmdline *cl)
> > > >  		return;
> > > >
> > > >  	terminal_restore(cl);
> > > > +	cmdline_free(cl);
> > > >  }
> > >
> > > Now cmdline_free() may not be called after cmdline_stdin_exit().
> > > User code that does so needs to be changed to avoid double-free.
> > > This behavior change must be documented in the release notes.
> > > I'm not sure it should be backported because of the above.
> > Using the asan tool, I found that many dpdk apps did not call cmdline_free,
> only one app called.
> 
> I mean external programs that use DPDK, not DPDK bundled apps only.
> If some of them use a stable DPDK branch and the change is backported, a
> double-free will be introduced by upgrading DPDK to a minor version.
> Users of current DPDK version that call cmdline_free() after
> cmdline_stdin_exit() will have to upgrade their code, release notes are the
> place to inform them about this need.
> The patch itself is good and now it is the right time for it.

Can you give me an ack, I have submitted v2:
http://patches.dpdk.org/project/dpdk/patch/20210917021502.502560-1-zhihongx.peng@intel.com/
  
Dmitry Kozlyuk Sept. 30, 2021, 7:44 a.m. UTC | #7
2021-09-30 06:53 (UTC+0000), Peng, ZhihongX:
> > -----Original Message-----
> > From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > Sent: Monday, September 6, 2021 3:34 PM
> > To: Peng, ZhihongX <zhihongx.peng@intel.com>
> > Cc: olivier.matz@6wind.com; dev@dpdk.org; stable@dpdk.org
> > Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when cmdline exit
> > 
> > 2021-09-06 05:51 (UTC+0000), Peng, ZhihongX:  
> > > > -----Original Message-----
> > > > From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > > > Sent: Wednesday, September 1, 2021 1:52 AM
> > > > To: Peng, ZhihongX <zhihongx.peng@intel.com>
> > > > Cc: olivier.matz@6wind.com; dev@dpdk.org; stable@dpdk.org
> > > > Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when cmdline
> > > > exit
> > > >
> > > > 2021-08-31 10:28 (UTC+0800), zhihongx.peng@intel.com:  
> > > > > From: Zhihong Peng <zhihongx.peng@intel.com>
> > > > >
> > > > > Malloc cl in the cmdline_stdin_new function, so release in the
> > > > > cmdline_stdin_exit function is logical, so that cl will not be
> > > > > released alone.
> > > > >
> > > > > Fixes: af75078fece3 (first public release)
> > > > > Cc: stable@dpdk.org
> > > > >
> > > > > Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
> > > > > ---
> > > > >  lib/cmdline/cmdline_socket.c | 1 +
> > > > >  1 file changed, 1 insertion(+)
> > > > >
> > > > > diff --git a/lib/cmdline/cmdline_socket.c
> > > > > b/lib/cmdline/cmdline_socket.c index 998e8ade25..ebd5343754 100644
> > > > > --- a/lib/cmdline/cmdline_socket.c
> > > > > +++ b/lib/cmdline/cmdline_socket.c
> > > > > @@ -53,4 +53,5 @@ cmdline_stdin_exit(struct cmdline *cl)
> > > > >  		return;
> > > > >
> > > > >  	terminal_restore(cl);
> > > > > +	cmdline_free(cl);
> > > > >  }  
> > > >
> > > > Now cmdline_free() may not be called after cmdline_stdin_exit().
> > > > User code that does so needs to be changed to avoid double-free.
> > > > This behavior change must be documented in the release notes.
> > > > I'm not sure it should be backported because of the above.  
> > > Using the asan tool, I found that many dpdk apps did not call cmdline_free,  
> > only one app called.
> > 
> > I mean external programs that use DPDK, not DPDK bundled apps only.
> > If some of them use a stable DPDK branch and the change is backported, a
> > double-free will be introduced by upgrading DPDK to a minor version.
> > Users of current DPDK version that call cmdline_free() after
> > cmdline_stdin_exit() will have to upgrade their code, release notes are the
> > place to inform them about this need.
> > The patch itself is good and now it is the right time for it.  
> 
> Can you give me an ack, I have submitted v2:
> http://patches.dpdk.org/project/dpdk/patch/20210917021502.502560-1-zhihongx.peng@intel.com/

Hi Zhihong,
v2 doesn't address my concerns above.
Do you have any objections?
  
Peng, ZhihongX Oct. 8, 2021, 6:55 a.m. UTC | #8
> -----Original Message-----
> From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> Sent: Thursday, September 30, 2021 3:44 PM
> To: Peng, ZhihongX <zhihongx.peng@intel.com>; olivier.matz@6wind.com
> Cc: dev@dpdk.org; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when cmdline exit
> 
> 2021-09-30 06:53 (UTC+0000), Peng, ZhihongX:
> > > -----Original Message-----
> > > From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > > Sent: Monday, September 6, 2021 3:34 PM
> > > To: Peng, ZhihongX <zhihongx.peng@intel.com>
> > > Cc: olivier.matz@6wind.com; dev@dpdk.org; stable@dpdk.org
> > > Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when cmdline
> > > exit
> > >
> > > 2021-09-06 05:51 (UTC+0000), Peng, ZhihongX:
> > > > > -----Original Message-----
> > > > > From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > > > > Sent: Wednesday, September 1, 2021 1:52 AM
> > > > > To: Peng, ZhihongX <zhihongx.peng@intel.com>
> > > > > Cc: olivier.matz@6wind.com; dev@dpdk.org; stable@dpdk.org
> > > > > Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: release cl when
> > > > > cmdline exit
> > > > >
> > > > > 2021-08-31 10:28 (UTC+0800), zhihongx.peng@intel.com:
> > > > > > From: Zhihong Peng <zhihongx.peng@intel.com>
> > > > > >
> > > > > > Malloc cl in the cmdline_stdin_new function, so release in the
> > > > > > cmdline_stdin_exit function is logical, so that cl will not be
> > > > > > released alone.
> > > > > >
> > > > > > Fixes: af75078fece3 (first public release)
> > > > > > Cc: stable@dpdk.org
> > > > > >
> > > > > > Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
> > > > > > ---
> > > > > >  lib/cmdline/cmdline_socket.c | 1 +
> > > > > >  1 file changed, 1 insertion(+)
> > > > > >
> > > > > > diff --git a/lib/cmdline/cmdline_socket.c
> > > > > > b/lib/cmdline/cmdline_socket.c index 998e8ade25..ebd5343754
> > > > > > 100644
> > > > > > --- a/lib/cmdline/cmdline_socket.c
> > > > > > +++ b/lib/cmdline/cmdline_socket.c
> > > > > > @@ -53,4 +53,5 @@ cmdline_stdin_exit(struct cmdline *cl)
> > > > > >  		return;
> > > > > >
> > > > > >  	terminal_restore(cl);
> > > > > > +	cmdline_free(cl);
> > > > > >  }
> > > > >
> > > > > Now cmdline_free() may not be called after cmdline_stdin_exit().
> > > > > User code that does so needs to be changed to avoid double-free.
> > > > > This behavior change must be documented in the release notes.
> > > > > I'm not sure it should be backported because of the above.
> > > > Using the asan tool, I found that many dpdk apps did not call
> > > > cmdline_free,
> > > only one app called.
> > >
> > > I mean external programs that use DPDK, not DPDK bundled apps only.
> > > If some of them use a stable DPDK branch and the change is
> > > backported, a double-free will be introduced by upgrading DPDK to a
> minor version.
> > > Users of current DPDK version that call cmdline_free() after
> > > cmdline_stdin_exit() will have to upgrade their code, release notes
> > > are the place to inform them about this need.
> > > The patch itself is good and now it is the right time for it.
> >
> > Can you give me an ack, I have submitted v2:
> > http://patches.dpdk.org/project/dpdk/patch/20210917021502.502560-1-
> zhi
> > hongx.peng@intel.com/
> 
> Hi Zhihong,
> v2 doesn't address my concerns above.
> Do you have any objections?

I got it wrong, I have submitted the v3 version and added the rel_notes document.
  

Patch

diff --git a/lib/cmdline/cmdline_socket.c b/lib/cmdline/cmdline_socket.c
index 998e8ade25..ebd5343754 100644
--- a/lib/cmdline/cmdline_socket.c
+++ b/lib/cmdline/cmdline_socket.c
@@ -53,4 +53,5 @@  cmdline_stdin_exit(struct cmdline *cl)
 		return;
 
 	terminal_restore(cl);
+	cmdline_free(cl);
 }