net/af_xdp: fix memzone leak in error path

Message ID 64117415a68e8c920efdf905f799b26dcbc3f8fb.1701415014.git.wangyunjian@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series net/af_xdp: fix memzone leak in error path |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Yunjian Wang Dec. 1, 2023, 8:03 a.m. UTC
  In xdp_umem_configure() allocated memzone for the 'umem', we should
free it when xsk_umem__create() call fails, otherwise it will lead
to memory zone leak.

Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Ferruh Yigit Dec. 4, 2023, 2:09 p.m. UTC | #1
On 12/1/2023 8:03 AM, Yunjian Wang wrote:
> In xdp_umem_configure() allocated memzone for the 'umem', we should
> free it when xsk_umem__create() call fails, otherwise it will lead
> to memory zone leak.
> 
> Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  drivers/net/af_xdp/rte_eth_af_xdp.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
> index 2a20a6960c..2a1fdafb3c 100644
> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> @@ -1229,6 +1229,7 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
>  
>  	if (ret) {
>  		AF_XDP_LOG(ERR, "Failed to create umem\n");
> +		rte_memzone_free(mz);
>

Doesn't 'xdp_umem_destroy()', in the label 'err', already free it?

>  		goto err;
>  	}
>  	umem->mz = mz;
  
Yunjian Wang Dec. 5, 2023, 1:23 a.m. UTC | #2
> -----Original Message-----
> From: Ferruh Yigit [mailto:ferruh.yigit@amd.com]
> Sent: Monday, December 4, 2023 10:10 PM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: ciara.loftus@intel.com; qi.z.zhang@intel.com; xudingke
> <xudingke@huawei.com>; Lilijun (Jerry) <jerry.lilijun@huawei.com>;
> stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] net/af_xdp: fix memzone leak in error path
> 
> On 12/1/2023 8:03 AM, Yunjian Wang wrote:
> > In xdp_umem_configure() allocated memzone for the 'umem', we should
> > free it when xsk_umem__create() call fails, otherwise it will lead to
> > memory zone leak.
> >
> > Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >  drivers/net/af_xdp/rte_eth_af_xdp.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c
> > b/drivers/net/af_xdp/rte_eth_af_xdp.c
> > index 2a20a6960c..2a1fdafb3c 100644
> > --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> > +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> > @@ -1229,6 +1229,7 @@ xsk_umem_info *xdp_umem_configure(struct
> > pmd_internals *internals,
> >
> >  	if (ret) {
> >  		AF_XDP_LOG(ERR, "Failed to create umem\n");
> > +		rte_memzone_free(mz);
> >
> 
> Doesn't 'xdp_umem_destroy()', in the label 'err', already free it?

In this case, 'mz' is not assigned to 'umem->mz'. Therefore,
the'xdp_umem_destroy()' does not free 'mz'.

Thanks,
Yunjian

> 
> >  		goto err;
> >  	}
> >  	umem->mz = mz;
  
Ferruh Yigit Dec. 5, 2023, 9:41 a.m. UTC | #3
On 12/5/2023 1:23 AM, wangyunjian wrote:
> 
> 
>> -----Original Message-----
>> From: Ferruh Yigit [mailto:ferruh.yigit@amd.com]
>> Sent: Monday, December 4, 2023 10:10 PM
>> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
>> Cc: ciara.loftus@intel.com; qi.z.zhang@intel.com; xudingke
>> <xudingke@huawei.com>; Lilijun (Jerry) <jerry.lilijun@huawei.com>;
>> stable@dpdk.org
>> Subject: Re: [dpdk-dev] [PATCH] net/af_xdp: fix memzone leak in error path
>>
>> On 12/1/2023 8:03 AM, Yunjian Wang wrote:
>>> In xdp_umem_configure() allocated memzone for the 'umem', we should
>>> free it when xsk_umem__create() call fails, otherwise it will lead to
>>> memory zone leak.
>>>
>>> Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
>>> ---
>>>  drivers/net/af_xdp/rte_eth_af_xdp.c | 1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c
>>> b/drivers/net/af_xdp/rte_eth_af_xdp.c
>>> index 2a20a6960c..2a1fdafb3c 100644
>>> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
>>> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
>>> @@ -1229,6 +1229,7 @@ xsk_umem_info *xdp_umem_configure(struct
>>> pmd_internals *internals,
>>>
>>>  	if (ret) {
>>>  		AF_XDP_LOG(ERR, "Failed to create umem\n");
>>> +		rte_memzone_free(mz);
>>>
>>
>> Doesn't 'xdp_umem_destroy()', in the label 'err', already free it?
> 
> In this case, 'mz' is not assigned to 'umem->mz'. Therefore,
> the'xdp_umem_destroy()' does not free 'mz'.
> 
> 

True.
What do you think to move 'umem->mz = mz;' assignment after 'mz == NULL'
check? So related code can be grouped together.
  
Yunjian Wang Dec. 5, 2023, 12:31 p.m. UTC | #4
> -----Original Message-----
> From: Ferruh Yigit [mailto:ferruh.yigit@amd.com]
> Sent: Tuesday, December 5, 2023 5:42 PM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: ciara.loftus@intel.com; qi.z.zhang@intel.com; xudingke
> <xudingke@huawei.com>; Lilijun (Jerry) <jerry.lilijun@huawei.com>;
> stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] net/af_xdp: fix memzone leak in error path
> 
> On 12/5/2023 1:23 AM, wangyunjian wrote:
> >
> >
> >> -----Original Message-----
> >> From: Ferruh Yigit [mailto:ferruh.yigit@amd.com]
> >> Sent: Monday, December 4, 2023 10:10 PM
> >> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> >> Cc: ciara.loftus@intel.com; qi.z.zhang@intel.com; xudingke
> >> <xudingke@huawei.com>; Lilijun (Jerry) <jerry.lilijun@huawei.com>;
> >> stable@dpdk.org
> >> Subject: Re: [dpdk-dev] [PATCH] net/af_xdp: fix memzone leak in error
> >> path
> >>
> >> On 12/1/2023 8:03 AM, Yunjian Wang wrote:
> >>> In xdp_umem_configure() allocated memzone for the 'umem', we should
> >>> free it when xsk_umem__create() call fails, otherwise it will lead
> >>> to memory zone leak.
> >>>
> >>> Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
> >>> Cc: stable@dpdk.org
> >>>
> >>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> >>> ---
> >>>  drivers/net/af_xdp/rte_eth_af_xdp.c | 1 +
> >>>  1 file changed, 1 insertion(+)
> >>>
> >>> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c
> >>> b/drivers/net/af_xdp/rte_eth_af_xdp.c
> >>> index 2a20a6960c..2a1fdafb3c 100644
> >>> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> >>> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> >>> @@ -1229,6 +1229,7 @@ xsk_umem_info *xdp_umem_configure(struct
> >>> pmd_internals *internals,
> >>>
> >>>  	if (ret) {
> >>>  		AF_XDP_LOG(ERR, "Failed to create umem\n");
> >>> +		rte_memzone_free(mz);
> >>>
> >>
> >> Doesn't 'xdp_umem_destroy()', in the label 'err', already free it?
> >
> > In this case, 'mz' is not assigned to 'umem->mz'. Therefore,
> > the'xdp_umem_destroy()' does not free 'mz'.
> >
> >
> 
> True.
> What do you think to move 'umem->mz = mz;' assignment after 'mz == NULL'
> check? So related code can be grouped together.

OK, I update the patch in v2. Thanks.
https://patchwork.dpdk.org/project/dpdk/patch/ab06b0b804b4b27ea8444381ea14a98a3c3231bb.1701778603.git.wangyunjian@huawei.com/
> 
> 
>
  

Patch

diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index 2a20a6960c..2a1fdafb3c 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -1229,6 +1229,7 @@  xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
 
 	if (ret) {
 		AF_XDP_LOG(ERR, "Failed to create umem\n");
+		rte_memzone_free(mz);
 		goto err;
 	}
 	umem->mz = mz;