[v1,2/2] raw/ifpga/base: add argument to use untained variable

Message ID 1615969417-17118-3-git-send-email-wei.huang@intel.com (mailing list archive)
State Rejected, archived
Delegated to: Qi Zhang
Headers
Series Fix coverity issues reported in DPDK-26381 |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/travis-robot success travis build: passed
ci/github-robot success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Wei Huang March 17, 2021, 8:23 a.m. UTC
  In fme_nios_spi_init(), passing tainted expression "fme->max10_dev"
to function "fme_get_board_interface" has risk. Add new arguemnt in
function "fme_get_board_interface" to accept untainted variable.

Coverity issue: 367482
Fixes: 96ebfcf8125c ("raw/ifpga/base: add SPI and MAX10 device driver")

Signed-off-by: Wei Huang <wei.huang@intel.com>
---
 drivers/raw/ifpga/base/ifpga_fme.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
  

Comments

Zhang, Tianfei April 1, 2021, 7:48 a.m. UTC | #1
> -----Original Message-----
> From: Huang, Wei <wei.huang@intel.com>
> Sent: 2021年3月17日 16:24
> To: dev@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>
> Cc: stable@dpdk.org; Zhang, Tianfei <tianfei.zhang@intel.com>; Huang, Wei
> <wei.huang@intel.com>
> Subject: [PATCH v1 2/2] raw/ifpga/base: add argument to use untained
> variable
> 
> In fme_nios_spi_init(), passing tainted expression "fme->max10_dev"
> to function "fme_get_board_interface" has risk. Add new arguemnt in
> function "fme_get_board_interface" to accept untainted variable.
> 
> Coverity issue: 367482
> Fixes: 96ebfcf8125c ("raw/ifpga/base: add SPI and MAX10 device driver")
> 
> Signed-off-by: Wei Huang <wei.huang@intel.com>
> ---
>  drivers/raw/ifpga/base/ifpga_fme.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/raw/ifpga/base/ifpga_fme.c
> b/drivers/raw/ifpga/base/ifpga_fme.c
> index a63f90331f..4edb9e09e1 100644
> --- a/drivers/raw/ifpga/base/ifpga_fme.c
> +++ b/drivers/raw/ifpga/base/ifpga_fme.c
> @@ -857,7 +857,8 @@ static int board_type_to_info(u32 type,
>  	return 0;
>  }
> 
> -static int fme_get_board_interface(struct ifpga_fme_hw *fme)
> +static int fme_get_board_interface(struct ifpga_fme_hw *fme,
> +	struct intel_max10_device *max10_dev)
>  {
>  	struct fme_bitstream_id id;
>  	struct ifpga_hw *hw;
> @@ -911,15 +912,15 @@ static int fme_get_board_interface(struct
> ifpga_fme_hw *fme)
>  			fme->board_info.nums_of_fvl,
>  			fme->board_info.ports_per_fvl);
> 
> -	if (max10_sys_read(fme->max10_dev, FPGA_PAGE_INFO, &val))
> +	if (max10_sys_read(max10_dev, FPGA_PAGE_INFO, &val))
>  		return -EINVAL;
>  	fme->board_info.boot_page = val & 0x7;
> 
> -	if (max10_sys_read(fme->max10_dev, MAX10_BUILD_VER, &val))
> +	if (max10_sys_read(max10_dev, MAX10_BUILD_VER, &val))
>  		return -EINVAL;
>  	fme->board_info.max10_version = val;
> 
> -	if (max10_sys_read(fme->max10_dev, NIOS2_FW_VERSION, &val))
> +	if (max10_sys_read(max10_dev, NIOS2_FW_VERSION, &val))
>  		return -EINVAL;
>  	fme->board_info.nios_fw_version = val;
> 
> @@ -1169,7 +1170,7 @@ static int fme_nios_spi_init(struct ifpga_feature
> *feature)
> 
>  	max10->bus = hw->pci_data->bus;
> 
> -	fme_get_board_interface(fme);
> +	fme_get_board_interface(fme, max10);
> 
>  	mgr->sensor_list = &max10->opae_sensor_list;
> 
> @@ -1186,7 +1187,7 @@ static int fme_nios_spi_init(struct ifpga_feature
> *feature)
>  	return ret;
> 
>  spi_fail:
> -	intel_max10_device_remove(fme->max10_dev);
> +	intel_max10_device_remove(max10);
>  release_dev:
>  	altera_spi_release(spi_master);
>  	return -ENODEV;
> --
Acked-by: Tianfei zhang <Tianfei.zhang@intel.com>
  
Xu, Rosen April 1, 2021, 8:48 a.m. UTC | #2
Hi,

-----Original Message-----
From: Huang, Wei <wei.huang@intel.com> 
Sent: Wednesday, March 17, 2021 4:24 PM
To: dev@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
Cc: stable@dpdk.org; Zhang, Tianfei <tianfei.zhang@intel.com>; Huang, Wei <wei.huang@intel.com>
Subject: [PATCH v1 2/2] raw/ifpga/base: add argument to use untained variable

In fme_nios_spi_init(), passing tainted expression "fme->max10_dev"
to function "fme_get_board_interface" has risk. Add new arguemnt in function "fme_get_board_interface" to accept untainted variable.

Coverity issue: 367482
Fixes: 96ebfcf8125c ("raw/ifpga/base: add SPI and MAX10 device driver")

Signed-off-by: Wei Huang <wei.huang@intel.com>
---
 drivers/raw/ifpga/base/ifpga_fme.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/raw/ifpga/base/ifpga_fme.c b/drivers/raw/ifpga/base/ifpga_fme.c
index a63f90331f..4edb9e09e1 100644
--- a/drivers/raw/ifpga/base/ifpga_fme.c
+++ b/drivers/raw/ifpga/base/ifpga_fme.c
@@ -857,7 +857,8 @@ static int board_type_to_info(u32 type,
 	return 0;
 }
 
-static int fme_get_board_interface(struct ifpga_fme_hw *fme)
+static int fme_get_board_interface(struct ifpga_fme_hw *fme,
+	struct intel_max10_device *max10_dev)
 {
 	struct fme_bitstream_id id;
 	struct ifpga_hw *hw;
@@ -911,15 +912,15 @@ static int fme_get_board_interface(struct ifpga_fme_hw *fme)
 			fme->board_info.nums_of_fvl,
 			fme->board_info.ports_per_fvl);
 
-	if (max10_sys_read(fme->max10_dev, FPGA_PAGE_INFO, &val))
+	if (max10_sys_read(max10_dev, FPGA_PAGE_INFO, &val))
 		return -EINVAL;
 	fme->board_info.boot_page = val & 0x7;
 
-	if (max10_sys_read(fme->max10_dev, MAX10_BUILD_VER, &val))
+	if (max10_sys_read(max10_dev, MAX10_BUILD_VER, &val))
 		return -EINVAL;
 	fme->board_info.max10_version = val;
 
-	if (max10_sys_read(fme->max10_dev, NIOS2_FW_VERSION, &val))
+	if (max10_sys_read(max10_dev, NIOS2_FW_VERSION, &val))
 		return -EINVAL;
 	fme->board_info.nios_fw_version = val;
 
@@ -1169,7 +1170,7 @@ static int fme_nios_spi_init(struct ifpga_feature *feature)
 
 	max10->bus = hw->pci_data->bus;
 
-	fme_get_board_interface(fme);
+	fme_get_board_interface(fme, max10);
 
 	mgr->sensor_list = &max10->opae_sensor_list;
 
@@ -1186,7 +1187,7 @@ static int fme_nios_spi_init(struct ifpga_feature *feature)
 	return ret;
 
 spi_fail:
-	intel_max10_device_remove(fme->max10_dev);
+	intel_max10_device_remove(max10);
 release_dev:
 	altera_spi_release(spi_master);
 	return -ENODEV;
--
2.29.2

Acked-by: Rosen Xu <rosen.xu@intel.com>
  

Patch

diff --git a/drivers/raw/ifpga/base/ifpga_fme.c b/drivers/raw/ifpga/base/ifpga_fme.c
index a63f90331f..4edb9e09e1 100644
--- a/drivers/raw/ifpga/base/ifpga_fme.c
+++ b/drivers/raw/ifpga/base/ifpga_fme.c
@@ -857,7 +857,8 @@  static int board_type_to_info(u32 type,
 	return 0;
 }
 
-static int fme_get_board_interface(struct ifpga_fme_hw *fme)
+static int fme_get_board_interface(struct ifpga_fme_hw *fme,
+	struct intel_max10_device *max10_dev)
 {
 	struct fme_bitstream_id id;
 	struct ifpga_hw *hw;
@@ -911,15 +912,15 @@  static int fme_get_board_interface(struct ifpga_fme_hw *fme)
 			fme->board_info.nums_of_fvl,
 			fme->board_info.ports_per_fvl);
 
-	if (max10_sys_read(fme->max10_dev, FPGA_PAGE_INFO, &val))
+	if (max10_sys_read(max10_dev, FPGA_PAGE_INFO, &val))
 		return -EINVAL;
 	fme->board_info.boot_page = val & 0x7;
 
-	if (max10_sys_read(fme->max10_dev, MAX10_BUILD_VER, &val))
+	if (max10_sys_read(max10_dev, MAX10_BUILD_VER, &val))
 		return -EINVAL;
 	fme->board_info.max10_version = val;
 
-	if (max10_sys_read(fme->max10_dev, NIOS2_FW_VERSION, &val))
+	if (max10_sys_read(max10_dev, NIOS2_FW_VERSION, &val))
 		return -EINVAL;
 	fme->board_info.nios_fw_version = val;
 
@@ -1169,7 +1170,7 @@  static int fme_nios_spi_init(struct ifpga_feature *feature)
 
 	max10->bus = hw->pci_data->bus;
 
-	fme_get_board_interface(fme);
+	fme_get_board_interface(fme, max10);
 
 	mgr->sensor_list = &max10->opae_sensor_list;
 
@@ -1186,7 +1187,7 @@  static int fme_nios_spi_init(struct ifpga_feature *feature)
 	return ret;
 
 spi_fail:
-	intel_max10_device_remove(fme->max10_dev);
+	intel_max10_device_remove(max10);
 release_dev:
 	altera_spi_release(spi_master);
 	return -ENODEV;