[2/2] examples/vm_power_manager: use safe version of list iterator

Message ID 20220601105455.166505-2-hamza.khan@intel.com (mailing list archive)
State Superseded, archived
Headers
Series [1/2] common: add safe version of foreach-list to Linux |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Khan, Hamza June 1, 2022, 10:54 a.m. UTC
  Currently, when vm_power_manager exits, we are using a LIST_FOREACH
macro to iterate over VM info structures while freeing them. This
leads to use-after-free error. To address this, use the newly added
LIST_FOREACH_SAFE macro.

Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host")
Cc: alan.carew@intel.com
Cc: stable@dpdk.org

Signed-off-by: Hamza Khan <hamza.khan@intel.com>
---
 examples/vm_power_manager/channel_manager.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Hunt, David July 4, 2022, 12:31 p.m. UTC | #1
On 01/06/2022 11:54, Hamza Khan wrote:
> Currently, when vm_power_manager exits, we are using a LIST_FOREACH
> macro to iterate over VM info structures while freeing them. This
> leads to use-after-free error. To address this, use the newly added
> LIST_FOREACH_SAFE macro.
>
> Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host")
> Cc: alan.carew@intel.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Hamza Khan <hamza.khan@intel.com>
> ---
>   examples/vm_power_manager/channel_manager.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
> index 838465ab4b..bc95cec8d6 100644
> --- a/examples/vm_power_manager/channel_manager.c
> +++ b/examples/vm_power_manager/channel_manager.c
> @@ -1005,9 +1005,9 @@ channel_manager_exit(void)
>   {
>   	unsigned i;
>   	char mask[RTE_MAX_LCORE];
> -	struct virtual_machine_info *vm_info;
> +	struct virtual_machine_info *vm_info, *tmp;
>   
> -	LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
> +	LIST_FOREACH_SAFE(vm_info, &vm_list_head, vms_info, tmp) {
>   
>   		rte_spinlock_lock(&(vm_info->config_spinlock));
>   


Acked-by: David Hunt <david.hunt@intel.com>
  
Weiyuan Li July 5, 2022, 2:38 a.m. UTC | #2
> -----Original Message-----
> From: Hunt, David <david.hunt@intel.com>
> Sent: Monday, July 4, 2022 8:32 PM
> To: Khan, Hamza <hamza.khan@intel.com>; Carew, Alan
> <alan.carew@intel.com>; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>
> Cc: dev@dpdk.org; stable@dpdk.org
> Subject: Re: [PATCH 2/2] examples/vm_power_manager: use safe version of
> list iterator
> 
> 
> On 01/06/2022 11:54, Hamza Khan wrote:
> > Currently, when vm_power_manager exits, we are using a LIST_FOREACH
> > macro to iterate over VM info structures while freeing them. This
> > leads to use-after-free error. To address this, use the newly added
> > LIST_FOREACH_SAFE macro.
> >
> > Fixes: e8ae9b662506 ("examples/vm_power: channel manager and
> monitor
> > in host")
> > Cc: alan.carew@intel.com
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Hamza Khan <hamza.khan@intel.com>
> > ---
> >   examples/vm_power_manager/channel_manager.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/examples/vm_power_manager/channel_manager.c
> > b/examples/vm_power_manager/channel_manager.c
> > index 838465ab4b..bc95cec8d6 100644
> > --- a/examples/vm_power_manager/channel_manager.c
> > +++ b/examples/vm_power_manager/channel_manager.c
> > @@ -1005,9 +1005,9 @@ channel_manager_exit(void)
> >   {
> >   	unsigned i;
> >   	char mask[RTE_MAX_LCORE];
> > -	struct virtual_machine_info *vm_info;
> > +	struct virtual_machine_info *vm_info, *tmp;
> >
> > -	LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
> > +	LIST_FOREACH_SAFE(vm_info, &vm_list_head, vms_info, tmp) {
> >
> >   		rte_spinlock_lock(&(vm_info->config_spinlock));
> >
> 
> 
> Acked-by: David Hunt <david.hunt@intel.com>
> 

Tested-by: Weiyuan Li <weiyuanx.li@intel.com>
  

Patch

diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 838465ab4b..bc95cec8d6 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -1005,9 +1005,9 @@  channel_manager_exit(void)
 {
 	unsigned i;
 	char mask[RTE_MAX_LCORE];
-	struct virtual_machine_info *vm_info;
+	struct virtual_machine_info *vm_info, *tmp;
 
-	LIST_FOREACH(vm_info, &vm_list_head, vms_info) {
+	LIST_FOREACH_SAFE(vm_info, &vm_list_head, vms_info, tmp) {
 
 		rte_spinlock_lock(&(vm_info->config_spinlock));