[v2] vdpa/ifc: fix null pointer dereference

Message ID 1655274214-164117-1-git-send-email-andy.pei@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series [v2] vdpa/ifc: fix null pointer dereference |

Checks

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

Commit Message

Pei, Andy June 15, 2022, 6:23 a.m. UTC
  Fix null pointer dereference reported in coverity scan.

Coverity issue: 378882
Fixes: 5d75517beffe ("vdpa/ifc/base: access correct register for blk device")

Signed-off-by: Andy Pei <andy.pei@intel.com>
Acked-by: Xiao Wang <xiao.w.wang@intel.com>
---
 drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Comments

Maxime Coquelin June 17, 2022, 12:40 p.m. UTC | #1
On 6/15/22 08:23, Andy Pei wrote:
> Fix null pointer dereference reported in coverity scan.
> 
> Coverity issue: 378882
> Fixes: 5d75517beffe ("vdpa/ifc/base: access correct register for blk device")
> 
> Signed-off-by: Andy Pei <andy.pei@intel.com>
> Acked-by: Xiao Wang <xiao.w.wang@intel.com>
> ---
>   drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/vdpa/ifc/base/ifcvf.c b/drivers/vdpa/ifc/base/ifcvf.c
> index dd475a7..0a9f71a 100644
> --- a/drivers/vdpa/ifc/base/ifcvf.c
> +++ b/drivers/vdpa/ifc/base/ifcvf.c
> @@ -255,6 +255,10 @@
>   	u32 ring_state;
>   
>   	cfg = hw->common_cfg;
> +	if (!cfg) {
> +		DEBUGOUT("common_cfg in HW is NULL.\n");
> +		return;
> +	}
>   
>   	IFCVF_WRITE_REG16(IFCVF_MSI_NO_VECTOR, &cfg->msix_config);
>   	for (i = 0; i < hw->nr_vring; i++) {
> @@ -262,6 +266,11 @@
>   		IFCVF_WRITE_REG16(0, &cfg->queue_enable);
>   		IFCVF_WRITE_REG16(IFCVF_MSI_NO_VECTOR, &cfg->queue_msix_vector);
>   
> +		if (!hw->lm_cfg) {
> +			DEBUGOUT("live migration cfg in HW is NULL.\n");
> +			continue;
> +		}
> +
>   		if (hw->device_type == IFCVF_BLK)
>   			ring_state = *(u32 *)(hw->lm_cfg +
>   					IFCVF_LM_RING_STATE_OFFSET +

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
Maxime Coquelin June 17, 2022, 2:07 p.m. UTC | #2
On 6/15/22 08:23, Andy Pei wrote:
> Fix null pointer dereference reported in coverity scan.
> 
> Coverity issue: 378882
> Fixes: 5d75517beffe ("vdpa/ifc/base: access correct register for blk device")
> 
> Signed-off-by: Andy Pei <andy.pei@intel.com>
> Acked-by: Xiao Wang <xiao.w.wang@intel.com>
> ---
>   drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 

Applied to dpdk-next-virtio/main.

Thanks,
Maxime
  
Pei, Andy June 18, 2022, 9:04 a.m. UTC | #3
Hi Maxime,

Thanks for your effort.

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Friday, June 17, 2022 10:08 PM
> To: Pei, Andy <andy.pei@intel.com>; dev@dpdk.org
> Cc: Xia, Chenbo <chenbo.xia@intel.com>; Wang, Xiao W
> <xiao.w.wang@intel.com>; Xu, Rosen <rosen.xu@intel.com>; Xiao, QimaiX
> <qimaix.xiao@intel.com>
> Subject: Re: [PATCH v2] vdpa/ifc: fix null pointer dereference
> 
> 
> 
> On 6/15/22 08:23, Andy Pei wrote:
> > Fix null pointer dereference reported in coverity scan.
> >
> > Coverity issue: 378882
> > Fixes: 5d75517beffe ("vdpa/ifc/base: access correct register for blk device")
> >
> > Signed-off-by: Andy Pei <andy.pei@intel.com>
> > Acked-by: Xiao Wang <xiao.w.wang@intel.com>
> > ---
> >   drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
> >   1 file changed, 9 insertions(+)
> >
> 
> Applied to dpdk-next-virtio/main.
> 
> Thanks,
> Maxime
  

Patch

diff --git a/drivers/vdpa/ifc/base/ifcvf.c b/drivers/vdpa/ifc/base/ifcvf.c
index dd475a7..0a9f71a 100644
--- a/drivers/vdpa/ifc/base/ifcvf.c
+++ b/drivers/vdpa/ifc/base/ifcvf.c
@@ -255,6 +255,10 @@ 
 	u32 ring_state;
 
 	cfg = hw->common_cfg;
+	if (!cfg) {
+		DEBUGOUT("common_cfg in HW is NULL.\n");
+		return;
+	}
 
 	IFCVF_WRITE_REG16(IFCVF_MSI_NO_VECTOR, &cfg->msix_config);
 	for (i = 0; i < hw->nr_vring; i++) {
@@ -262,6 +266,11 @@ 
 		IFCVF_WRITE_REG16(0, &cfg->queue_enable);
 		IFCVF_WRITE_REG16(IFCVF_MSI_NO_VECTOR, &cfg->queue_msix_vector);
 
+		if (!hw->lm_cfg) {
+			DEBUGOUT("live migration cfg in HW is NULL.\n");
+			continue;
+		}
+
 		if (hw->device_type == IFCVF_BLK)
 			ring_state = *(u32 *)(hw->lm_cfg +
 					IFCVF_LM_RING_STATE_OFFSET +