[dpdk-dev] examples/performance-thread: fix out-of-bounds read

Message ID 1505893654-25460-1-git-send-email-slawomirx.mrozowicz@intel.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Slawomir Mrozowicz Sept. 20, 2017, 7:47 a.m. UTC
  Overrunning array schedcore of 128 8-byte elements at element index 128
using index lcore_id.
Fixed by correct check index lcoreid condition and
change type of lcoreid to unsigned.

Coverity issue: 143459
Fixes: 116819b9ed0d ("examples/performance-thread: add lthread subsystem")
Cc: ian.betts@intel.com
Cc: stable@dpdk.org

Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
---
 examples/performance-thread/common/lthread.h       |  2 +-
 examples/performance-thread/common/lthread_sched.c | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)
  

Comments

Michal Jastrzebski Oct. 2, 2017, 2:07 p.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Slawomir
> Mrozowicz
> Sent: Wednesday, September 20, 2017 9:48 AM
> To: Mcnamara, John <john.mcnamara@intel.com>
> Cc: dev@dpdk.org; Mrozowicz, SlawomirX
> <slawomirx.mrozowicz@intel.com>; ian.betts@intel.com; stable@dpdk.org
> Subject: [dpdk-dev] [PATCH] examples/performance-thread: fix out-of-
> bounds read
> 
> Overrunning array schedcore of 128 8-byte elements at element index 128
> using index lcore_id.
> Fixed by correct check index lcoreid condition and
> change type of lcoreid to unsigned.
> 
> Coverity issue: 143459
> Fixes: 116819b9ed0d ("examples/performance-thread: add lthread
> subsystem")
> Cc: ian.betts@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
> ---
>  examples/performance-thread/common/lthread.h       |  2 +-
>  examples/performance-thread/common/lthread_sched.c | 11 +++++++----
>  2 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/examples/performance-thread/common/lthread.h
> b/examples/performance-thread/common/lthread.h
> index 5c2c1a5f0..0cde5919b 100644
> --- a/examples/performance-thread/common/lthread.h
> +++ b/examples/performance-thread/common/lthread.h
> @@ -87,7 +87,7 @@ int _lthread_desched_sleep(struct lthread *lt);
> 
>  void _lthread_free(struct lthread *lt);
> 
> -struct lthread_sched *_lthread_sched_get(int lcore_id);
> +struct lthread_sched *_lthread_sched_get(unsigned int lcore_id);
> 
>  struct lthread_stack *_stack_alloc(void);
> 
> diff --git a/examples/performance-thread/common/lthread_sched.c
> b/examples/performance-thread/common/lthread_sched.c
> index 98291478e..3484387b4 100644
> --- a/examples/performance-thread/common/lthread_sched.c
> +++ b/examples/performance-thread/common/lthread_sched.c
> @@ -562,11 +562,14 @@ void lthread_run(void)
>   * Return the scheduler for this lcore
>   *
>   */
> -struct lthread_sched *_lthread_sched_get(int lcore_id)
> +struct lthread_sched *_lthread_sched_get(unsigned int lcore_id)
>  {
> -	if (lcore_id > LTHREAD_MAX_LCORES)
> -		return NULL;
> -	return schedcore[lcore_id];
> +	struct lthread_sched *res = NULL;
> +
> +	if (lcore_id < LTHREAD_MAX_LCORES)
> +		res = schedcore[lcore_id];
> +
> +	return res;
>  }
> 
>  /*
> --
> 2.11.0

Hi John, 
Here are four fixes for coverity issues in lthread code:
http://dpdk.org/dev/patchwork/patch/28979/
http://dpdk.org/dev/patchwork/patch/28977/
http://dpdk.org/dev/patchwork/patch/28976/
http://dpdk.org/dev/patchwork/patch/28975/

I would like to ask for Your feedback about these fix proposals.
If everything is ok with them, please send acked-by.

Best regards
Michal.
  
Michal Jastrzebski Oct. 11, 2017, 1:55 p.m. UTC | #2
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jastrzebski,
> MichalX K
> Sent: Monday, October 2, 2017 4:08 PM
> To: Mrozowicz, SlawomirX <slawomirx.mrozowicz@intel.com>; Mcnamara,
> John <john.mcnamara@intel.com>
> Cc: dev@dpdk.org; Mrozowicz, SlawomirX
> <slawomirx.mrozowicz@intel.com>; ian.betts@intel.com; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] examples/performance-thread: fix out-of-
> bounds read
> 
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Slawomir
> > Mrozowicz
> > Sent: Wednesday, September 20, 2017 9:48 AM
> > To: Mcnamara, John <john.mcnamara@intel.com>
> > Cc: dev@dpdk.org; Mrozowicz, SlawomirX
> > <slawomirx.mrozowicz@intel.com>; ian.betts@intel.com;
> stable@dpdk.org
> > Subject: [dpdk-dev] [PATCH] examples/performance-thread: fix out-of-
> > bounds read
> >
> > Overrunning array schedcore of 128 8-byte elements at element index
> 128
> > using index lcore_id.
> > Fixed by correct check index lcoreid condition and
> > change type of lcoreid to unsigned.
> >
> > Coverity issue: 143459
> > Fixes: 116819b9ed0d ("examples/performance-thread: add lthread
> > subsystem")
> > Cc: ian.betts@intel.com
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
> > ---
> >  examples/performance-thread/common/lthread.h       |  2 +-
> >  examples/performance-thread/common/lthread_sched.c | 11 +++++++--
> --
> >  2 files changed, 8 insertions(+), 5 deletions(-)
> >
> > diff --git a/examples/performance-thread/common/lthread.h
> > b/examples/performance-thread/common/lthread.h
> > index 5c2c1a5f0..0cde5919b 100644
> > --- a/examples/performance-thread/common/lthread.h
> > +++ b/examples/performance-thread/common/lthread.h
> > @@ -87,7 +87,7 @@ int _lthread_desched_sleep(struct lthread *lt);
> >
> >  void _lthread_free(struct lthread *lt);
> >
> > -struct lthread_sched *_lthread_sched_get(int lcore_id);
> > +struct lthread_sched *_lthread_sched_get(unsigned int lcore_id);
> >
> >  struct lthread_stack *_stack_alloc(void);
> >
> > diff --git a/examples/performance-thread/common/lthread_sched.c
> > b/examples/performance-thread/common/lthread_sched.c
> > index 98291478e..3484387b4 100644
> > --- a/examples/performance-thread/common/lthread_sched.c
> > +++ b/examples/performance-thread/common/lthread_sched.c
> > @@ -562,11 +562,14 @@ void lthread_run(void)
> >   * Return the scheduler for this lcore
> >   *
> >   */
> > -struct lthread_sched *_lthread_sched_get(int lcore_id)
> > +struct lthread_sched *_lthread_sched_get(unsigned int lcore_id)
> >  {
> > -	if (lcore_id > LTHREAD_MAX_LCORES)
> > -		return NULL;
> > -	return schedcore[lcore_id];
> > +	struct lthread_sched *res = NULL;
> > +
> > +	if (lcore_id < LTHREAD_MAX_LCORES)
> > +		res = schedcore[lcore_id];
> > +
> > +	return res;
> >  }
> >
> >  /*
> > --
> > 2.11.0
> 
> Hi John,
> Here are four fixes for coverity issues in lthread code:
> http://dpdk.org/dev/patchwork/patch/28979/
> http://dpdk.org/dev/patchwork/patch/28977/
> http://dpdk.org/dev/patchwork/patch/28976/
> http://dpdk.org/dev/patchwork/patch/28975/
> 
> I would like to ask for Your feedback about these fix proposals.
> If everything is ok with them, please send acked-by.
> 
> Best regards
> Michal.

Acked-by: Michal Jastrzebski <michalx.k.jastrzebski@intel.com>
  
Thomas Monjalon Oct. 13, 2017, 11:14 p.m. UTC | #3
> > > Overrunning array schedcore of 128 8-byte elements at element index
> > 128
> > > using index lcore_id.
> > > Fixed by correct check index lcoreid condition and
> > > change type of lcoreid to unsigned.
> > >
> > > Coverity issue: 143459
> > > Fixes: 116819b9ed0d ("examples/performance-thread: add lthread
> > > subsystem")
> > > Cc: ian.betts@intel.com
> > > Cc: stable@dpdk.org
> > >
> > > Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
> 
> Acked-by: Michal Jastrzebski <michalx.k.jastrzebski@intel.com>

Applied, thanks
  

Patch

diff --git a/examples/performance-thread/common/lthread.h b/examples/performance-thread/common/lthread.h
index 5c2c1a5f0..0cde5919b 100644
--- a/examples/performance-thread/common/lthread.h
+++ b/examples/performance-thread/common/lthread.h
@@ -87,7 +87,7 @@  int _lthread_desched_sleep(struct lthread *lt);
 
 void _lthread_free(struct lthread *lt);
 
-struct lthread_sched *_lthread_sched_get(int lcore_id);
+struct lthread_sched *_lthread_sched_get(unsigned int lcore_id);
 
 struct lthread_stack *_stack_alloc(void);
 
diff --git a/examples/performance-thread/common/lthread_sched.c b/examples/performance-thread/common/lthread_sched.c
index 98291478e..3484387b4 100644
--- a/examples/performance-thread/common/lthread_sched.c
+++ b/examples/performance-thread/common/lthread_sched.c
@@ -562,11 +562,14 @@  void lthread_run(void)
  * Return the scheduler for this lcore
  *
  */
-struct lthread_sched *_lthread_sched_get(int lcore_id)
+struct lthread_sched *_lthread_sched_get(unsigned int lcore_id)
 {
-	if (lcore_id > LTHREAD_MAX_LCORES)
-		return NULL;
-	return schedcore[lcore_id];
+	struct lthread_sched *res = NULL;
+
+	if (lcore_id < LTHREAD_MAX_LCORES)
+		res = schedcore[lcore_id];
+
+	return res;
 }
 
 /*