[v1] bus/ifpga: fix issue of accessing null address

Message ID 20230316204412.338823-1-wei.huang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v1] bus/ifpga: fix issue of accessing null address |

Checks

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

Commit Message

Wei Huang March 16, 2023, 8:44 p.m. UTC
  In function ifpga_scan_one(), variable 'path' is NULL if device argument
'afu_bts' is not set, subsequent string copy with 'path' would lead to
segmentation fault.

Fixes: 6fa4aa2b3645 ("bus/ifpga: fix forcing optional devargs")
Cc: stable@dpdk.org

Signed-off-by: Wei Huang <wei.huang@intel.com>
---
 drivers/bus/ifpga/ifpga_bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Zhang, Tianfei March 20, 2023, 6:34 a.m. UTC | #1
> -----Original Message-----
> From: Huang, Wei <wei.huang@intel.com>
> Sent: Friday, March 17, 2023 4:44 AM
> To: dev@dpdk.org; thomas@monjalon.net; david.marchand@redhat.com
> Cc: stable@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Tianfei
> <tianfei.zhang@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>; Huang, Wei
> <wei.huang@intel.com>
> Subject: [PATCH v1] bus/ifpga: fix issue of accessing null address
> 
> In function ifpga_scan_one(), variable 'path' is NULL if device argument 'afu_bts' is
> not set, subsequent string copy with 'path' would lead to segmentation fault.
> 
> Fixes: 6fa4aa2b3645 ("bus/ifpga: fix forcing optional devargs")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Wei Huang <wei.huang@intel.com>
> ---
>  drivers/bus/ifpga/ifpga_bus.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c index
> bb943b5..07e316b 100644
> --- a/drivers/bus/ifpga/ifpga_bus.c
> +++ b/drivers/bus/ifpga/ifpga_bus.c
> @@ -135,6 +135,8 @@ struct rte_afu_device *
>  			goto end;
>  		}
>  		afu_pr_conf.pr_enable = 1;
> +		strlcpy(afu_pr_conf.bs_path, path,
> +			sizeof(afu_pr_conf.bs_path));
>  	} else {
>  		afu_pr_conf.pr_enable = 0;
>  	}
> @@ -174,7 +176,6 @@ struct rte_afu_device *
>  		rawdev->dev_ops->dev_start(rawdev))
>  		goto end;
> 
> -	strlcpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
>  	if (rawdev->dev_ops &&
>  		rawdev->dev_ops->firmware_load &&
>  		rawdev->dev_ops->firmware_load(rawdev,
> --
> 1.8.3.1

It looks good for me.
Acked-by: Tianfei Zhang <tianfei.zhang@intel.com>
  
Xu, Rosen March 20, 2023, 6:54 a.m. UTC | #2
Hi,

> -----Original Message-----
> From: Huang, Wei <wei.huang@intel.com>
> Sent: Friday, March 17, 2023 4:44 AM
> To: dev@dpdk.org; thomas@monjalon.net; david.marchand@redhat.com
> Cc: stable@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Tianfei
> <tianfei.zhang@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>; Huang, Wei
> <wei.huang@intel.com>
> Subject: [PATCH v1] bus/ifpga: fix issue of accessing null address
> 
> In function ifpga_scan_one(), variable 'path' is NULL if device argument
> 'afu_bts' is not set, subsequent string copy with 'path' would lead to
> segmentation fault.
> 
> Fixes: 6fa4aa2b3645 ("bus/ifpga: fix forcing optional devargs")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Wei Huang <wei.huang@intel.com>
> ---
>  drivers/bus/ifpga/ifpga_bus.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
> index bb943b5..07e316b 100644
> --- a/drivers/bus/ifpga/ifpga_bus.c
> +++ b/drivers/bus/ifpga/ifpga_bus.c
> @@ -135,6 +135,8 @@ struct rte_afu_device *
>  			goto end;
>  		}
>  		afu_pr_conf.pr_enable = 1;
> +		strlcpy(afu_pr_conf.bs_path, path,
> +			sizeof(afu_pr_conf.bs_path));
>  	} else {
>  		afu_pr_conf.pr_enable = 0;
>  	}
> @@ -174,7 +176,6 @@ struct rte_afu_device *
>  		rawdev->dev_ops->dev_start(rawdev))
>  		goto end;
> 
> -	strlcpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
>  	if (rawdev->dev_ops &&
>  		rawdev->dev_ops->firmware_load &&
>  		rawdev->dev_ops->firmware_load(rawdev,
> --
> 1.8.3.1

Acked-by: Rosen Xu <rosen.xu@intel.com>
  
Thomas Monjalon March 20, 2023, 3:56 p.m. UTC | #3
> > In function ifpga_scan_one(), variable 'path' is NULL if device argument 'afu_bts' is
> > not set, subsequent string copy with 'path' would lead to segmentation fault.
> > 
> > Fixes: 6fa4aa2b3645 ("bus/ifpga: fix forcing optional devargs")
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Wei Huang <wei.huang@intel.com>
> 
> It looks good for me.
> Acked-by: Tianfei Zhang <tianfei.zhang@intel.com>

Applied, thanks.
  

Patch

diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index bb943b5..07e316b 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -135,6 +135,8 @@  struct rte_afu_device *
 			goto end;
 		}
 		afu_pr_conf.pr_enable = 1;
+		strlcpy(afu_pr_conf.bs_path, path,
+			sizeof(afu_pr_conf.bs_path));
 	} else {
 		afu_pr_conf.pr_enable = 0;
 	}
@@ -174,7 +176,6 @@  struct rte_afu_device *
 		rawdev->dev_ops->dev_start(rawdev))
 		goto end;
 
-	strlcpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
 	if (rawdev->dev_ops &&
 		rawdev->dev_ops->firmware_load &&
 		rawdev->dev_ops->firmware_load(rawdev,