[dpdk-dev,v3,1/3] mempool: fix segfault when shared mempool handler not linked

Message ID 1490938537-1177-1-git-send-email-shreyansh.jain@nxp.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

Shreyansh Jain March 31, 2017, 5:35 a.m. UTC
  Fixes: 449c49b93a6b ("mempool: support handler operations")

In case the stack or ring mempool handler are compiled as shared
library and not linked in with test binary, segfault is reported.
This is because return value of rte_mempool_set_ops_byname is not
being checked in rte_mempool_ops_alloc.

This patch handles error returned from rte_mempool_set_ops_byname
when a mempool is not found.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
v3:
 * resending as v2 didn't contain version
 * Added this fix after v1 as segault occurs when an unregistered mempool
   handler is requested

 lib/librte_mempool/rte_mempool.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
  

Comments

Shreyansh Jain March 31, 2017, 5:41 a.m. UTC | #1
On Friday 31 March 2017 11:05 AM, Shreyansh Jain wrote:
> Fixes: 449c49b93a6b ("mempool: support handler operations")
>
> In case the stack or ring mempool handler are compiled as shared
> library and not linked in with test binary, segfault is reported.
> This is because return value of rte_mempool_set_ops_byname is not
> being checked in rte_mempool_ops_alloc.
>
> This patch handles error returned from rte_mempool_set_ops_byname
> when a mempool is not found.
>
> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> ---

$ devtools/check-git-log.sh <this patch>
Is it candidate for Cc: stable@dpdk.org backport?
         mempool: fix segfault when shared mempool handler not linked

I am not sure this needs to be in stable. Previous versions never had
an external mempool handler and ring/stack are statically linked in
always.
Though, if a new handler is added (out of tree) over 16.11, and somehow
and application requests for it without linking the library, this
segfault would occur.

Any suggestions?

And just to add to this patch, this segfault is in 'test' binary. It may 
not necessarily be the case for other application if they are
handling the error well.
  
Olivier Matz March 31, 2017, 1:44 p.m. UTC | #2
Hi Shreyansh,

On Fri, 31 Mar 2017 11:11:19 +0530, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> On Friday 31 March 2017 11:05 AM, Shreyansh Jain wrote:
> > Fixes: 449c49b93a6b ("mempool: support handler operations")
> >
> > In case the stack or ring mempool handler are compiled as shared
> > library and not linked in with test binary, segfault is reported.
> > This is because return value of rte_mempool_set_ops_byname is not
> > being checked in rte_mempool_ops_alloc.
> >
> > This patch handles error returned from rte_mempool_set_ops_byname
> > when a mempool is not found.
> >
> > Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> > ---  
> 
> $ devtools/check-git-log.sh <this patch>
> Is it candidate for Cc: stable@dpdk.org backport?
>          mempool: fix segfault when shared mempool handler not linked
> 
> I am not sure this needs to be in stable. Previous versions never had
> an external mempool handler and ring/stack are statically linked in
> always.
> Though, if a new handler is added (out of tree) over 16.11, and somehow
> and application requests for it without linking the library, this
> segfault would occur.
> 
> Any suggestions?
> 
> And just to add to this patch, this segfault is in 'test' binary. It may 
> not necessarily be the case for other application if they are
> handling the error well.
> 

I think it's not needed to backport in stable. As you said, the
crash cannot occur because ring handler is always registered (it's
part of the same mempool lib).


Thanks,
Olivier
  
Olivier Matz March 31, 2017, 1:49 p.m. UTC | #3
On Fri, 31 Mar 2017 11:05:35 +0530, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> Fixes: 449c49b93a6b ("mempool: support handler operations")
> 
> In case the stack or ring mempool handler are compiled as shared
> library and not linked in with test binary, segfault is reported.
> This is because return value of rte_mempool_set_ops_byname is not
> being checked in rte_mempool_ops_alloc.
> 
> This patch handles error returned from rte_mempool_set_ops_byname
> when a mempool is not found.
> 
> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>
  
Thomas Monjalon April 3, 2017, 4:58 p.m. UTC | #4
2017-03-31 15:49, Olivier Matz:
> On Fri, 31 Mar 2017 11:05:35 +0530, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> > Fixes: 449c49b93a6b ("mempool: support handler operations")
> > 
> > In case the stack or ring mempool handler are compiled as shared
> > library and not linked in with test binary, segfault is reported.
> > This is because return value of rte_mempool_set_ops_byname is not
> > being checked in rte_mempool_ops_alloc.
> > 
> > This patch handles error returned from rte_mempool_set_ops_byname
> > when a mempool is not found.
> > 
> > Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> 
> Acked-by: Olivier Matz <olivier.matz@6wind.com>

Series applied, thanks
  

Patch

diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index 40d3afd..ef7d3d1 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -868,6 +868,7 @@  rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
 	rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
 	int socket_id, unsigned flags)
 {
+	int ret;
 	struct rte_mempool *mp;
 
 	mp = rte_mempool_create_empty(name, n, elt_size, cache_size,
@@ -880,13 +881,16 @@  rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
 	 * set the correct index into the table of ops structs.
 	 */
 	if ((flags & MEMPOOL_F_SP_PUT) && (flags & MEMPOOL_F_SC_GET))
-		rte_mempool_set_ops_byname(mp, "ring_sp_sc", NULL);
+		ret = rte_mempool_set_ops_byname(mp, "ring_sp_sc", NULL);
 	else if (flags & MEMPOOL_F_SP_PUT)
-		rte_mempool_set_ops_byname(mp, "ring_sp_mc", NULL);
+		ret = rte_mempool_set_ops_byname(mp, "ring_sp_mc", NULL);
 	else if (flags & MEMPOOL_F_SC_GET)
-		rte_mempool_set_ops_byname(mp, "ring_mp_sc", NULL);
+		ret = rte_mempool_set_ops_byname(mp, "ring_mp_sc", NULL);
 	else
-		rte_mempool_set_ops_byname(mp, "ring_mp_mc", NULL);
+		ret = rte_mempool_set_ops_byname(mp, "ring_mp_mc", NULL);
+
+	if (ret)
+		goto fail;
 
 	/* call the mempool priv initializer */
 	if (mp_init)