[dpdk-dev] [PATCH] ring: fix use after free in ring release

wangyunjian wangyunjian at huawei.com
Wed Apr 19 09:08:59 CEST 2023



> -----Original Message-----
> From: Honnappa Nagarahalli [mailto:Honnappa.Nagarahalli at arm.com]
> Sent: Wednesday, April 19, 2023 7:53 AM
> To: wangyunjian <wangyunjian at huawei.com>; dev at dpdk.org
> Cc: konstantin.v.ananyev at yandex.ru; luyicai <luyicai at huawei.com>;
> stable at dpdk.org; nd <nd at arm.com>; Honnappa Nagarahalli
> <Honnappa.Nagarahalli at arm.com>; nd <nd at arm.com>
> Subject: RE: [dpdk-dev] [PATCH] ring: fix use after free in ring release
> 
> 
> 
> > -----Original Message-----
> > From: Yunjian Wang <wangyunjian at huawei.com>
> > Sent: Monday, April 17, 2023 8:12 AM
> > To: dev at dpdk.org
> > Cc: Honnappa Nagarahalli <Honnappa.Nagarahalli at arm.com>;
> > konstantin.v.ananyev at yandex.ru; luyicai at huawei.com; Yunjian Wang
> > <wangyunjian at huawei.com>; stable at dpdk.org
> > Subject: [dpdk-dev] [PATCH] ring: fix use after free in ring release
> >
> > When using the ring to find out tailq entry, however it had been freed
> > by rte_memzone_free function. This change prevents that from happening.
> I am unable to follow the problem you are describing.
> After the memzone for the ring is released, the contents of the memzone are
> not being used. I understand that the variable 'r' is being used, but that should
> not cause any issues.
> 
> >
> > Fixes: 4e32101f9b01 ("ring: support freeing")
> > Cc: stable at dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian at huawei.com>
> > ---
> >  lib/ring/rte_ring.c | 11 +++++------
> >  1 file changed, 5 insertions(+), 6 deletions(-)
> >
> > diff --git a/lib/ring/rte_ring.c b/lib/ring/rte_ring.c index
> > 8ed455043d..17d2d7f8a8 100644
> > --- a/lib/ring/rte_ring.c
> > +++ b/lib/ring/rte_ring.c
> > @@ -333,11 +333,6 @@ rte_ring_free(struct rte_ring *r)
> >  		return;
> >  	}
> >
> > -	if (rte_memzone_free(r->memzone) != 0) {
> > -		RTE_LOG(ERR, RING, "Cannot free memory\n");
> > -		return;
> > -	}
> Why do we need to free the memzone later?

After the memzone is freed, it is not removed from the 'rte_ring_tailq'.
If rte_ring_lookup is called at this time, it will cause a use-after-free problem.

Thanks,
Yunjian
> 
> > -
> >  	ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list);
> >  	rte_mcfg_tailq_write_lock();
> >
> > @@ -349,7 +344,7 @@ rte_ring_free(struct rte_ring *r)
> >
> >  	if (te == NULL) {
> >  		rte_mcfg_tailq_write_unlock();
> > -		return;
> > +		goto free_memzone;
> >  	}
> >
> >  	TAILQ_REMOVE(ring_list, te, next);
> > @@ -357,6 +352,10 @@ rte_ring_free(struct rte_ring *r)
> >  	rte_mcfg_tailq_write_unlock();
> >
> >  	rte_free(te);
> > +
> > +free_memzone:
> > +	if (rte_memzone_free(r->memzone) != 0)
> > +		RTE_LOG(ERR, RING, "Cannot free memory\n");
> >  }
> >
> >  /* dump the status of the ring on the console */
> > --
> > 2.33.0



More information about the stable mailing list