[v3,02/14] bus/fslmc: fix null pointer dereference

Message ID 20200626132712.1437673-3-maxime.coquelin@redhat.com (mailing list archive)
State Superseded, archived
Headers
Series vDPA API and framework rework |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Maxime Coquelin June 26, 2020, 1:27 p.m. UTC
  This patches fixes a null pointer derefencing that happens
when the device string passed to the iterator is NULL. This
situation can happen when iterating on a class type.
For example:

RTE_DEV_FOREACH(dev, "class=eth", &dev_iter) {
    ...
}

Fixes: e67a61614d0b ("bus/fslmc: support device iteration")
Cc: stable@dpdk.org
Cc: shreyansh.jain@nxp.com

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/bus/fslmc/fslmc_bus.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Adrian Moreno June 26, 2020, 1:48 p.m. UTC | #1
On 6/26/20 3:27 PM, Maxime Coquelin wrote:
> This patches fixes a null pointer derefencing that happens
> when the device string passed to the iterator is NULL. This
> situation can happen when iterating on a class type.
> For example:
> 
> RTE_DEV_FOREACH(dev, "class=eth", &dev_iter) {
>     ...
> }
> 
> Fixes: e67a61614d0b ("bus/fslmc: support device iteration")
> Cc: stable@dpdk.org
> Cc: shreyansh.jain@nxp.com
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  drivers/bus/fslmc/fslmc_bus.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
> index afbd82e8db..ac46eb4fe8 100644
> --- a/drivers/bus/fslmc/fslmc_bus.c
> +++ b/drivers/bus/fslmc/fslmc_bus.c
> @@ -603,6 +603,11 @@ fslmc_bus_dev_iterate(const void *start, const char *str,
>  	struct rte_dpaa2_device *dev;
>  	char *dup, *dev_name = NULL;
>  
> +	if (str == NULL) {
> +		DPAA2_BUS_DEBUG("No device string");
> +		return NULL;
> +	}
> +
>  	/* Expectation is that device would be name=device_name */
>  	if (strncmp(str, "name=", 5) != 0) {
>  		DPAA2_BUS_DEBUG("Invalid device string (%s)\n", str);
> 
Acked-by: Adrián Moreno <amorenoz@redhat.com>
  

Patch

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index afbd82e8db..ac46eb4fe8 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -603,6 +603,11 @@  fslmc_bus_dev_iterate(const void *start, const char *str,
 	struct rte_dpaa2_device *dev;
 	char *dup, *dev_name = NULL;
 
+	if (str == NULL) {
+		DPAA2_BUS_DEBUG("No device string");
+		return NULL;
+	}
+
 	/* Expectation is that device would be name=device_name */
 	if (strncmp(str, "name=", 5) != 0) {
 		DPAA2_BUS_DEBUG("Invalid device string (%s)\n", str);