Skip to contentSkip to conversation

vdpa/ifc: fix null pointer dereference

PATCH Superseded Andy Pei 4 participants 8 messages Jun 8, 2022 – Jun 18, 2022 virtio core

lore
Share & tools
lore

Andy Pei

author
#0 lore raw

PATCH 1/1 vdpa/ifc: fix null pointer dereference

Fix null pointer dereference reported in coverity scan.

Coverity issue: 378882

Fixes 8162a4a9 ("vdpa/ifc/base: access correct register for blk device")
---
 drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/vdpa/ifc/base/ifcvf.c +9 -0
index dd475a7..0a9f71a 100644
@@ -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 +
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw

Hi

Quoted 45 lines

-----Original Message-----
From: Pei, Andy <[email protected]>
Sent: Wednesday, June 8, 2022 3:34 PM
To: [email protected]
Cc: Xia, Chenbo <[email protected]>; [email protected]; Wang, Xiao W <[email protected]>; Xu, Rosen <[email protected]>; Xiao, QimaiX <[email protected]>
Subject: [PATCH] vdpa/ifc: fix null pointer dereference

Fix null pointer dereference reported in coverity scan.

Coverity issue: 378882

Fixes 8162a4a9 ("vdpa/ifc/base: access correct register for blk device")
---
 drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/vdpa/ifc/base/ifcvf.c +9 -0
index dd475a7..0a9f71a 100644
@@ -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 +
Quoted 3 lines

IFCVF_LM_RING_STATE_OFFSET +
--
1.8.3.1

BRs,
Xiao

#2 lore raw
In reply to Andy Pei

Hi Andy,

Quoted 9 lines

-----Original Message-----
From: Pei, Andy <[email protected]>
Sent: Wednesday, June 8, 2022 3:34 PM
To: [email protected]
Cc: Xia, Chenbo <[email protected]>; [email protected]; Wang, Xiao W <[email protected]>; Xu, Rosen <[email protected]>; Xiao, QimaiX <[email protected]>
Subject: [PATCH] vdpa/ifc: fix null pointer dereference

Quoted 4 lines

Fix null pointer dereference reported in coverity scan.

Coverity issue: 378882

Fixes 8162a4a9 ("vdpa/ifc/base: access correct register for blk device")

Commit id need to be 12 digits. Also pls leave a blank line between Fixes tag and signed-off

Thanks,
Chenbo

Quoted 35 lines
---
 drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/vdpa/ifc/base/ifcvf.c +9 -0
index dd475a7..0a9f71a 100644
@@ -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 +
--
1.8.3.1

author
#3 lore raw

Hi Chenbo,

Thanks for your reply.
I will fix this in next version.

Quoted 65 lines

-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Wednesday, June 15, 2022 10:04 AM
To: Pei, Andy <[email protected]>; [email protected]
Cc: [email protected]; Wang, Xiao W <[email protected]>; Xu, Rosen <[email protected]>; Xiao, QimaiX <[email protected]>
Subject: RE: [PATCH] vdpa/ifc: fix null pointer dereference

Hi Andy,

Quoted 9 lines

-----Original Message-----
From: Pei, Andy <[email protected]>
Sent: Wednesday, June 8, 2022 3:34 PM
To: [email protected]
Cc: Xia, Chenbo <[email protected]>; [email protected]; Wang, Xiao W <[email protected]>; Xu, Rosen <[email protected]>; Xiao, QimaiX <[email protected]>
Subject: [PATCH] vdpa/ifc: fix null pointer dereference

Quoted 5 lines

Fix null pointer dereference reported in coverity scan.

Coverity issue: 378882

Fixes 8162a4a9 ("vdpa/ifc/base: access correct register for blk

device")

Commit id need to be 12 digits. Also pls leave a blank line between Fixes tag and signed-off

Thanks,
Chenbo

Quoted 34 lines
---
 drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
 1 file changed, 9 insertions(+)
(quoted diff) +0 -0

b/drivers/vdpa/ifc/base/ifcvf.c index dd475a7..0a9f71a 100644

drivers/vdpa/ifc/base/ifcvf.c +4 -0
@@ -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 @@
drivers/vdpa/ifc/base/ifcvf.c +0 -0
 		IFCVF_WRITE_REG16(0, &cfg->queue_enable);
 		IFCVF_WRITE_REG16(IFCVF_MSI_NO_VECTOR, &cfg-
Quoted 1 line

queue_msix_vector);

drivers/vdpa/ifc/base/ifcvf.c +5 -1
+		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 +
--

1.8.3.1

author
#4 lore raw

PATCH v2 1/1 vdpa/ifc: fix null pointer dereference

In reply to Andy Pei

Fix null pointer dereference reported in coverity scan.

Coverity issue: 378882

Fixes 5d75517beffe ("vdpa/ifc/base: access correct register for blk device")
---
 drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/vdpa/ifc/base/ifcvf.c +9 -0
index dd475a7..0a9f71a 100644
@@ -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 +
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#5 lore raw
Quoted 28 lines · Andy Pei

Fix null pointer dereference reported in coverity scan.

Coverity issue: 378882

Fixes 5d75517beffe ("vdpa/ifc/base: access correct register for blk device")
---
  drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/vdpa/ifc/base/ifcvf.c +4 -0
index dd475a7..0a9f71a 100644
@@ -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);

drivers/vdpa/ifc/base/ifcvf.c line 276

Quoted 10 lines
drivers/vdpa/ifc/base/ifcvf.c +5 -0
  		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 +

Thanks,
Maxime

author
#7 lore raw

Hi Maxime,

Thanks for your effort.

Quoted 28 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, June 17, 2022 10:08 PM
To: Pei, Andy <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Wang, Xiao W <[email protected]>; Xu, Rosen <[email protected]>; Xiao, QimaiX <[email protected]>
Subject: Re: [PATCH v2] vdpa/ifc: fix null pointer dereference

Quoted 11 lines · Andy Pei

Fix null pointer dereference reported in coverity scan.

Coverity issue: 378882

Fixes 5d75517beffe ("vdpa/ifc/base: access correct register for blk device")
---
  drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++
  1 file changed, 9 insertions(+)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime