[dpdk-dev,v3] net/failsafe: fix probe cleanup

Message ID 1525782013-17527-1-git-send-email-rasland@mellanox.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Raslan Darawsheh May 8, 2018, 12:20 p.m. UTC
  The hot-plug alarm mechanism is responsible to practically execute both
plug in and out operations. It periodically tries to detect missed
sub-devices to be reconfigured and clean the resources of the removed
sub-devices.

The hot-plug alarm is started by the failsafe probe function, and it's
wrongly not stopped if failsafe instance got an error. for example
when starting failsafe with a MAC option, and giving it an invalid MAC
address this will lead to a NULL pointer for the dev private field. Then
when the hotplug alarm is called it will try to access this pointer,
which will lead to a segmentation fault.

Uninstall the hot-plug alarm in case of error in probe function.

Fixes: a46f8d58 ("net/failsafe: add fail-safe PMD")
Cc: stable@dpdk.org

Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>

---
v2 changes:
 Reword the commit log.

v3 changes:
 Reword the commit log.
---
---
 drivers/net/failsafe/failsafe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Matan Azrad May 8, 2018, 12:24 p.m. UTC | #1
From: Raslan Darawshehת Tuesday, May 8, 2018 3:20 PM
> The hot-plug alarm mechanism is responsible to practically execute both plug
> in and out operations. It periodically tries to detect missed sub-devices to be
> reconfigured and clean the resources of the removed sub-devices.
> 
> The hot-plug alarm is started by the failsafe probe function, and it's wrongly
> not stopped if failsafe instance got an error. for example when starting failsafe
> with a MAC option, and giving it an invalid MAC address this will lead to a NULL
> pointer for the dev private field. Then when the hotplug alarm is called it will
> try to access this pointer, which will lead to a segmentation fault.
> 
> Uninstall the hot-plug alarm in case of error in probe function.
> 
> Fixes: a46f8d58 ("net/failsafe: add fail-safe PMD")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
> 
> ---
> v2 changes:
>  Reword the commit log.
> 
> v3 changes:
>  Reword the commit log.
> ---
> ---
>  drivers/net/failsafe/failsafe.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c index
> 5e7a8ba..3a747c2 100644
> --- a/drivers/net/failsafe/failsafe.c
> +++ b/drivers/net/failsafe/failsafe.c
> @@ -226,7 +226,7 @@ fs_eth_dev_create(struct rte_vdev_device *vdev)
>  							       mac);
>  			if (ret) {
>  				ERROR("Failed to set default MAC address");
> -				goto free_args;
> +				goto cancel_alarm;
>  			}
>  		}
>  	} else {
> @@ -260,6 +260,8 @@ fs_eth_dev_create(struct rte_vdev_device *vdev)
>  		.type = RTE_INTR_HANDLE_EXT,
>  	};
>  	return 0;
> +cancel_alarm:
> +	failsafe_hotplug_alarm_cancel(dev);
>  free_args:
>  	failsafe_args_free(dev);
>  free_subs:
> --
> 2.7.4
  
Gaëtan Rivet May 9, 2018, 11:49 a.m. UTC | #2
Hello Raslan,

On Tue, May 08, 2018 at 03:20:13PM +0300, Raslan Darawsheh wrote:
> The hot-plug alarm mechanism is responsible to practically execute both
> plug in and out operations. It periodically tries to detect missed
> sub-devices to be reconfigured and clean the resources of the removed
> sub-devices.
> 
> The hot-plug alarm is started by the failsafe probe function, and it's
> wrongly not stopped if failsafe instance got an error. for example
> when starting failsafe with a MAC option, and giving it an invalid MAC
> address this will lead to a NULL pointer for the dev private field. Then
> when the hotplug alarm is called it will try to access this pointer,
> which will lead to a segmentation fault.
> 
> Uninstall the hot-plug alarm in case of error in probe function.
> 
> Fixes: a46f8d58 ("net/failsafe: add fail-safe PMD")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
> 
> ---
> v2 changes:
>  Reword the commit log.
> 
> v3 changes:
>  Reword the commit log.

Sorry I replied to the v3 instead, my comment on the v2 still stands.
The v2 was not superseded in patchwork and the commit title changed,
making me think it was two different fixes.

> ---
> ---
>  drivers/net/failsafe/failsafe.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c
> index 5e7a8ba..3a747c2 100644
> --- a/drivers/net/failsafe/failsafe.c
> +++ b/drivers/net/failsafe/failsafe.c
> @@ -226,7 +226,7 @@ fs_eth_dev_create(struct rte_vdev_device *vdev)
>  							       mac);
>  			if (ret) {
>  				ERROR("Failed to set default MAC address");
> -				goto free_args;
> +				goto cancel_alarm;
>  			}
>  		}
>  	} else {
> @@ -260,6 +260,8 @@ fs_eth_dev_create(struct rte_vdev_device *vdev)
>  		.type = RTE_INTR_HANDLE_EXT,
>  	};
>  	return 0;
> +cancel_alarm:
> +	failsafe_hotplug_alarm_cancel(dev);
>  free_args:
>  	failsafe_args_free(dev);
>  free_subs:
> -- 
> 2.7.4
>
  

Patch

diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c
index 5e7a8ba..3a747c2 100644
--- a/drivers/net/failsafe/failsafe.c
+++ b/drivers/net/failsafe/failsafe.c
@@ -226,7 +226,7 @@  fs_eth_dev_create(struct rte_vdev_device *vdev)
 							       mac);
 			if (ret) {
 				ERROR("Failed to set default MAC address");
-				goto free_args;
+				goto cancel_alarm;
 			}
 		}
 	} else {
@@ -260,6 +260,8 @@  fs_eth_dev_create(struct rte_vdev_device *vdev)
 		.type = RTE_INTR_HANDLE_EXT,
 	};
 	return 0;
+cancel_alarm:
+	failsafe_hotplug_alarm_cancel(dev);
 free_args:
 	failsafe_args_free(dev);
 free_subs: