[v2] net/af_xdp: fix memzone leak in error path

Message ID ab06b0b804b4b27ea8444381ea14a98a3c3231bb.1701778603.git.wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v2] 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/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing success 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

Commit Message

Yunjian Wang Dec. 5, 2023, 12:23 p.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. To fix it move 'umem->mz = mz;' assignment after
'mz == NULL' check.

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

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2: update code suggested by Ferruh Yigit
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Loftus, Ciara Dec. 5, 2023, 1:16 p.m. UTC | #1
> 
> 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. To fix it move 'umem->mz = mz;' assignment after
> 'mz == NULL' check.
> 
> Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
> v2: update code suggested by Ferruh Yigit
> ---
>  drivers/net/af_xdp/rte_eth_af_xdp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c
> b/drivers/net/af_xdp/rte_eth_af_xdp.c
> index 353c8688ec..9f0f751d4a 100644
> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> @@ -1235,6 +1235,7 @@ xsk_umem_info *xdp_umem_configure(struct
> pmd_internals *internals,
>  		goto err;
>  	}
> 
> +	umem->mz = mz;
>  	ret = xsk_umem__create(&umem->umem, mz->addr,
>  			       ETH_AF_XDP_NUM_BUFFERS *
> ETH_AF_XDP_FRAME_SIZE,
>  			       &rxq->fq, &rxq->cq,
> @@ -1244,7 +1245,6 @@ xsk_umem_info *xdp_umem_configure(struct
> pmd_internals *internals,
>  		AF_XDP_LOG(ERR, "Failed to create umem\n");
>  		goto err;
>  	}
> -	umem->mz = mz;
> 
>  	return umem;
> 
> --
> 2.33.0

Thank you for the patch.

Acked-by: Ciara Loftus <ciara.loftus@intel.com>
  
Ferruh Yigit Dec. 6, 2023, 12:29 p.m. UTC | #2
On 12/5/2023 1:16 PM, Loftus, Ciara 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. To fix it move 'umem->mz = mz;' assignment after
>> 'mz == NULL' check.
>>
>> Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
>> ---
>> v2: update code suggested by Ferruh Yigit
>> ---
>>  drivers/net/af_xdp/rte_eth_af_xdp.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c
>> b/drivers/net/af_xdp/rte_eth_af_xdp.c
>> index 353c8688ec..9f0f751d4a 100644
>> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
>> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
>> @@ -1235,6 +1235,7 @@ xsk_umem_info *xdp_umem_configure(struct
>> pmd_internals *internals,
>>  		goto err;
>>  	}
>>
>> +	umem->mz = mz;
>

Moved one line up, to group with mz alloc/check block, while merging.

>>  	ret = xsk_umem__create(&umem->umem, mz->addr,
>>  			       ETH_AF_XDP_NUM_BUFFERS *
>> ETH_AF_XDP_FRAME_SIZE,
>>  			       &rxq->fq, &rxq->cq,
>> @@ -1244,7 +1245,6 @@ xsk_umem_info *xdp_umem_configure(struct
>> pmd_internals *internals,
>>  		AF_XDP_LOG(ERR, "Failed to create umem\n");
>>  		goto err;
>>  	}
>> -	umem->mz = mz;
>>
>>  	return umem;
>>
>> --
>> 2.33.0
> 
> Thank you for the patch.
> 
> Acked-by: Ciara Loftus <ciara.loftus@intel.com>
> 

Acked-by: Ferruh Yigit <ferruh.yigit@amd.com>

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index 353c8688ec..9f0f751d4a 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -1235,6 +1235,7 @@  xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
 		goto err;
 	}
 
+	umem->mz = mz;
 	ret = xsk_umem__create(&umem->umem, mz->addr,
 			       ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
 			       &rxq->fq, &rxq->cq,
@@ -1244,7 +1245,6 @@  xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
 		AF_XDP_LOG(ERR, "Failed to create umem\n");
 		goto err;
 	}
-	umem->mz = mz;
 
 	return umem;