eal: fix dereference before null check
diff mbox series

Message ID 1600511670-27576-1-git-send-email-wangyunjian@huawei.com
State Superseded
Delegated to: David Marchand
Headers show
Series
  • eal: fix dereference before null check
Related show

Checks

Context Check Description
ci/travis-robot success Travis build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/checkpatch success coding style OK

Commit Message

wangyunjian Sept. 19, 2020, 10:34 a.m. UTC
From: Yunjian Wang <wangyunjian@huawei.com>

This patch fixes (dereference after null check) coverity issue.
The intr_handle may be a null pointer which led to this issue.

Coverity issue: 357695, 357751
Fixes: 05c4105738d8 ("trace: add interrupt tracepoints")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/librte_eal/freebsd/eal_interrupts.c | 6 ++++--
 lib/librte_eal/linux/eal_interrupts.c   | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

Comments

Ferruh Yigit Oct. 14, 2020, 5:02 p.m. UTC | #1
On 9/19/2020 11:34 AM, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> This patch fixes (dereference after null check) coverity issue.
> The intr_handle may be a null pointer which led to this issue.
> 
> Coverity issue: 357695, 357751
> Fixes: 05c4105738d8 ("trace: add interrupt tracepoints")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>   lib/librte_eal/freebsd/eal_interrupts.c | 6 ++++--
>   lib/librte_eal/linux/eal_interrupts.c   | 6 ++++--
>   2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/librte_eal/freebsd/eal_interrupts.c b/lib/librte_eal/freebsd/eal_interrupts.c
> index 6d53d33c8..028ab457a 100644
> --- a/lib/librte_eal/freebsd/eal_interrupts.c
> +++ b/lib/librte_eal/freebsd/eal_interrupts.c
> @@ -380,7 +380,8 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)
>   	}
>   
>   out:
> -	rte_eal_trace_intr_enable(intr_handle, rc);
> +	if (intr_handle)
> +		rte_eal_trace_intr_enable(intr_handle, rc);
>   	return rc;
>   }
>   
> @@ -418,7 +419,8 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)
>   		break;
>   	}
>   out:
> -	rte_eal_trace_intr_disable(intr_handle, rc);
> +	if (intr_handle)
> +		rte_eal_trace_intr_disable(intr_handle, rc);
>   	return rc;
>   }
>   
> diff --git a/lib/librte_eal/linux/eal_interrupts.c b/lib/librte_eal/linux/eal_interrupts.c
> index 13db5c4e8..e46443873 100644
> --- a/lib/librte_eal/linux/eal_interrupts.c
> +++ b/lib/librte_eal/linux/eal_interrupts.c
> @@ -725,7 +725,8 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)
>   		break;
>   	}
>   out:
> -	rte_eal_trace_intr_enable(intr_handle, rc);
> +	if (intr_handle)
> +		rte_eal_trace_intr_enable(intr_handle, rc);
>   	return rc;

It looks like whole function requires 'intr_handle' to be not NULL, so what do 
you think add following at the very beginning of the function and remove other 
'intr_handle' NULL checks from function:

if (intr_handle == NULL)
	return -1;

>   }
>   
> @@ -852,7 +853,8 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)
>   		break;
>   	}
>   out:
> -	rte_eal_trace_intr_disable(intr_handle, rc);
> +	if (intr_handle)
> +		rte_eal_trace_intr_disable(intr_handle, rc);
>   	return rc;
>   }
>   
>
wangyunjian Oct. 15, 2020, 2:29 a.m. UTC | #2
> -----Original Message-----
> From: Ferruh Yigit [mailto:ferruh.yigit@intel.com]
> Sent: Thursday, October 15, 2020 1:03 AM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: david.marchand@redhat.com; jerinj@marvell.com; hkalra@marvell.com;
> Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke <xudingke@huawei.com>;
> stable@dpdk.org
> Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH] eal: fix dereference before null
> check
> 
> On 9/19/2020 11:34 AM, wangyunjian wrote:
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > This patch fixes (dereference after null check) coverity issue.
> > The intr_handle may be a null pointer which led to this issue.
> >
> > Coverity issue: 357695, 357751
> > Fixes: 05c4105738d8 ("trace: add interrupt tracepoints")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >   lib/librte_eal/freebsd/eal_interrupts.c | 6 ++++--
> >   lib/librte_eal/linux/eal_interrupts.c   | 6 ++++--
> >   2 files changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/librte_eal/freebsd/eal_interrupts.c
> > b/lib/librte_eal/freebsd/eal_interrupts.c
> > index 6d53d33c8..028ab457a 100644
> > --- a/lib/librte_eal/freebsd/eal_interrupts.c
> > +++ b/lib/librte_eal/freebsd/eal_interrupts.c
> > @@ -380,7 +380,8 @@ rte_intr_enable(const struct rte_intr_handle
> *intr_handle)
> >   	}
> >
> >   out:
> > -	rte_eal_trace_intr_enable(intr_handle, rc);
> > +	if (intr_handle)
> > +		rte_eal_trace_intr_enable(intr_handle, rc);
> >   	return rc;
> >   }
> >
> > @@ -418,7 +419,8 @@ rte_intr_disable(const struct rte_intr_handle
> *intr_handle)
> >   		break;
> >   	}
> >   out:
> > -	rte_eal_trace_intr_disable(intr_handle, rc);
> > +	if (intr_handle)
> > +		rte_eal_trace_intr_disable(intr_handle, rc);
> >   	return rc;
> >   }
> >
> > diff --git a/lib/librte_eal/linux/eal_interrupts.c
> > b/lib/librte_eal/linux/eal_interrupts.c
> > index 13db5c4e8..e46443873 100644
> > --- a/lib/librte_eal/linux/eal_interrupts.c
> > +++ b/lib/librte_eal/linux/eal_interrupts.c
> > @@ -725,7 +725,8 @@ rte_intr_enable(const struct rte_intr_handle
> *intr_handle)
> >   		break;
> >   	}
> >   out:
> > -	rte_eal_trace_intr_enable(intr_handle, rc);
> > +	if (intr_handle)
> > +		rte_eal_trace_intr_enable(intr_handle, rc);
> >   	return rc;
> 
> It looks like whole function requires 'intr_handle' to be not NULL, so what do
> you think add following at the very beginning of the function and remove other
> 'intr_handle' NULL checks from function:
> 
> if (intr_handle == NULL)
> 	return -1;

Agree, I will add them in next version.

Thanks,
Yunjian

> 
> >   }
> >
> > @@ -852,7 +853,8 @@ rte_intr_disable(const struct rte_intr_handle
> *intr_handle)
> >   		break;
> >   	}
> >   out:
> > -	rte_eal_trace_intr_disable(intr_handle, rc);
> > +	if (intr_handle)
> > +		rte_eal_trace_intr_disable(intr_handle, rc);
> >   	return rc;
> >   }
> >
> >

Patch
diff mbox series

diff --git a/lib/librte_eal/freebsd/eal_interrupts.c b/lib/librte_eal/freebsd/eal_interrupts.c
index 6d53d33c8..028ab457a 100644
--- a/lib/librte_eal/freebsd/eal_interrupts.c
+++ b/lib/librte_eal/freebsd/eal_interrupts.c
@@ -380,7 +380,8 @@  rte_intr_enable(const struct rte_intr_handle *intr_handle)
 	}
 
 out:
-	rte_eal_trace_intr_enable(intr_handle, rc);
+	if (intr_handle)
+		rte_eal_trace_intr_enable(intr_handle, rc);
 	return rc;
 }
 
@@ -418,7 +419,8 @@  rte_intr_disable(const struct rte_intr_handle *intr_handle)
 		break;
 	}
 out:
-	rte_eal_trace_intr_disable(intr_handle, rc);
+	if (intr_handle)
+		rte_eal_trace_intr_disable(intr_handle, rc);
 	return rc;
 }
 
diff --git a/lib/librte_eal/linux/eal_interrupts.c b/lib/librte_eal/linux/eal_interrupts.c
index 13db5c4e8..e46443873 100644
--- a/lib/librte_eal/linux/eal_interrupts.c
+++ b/lib/librte_eal/linux/eal_interrupts.c
@@ -725,7 +725,8 @@  rte_intr_enable(const struct rte_intr_handle *intr_handle)
 		break;
 	}
 out:
-	rte_eal_trace_intr_enable(intr_handle, rc);
+	if (intr_handle)
+		rte_eal_trace_intr_enable(intr_handle, rc);
 	return rc;
 }
 
@@ -852,7 +853,8 @@  rte_intr_disable(const struct rte_intr_handle *intr_handle)
 		break;
 	}
 out:
-	rte_eal_trace_intr_disable(intr_handle, rc);
+	if (intr_handle)
+		rte_eal_trace_intr_disable(intr_handle, rc);
 	return rc;
 }