Skip to contentSkip to conversation

bugfix for raw ntb

PATCH In review Min Hu (Connor) 4 participants 12 messages Apr 21, 2021 – May 5, 2021

lore
Share & tools
lore
#0 lore raw

cover bugfix for raw ntb

This patchset contains two bugfix for raw ntb.

Chengwen Feng (2):
raw/ntb: check spad user index
raw/ntb: check malloc result

 drivers/raw/ntb/ntb.c          | 13 +++++++++++++
 drivers/raw/ntb/ntb_hw_intel.c |  5 +++++
 2 files changed, 18 insertions(+)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 raw/ntb: check spad user index

From: Chengwen Feng <[email protected]>

This patch adds checking spad user index validity when set or get attr.

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")
---
 drivers/raw/ntb/ntb.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/raw/ntb/ntb.c +8 -0
index 6dd213e..0f0e3f2 100644
@@ -1080,6 +1080,10 @@ ntb_attr_set(struct rte_rawdev *dev, const char *attr_name,
 		if (hw->ntb_ops->spad_write == NULL)
 			return -ENOTSUP;
 		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Invalid attribute (%s)", attr_name);
+			return -EINVAL;
+		}
 		(*hw->ntb_ops->spad_write)(dev, hw->spad_user_list[index],
 					   1, attr_value);
 		NTB_LOG(DEBUG, "Set attribute (%s) Value (%" PRIu64 ")",
@@ -1174,6 +1178,10 @@ ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,
 		if (hw->ntb_ops->spad_read == NULL)
 			return -ENOTSUP;
 		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Attribute (%s) out of range", attr_name);
+			return -EINVAL;
+		}
 		*attr_value = (*hw->ntb_ops->spad_read)(dev,
 				hw->spad_user_list[index], 0);
 		NTB_LOG(DEBUG, "Attribute (%s) Value (%" PRIu64 ")",
Signature · 1 line
2.7.4
#10 lore raw

PATCH 2/2 raw/ntb: check malloc result

In reply to Min Hu (Connor)

From: Chengwen Feng <[email protected]>

This patch adds checking for rte_zmalloc() result when init intel ntb device, also fix the same bug when start ntb device.

Fixes 034c328eb025 ("raw/ntb: support Intel NTB")
Fixes c39d1e082a4b ("raw/ntb: setup queues")
---
 drivers/raw/ntb/ntb.c          | 5 +++++
 drivers/raw/ntb/ntb_hw_intel.c | 5 +++++
 2 files changed, 10 insertions(+)
drivers/raw/ntb/ntb.c +5 -0
index 0f0e3f2..6703bb5 100644
@@ -923,6 +923,11 @@ ntb_dev_start(struct rte_rawdev *dev)
 
 	hw->peer_mw_base = rte_zmalloc("ntb_peer_mw_base", hw->mw_cnt *
 					sizeof(uint64_t), 0);
+	if (hw->peer_mw_base == NULL) {
+		NTB_LOG(ERR, "Cannot allocate memory for peer mw base.");
+		ret = -ENOMEM;
+		goto err_q_init;
+	}
 
 	if (hw->ntb_ops->spad_read == NULL) {
 		ret = -ENOTSUP;
drivers/raw/ntb/ntb_hw_intel.c +5 -0
index 4427e11..a742e8f 100644
@@ -148,6 +148,11 @@ intel_ntb_dev_init(const struct rte_rawdev *dev)
 
 	hw->mw_size = rte_zmalloc("ntb_mw_size",
 				  hw->mw_cnt * sizeof(uint64_t), 0);
+	if (hw->mw_size == NULL) {
+		NTB_LOG(ERR, "Cannot allocate memory for mw size.");
+		return -ENOMEM;
+	}
+
 	for (i = 0; i < hw->mw_cnt; i++) {
 		bar = intel_ntb_bar[i];
 		hw->mw_size[i] = hw->pci_dev->mem_resource[bar].len;
Signature · 1 line
2.7.4
#2 lore raw

Re: [dpdk-dev] [PATCH 1/2] raw/ntb: check spad user index

In reply to Min Hu (Connor)

Hi

Quoted 26 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Wednesday, April 21, 2021 10:08
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Li, Xiaoyun <[email protected]>; Wu, Jingjing <[email protected]>
Subject: [PATCH 1/2] raw/ntb: check spad user index

From: Chengwen Feng <[email protected]>

This patch adds checking spad user index validity when set or get attr.

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")
---
 drivers/raw/ntb/ntb.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/raw/ntb/ntb.c index renamed from drivers/raw/ntb/ntb.c +0 -0

6dd213e..0f0e3f2 100644

drivers/raw/ntb/ntb.c ntb_attr_set(struct rte_rawdev *dev, const char · line 1087

Quoted 8 lines
drivers/raw/ntb/ntb.c +4 -0
@@ -1080,6 +1080,10 @@ ntb_attr_set(struct rte_rawdev *dev, const char
 *attr_name,
 		if (hw->ntb_ops->spad_write == NULL)
 			return -ENOTSUP;
 		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Invalid attribute (%s)", attr_name);
+			return -EINVAL;
+		}

It's unnecessary. The value will be checked in intel_ntb_spad_write(). There will be error remind in that.

drivers/raw/ntb/ntb.c

Quoted 13 lines
drivers/raw/ntb/ntb.c +0 -0
 		(*hw->ntb_ops->spad_write)(dev, hw->spad_user_list[index],
 					   1, attr_value);

NTB_LOG(DEBUG, "Set attribute (%s) Value (%" PRIu64 ")", @@
-1174,6 +1178,10 @@ ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,

drivers/raw/ntb/ntb.c +2 -0
 		if (hw->ntb_ops->spad_read == NULL)
 			return -ENOTSUP;
 		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Attribute (%s) out of range",

attr_name);

drivers/raw/ntb/ntb.c +2 -0
+			return -EINVAL;
+		}

Same as above.

Quoted 5 lines
drivers/raw/ntb/ntb.c +0 -1
 		*attr_value = (*hw->ntb_ops->spad_read)(dev,
 				hw->spad_user_list[index], 0);
 		NTB_LOG(DEBUG, "Attribute (%s) Value (%" PRIu64 ")",
--

2.7.4

Acked-by on v1 2/2
#11 lore raw

Re: [dpdk-dev] [PATCH 2/2] raw/ntb: check malloc result

In reply to Min Hu (Connor)

Hi

Quoted 58 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Wednesday, April 21, 2021 10:08
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Li, Xiaoyun <[email protected]>; Wu, Jingjing <[email protected]>
Subject: [PATCH 2/2] raw/ntb: check malloc result

From: Chengwen Feng <[email protected]>

This patch adds checking for rte_zmalloc() result when init intel ntb device, also fix the same bug when start ntb device.

Fixes 034c328eb025 ("raw/ntb: support Intel NTB")
Fixes c39d1e082a4b ("raw/ntb: setup queues")
---
 drivers/raw/ntb/ntb.c          | 5 +++++
 drivers/raw/ntb/ntb_hw_intel.c | 5 +++++
 2 files changed, 10 insertions(+)
drivers/raw/ntb/ntb.c index renamed from drivers/raw/ntb/ntb.c +0 -0

0f0e3f2..6703bb5 100644

drivers/raw/ntb/ntb.c +5 -0
@@ -923,6 +923,11 @@ ntb_dev_start(struct rte_rawdev *dev)
 
 	hw->peer_mw_base = rte_zmalloc("ntb_peer_mw_base", hw->mw_cnt
 *
 					sizeof(uint64_t), 0);
+	if (hw->peer_mw_base == NULL) {
+		NTB_LOG(ERR, "Cannot allocate memory for peer mw base.");
+		ret = -ENOMEM;
+		goto err_q_init;
+	}
 
 	if (hw->ntb_ops->spad_read == NULL) {
drivers/raw/ntb/ntb.c +0 -0
 		ret = -ENOTSUP;
drivers/raw/ntb/ntb_hw_intel.c +5 -1
index 4427e11..a742e8f 100644
@@ -148,6 +148,11 @@ intel_ntb_dev_init(const struct rte_rawdev *dev)
 
 	hw->mw_size = rte_zmalloc("ntb_mw_size",
 				  hw->mw_cnt * sizeof(uint64_t), 0);
+	if (hw->mw_size == NULL) {
+		NTB_LOG(ERR, "Cannot allocate memory for mw size.");
+		return -ENOMEM;
+	}
+
 	for (i = 0; i < hw->mw_cnt; i++) {
 		bar = intel_ntb_bar[i];
 		hw->mw_size[i] = hw->pci_dev->mem_resource[bar].len;
--
Quoted 1 line

2.7.4

#3 lore raw

Re: [dpdk-dev] [PATCH 1/2] raw/ntb: check spad user index

In reply to Li, Xiaoyun
Quoted 23 lines · Xiaoyun

Hi

Quoted 21 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Wednesday, April 21, 2021 10:08
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Li, Xiaoyun <[email protected]>; Wu, Jingjing <[email protected]>
Subject: [PATCH 1/2] raw/ntb: check spad user index

From: Chengwen Feng <[email protected]>

This patch adds checking spad user index validity when set or get attr.

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")
---
 drivers/raw/ntb/ntb.c | 8 ++++++++
 1 file changed, 8 insertions(+)
Quoted 15 lines

drivers/raw/ntb/ntb.c ntb_attr_set(struct rte_rawdev *dev, const char · line 1087

Quoted 13 lines
drivers/raw/ntb/ntb.c index renamed from drivers/raw/ntb/ntb.c +0 -0

6dd213e..0f0e3f2 100644

drivers/raw/ntb/ntb.c +4 -0
@@ -1080,6 +1080,10 @@ ntb_attr_set(struct rte_rawdev *dev, const char
 *attr_name,
 		if (hw->ntb_ops->spad_write == NULL)
 			return -ENOTSUP;
 		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Invalid attribute (%s)", attr_name);
+			return -EINVAL;
+		}

It's unnecessary. The value will be checked in intel_ntb_spad_write(). There will be error remind in that.

index maybe large, and then hw->spad_user_list[index] may lead to segmentation fault. so the verification is required.

Quoted 26 lines
Quoted 12 lines
drivers/raw/ntb/ntb.c +0 -0
 		(*hw->ntb_ops->spad_write)(dev, hw->spad_user_list[index],
 					   1, attr_value);

NTB_LOG(DEBUG, "Set attribute (%s) Value (%" PRIu64 ")", @@
-1174,6 +1178,10 @@ ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,

drivers/raw/ntb/ntb.c +2 -0
 		if (hw->ntb_ops->spad_read == NULL)
 			return -ENOTSUP;
 		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Attribute (%s) out of range",

attr_name);

drivers/raw/ntb/ntb.c

Quoted 2 lines
drivers/raw/ntb/ntb.c +2 -0
+			return -EINVAL;
+		}

Same as above.

Quoted 5 lines
drivers/raw/ntb/ntb.c +0 -1
 		*attr_value = (*hw->ntb_ops->spad_read)(dev,
 				hw->spad_user_list[index], 0);
 		NTB_LOG(DEBUG, "Attribute (%s) Value (%" PRIu64 ")",
--

2.7.4

.

#4 lore raw

Re: [dpdk-dev] [PATCH 1/2] raw/ntb: check spad user index

In reply to Li, Xiaoyun

Hi, xiaoyun,

Quoted 23 lines · Xiaoyun

Hi

Quoted 21 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Wednesday, April 21, 2021 10:08
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Li, Xiaoyun <[email protected]>; Wu, Jingjing <[email protected]>
Subject: [PATCH 1/2] raw/ntb: check spad user index

From: Chengwen Feng <[email protected]>

This patch adds checking spad user index validity when set or get attr.

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")
---
  drivers/raw/ntb/ntb.c | 8 ++++++++
  1 file changed, 8 insertions(+)
Quoted 16 lines

drivers/raw/ntb/ntb.c ntb_attr_set(struct rte_rawdev *dev, const char · line 1087

Quoted 13 lines
drivers/raw/ntb/ntb.c index renamed from drivers/raw/ntb/ntb.c +0 -0

6dd213e..0f0e3f2 100644

drivers/raw/ntb/ntb.c +4 -0
@@ -1080,6 +1080,10 @@ ntb_attr_set(struct rte_rawdev *dev, const char
 *attr_name,
  		if (hw->ntb_ops->spad_write == NULL)
  			return -ENOTSUP;
  		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Invalid attribute (%s)", attr_name);
+			return -EINVAL;
+		}

It's unnecessary. The value will be checked in intel_ntb_spad_write(). There will be error remind in that.

Nothing to do with intel_ntb_spad_write. If index is no checked, hw->spad_user_list[index] may be be out of memory and result in segmentation default.

Quoted 24 lines

drivers/raw/ntb/ntb.c

Quoted 13 lines
drivers/raw/ntb/ntb.c +0 -0
  		(*hw->ntb_ops->spad_write)(dev, hw->spad_user_list[index],
  					   1, attr_value);

NTB_LOG(DEBUG, "Set attribute (%s) Value (%" PRIu64 ")", @@
-1174,6 +1178,10 @@ ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,
if (hw->ntb_ops->spad_read == NULL)
return -ENOTSUP;
index = atoi(&attr_name[NTB_SPAD_USER_LEN]);

drivers/raw/ntb/ntb.c +2 -0
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Attribute (%s) out of range",

attr_name);

drivers/raw/ntb/ntb.c +2 -0
+			return -EINVAL;
+		}

Same as above.

Quoted 5 lines

*attr_value = (*hw->ntb_ops->spad_read)(dev,
hw->spad_user_list[index], 0);
NTB_LOG(DEBUG, "Attribute (%s) Value (%" PRIu64 ")",
--
2.7.4

.

#5 lore raw

Re: [dpdk-dev] [PATCH 1/2] raw/ntb: check spad user index

Quoted 50 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Wednesday, April 21, 2021 12:37
To: Li, Xiaoyun <[email protected]>; [email protected]
Cc: Yigit, Ferruh <[email protected]>; Wu, Jingjing <[email protected]>
Subject: Re: [PATCH 1/2] raw/ntb: check spad user index

Hi, xiaoyun,

Quoted 23 lines · Xiaoyun

Hi

Quoted 21 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Wednesday, April 21, 2021 10:08
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Li, Xiaoyun <[email protected]>; Wu, Jingjing <[email protected]>
Subject: [PATCH 1/2] raw/ntb: check spad user index

From: Chengwen Feng <[email protected]>

This patch adds checking spad user index validity when set or get attr.

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")
---
  drivers/raw/ntb/ntb.c | 8 ++++++++
  1 file changed, 8 insertions(+)
Quoted 15 lines

drivers/raw/ntb/ntb.c ntb_attr_set(struct rte_rawdev *dev, const · line 1087

Quoted 13 lines
drivers/raw/ntb/ntb.c index renamed from drivers/raw/ntb/ntb.c +0 -0

6dd213e..0f0e3f2 100644

drivers/raw/ntb/ntb.c +4 -0
@@ -1080,6 +1080,10 @@ ntb_attr_set(struct rte_rawdev *dev, const
 char *attr_name,
  		if (hw->ntb_ops->spad_write == NULL)
  			return -ENOTSUP;
  		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Invalid attribute (%s)", attr_name);
+			return -EINVAL;
+		}

It's unnecessary. The value will be checked in intel_ntb_spad_write(). There

Quoted 5 lines

will be error remind in that.

Quoted 1 line

Nothing to do with intel_ntb_spad_write. If index is no checked, hw->spad_user_list[index] may be be out of memory and result in segmentation default.

Are you using this driver externally? Or you just check everything in DPDK.
This is actually only used for ntb example in file trans mode. And only 0 and 1 are used for index.

Quoted 26 lines
Quoted 26 lines
Quoted 13 lines
drivers/raw/ntb/ntb.c +0 -0
  		(*hw->ntb_ops->spad_write)(dev, hw->spad_user_list[index],
  					   1, attr_value);

NTB_LOG(DEBUG, "Set attribute (%s) Value (%" PRIu64 ")", @@
-1174,6 +1178,10 @@ ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,
if (hw->ntb_ops->spad_read == NULL)
return -ENOTSUP;
index = atoi(&attr_name[NTB_SPAD_USER_LEN]);

drivers/raw/ntb/ntb.c +2 -0
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Attribute (%s) out of range",

attr_name);

drivers/raw/ntb/ntb.c

Quoted 2 lines
drivers/raw/ntb/ntb.c +2 -0
+			return -EINVAL;
+		}

Same as above.

Quoted 5 lines

*attr_value = (*hw->ntb_ops->spad_read)(dev,
hw->spad_user_list[index], 0);
NTB_LOG(DEBUG, "Attribute (%s) Value (%" PRIu64 ")",
--
2.7.4

.

#6 lore raw

Re: [dpdk-dev] [PATCH 1/2] raw/ntb: check spad user index

Quoted 50 lines · Xiaoyun
Quoted 50 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Wednesday, April 21, 2021 12:37
To: Li, Xiaoyun <[email protected]>; [email protected]
Cc: Yigit, Ferruh <[email protected]>; Wu, Jingjing <[email protected]>
Subject: Re: [PATCH 1/2] raw/ntb: check spad user index

Hi, xiaoyun,

Quoted 38 lines · Xiaoyun

Hi

Quoted 26 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Wednesday, April 21, 2021 10:08
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Li, Xiaoyun <[email protected]>; Wu, Jingjing <[email protected]>
Subject: [PATCH 1/2] raw/ntb: check spad user index

From: Chengwen Feng <[email protected]>

This patch adds checking spad user index validity when set or get attr.

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")
---
   drivers/raw/ntb/ntb.c | 8 ++++++++
   1 file changed, 8 insertions(+)
drivers/raw/ntb/ntb.c index renamed from drivers/raw/ntb/ntb.c +0 -0

6dd213e..0f0e3f2 100644

drivers/raw/ntb/ntb.c ntb_attr_set(struct rte_rawdev *dev, const · line 1087

Quoted 8 lines
drivers/raw/ntb/ntb.c +4 -0
@@ -1080,6 +1080,10 @@ ntb_attr_set(struct rte_rawdev *dev, const
 char *attr_name,
   		if (hw->ntb_ops->spad_write == NULL)
   			return -ENOTSUP;
   		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Invalid attribute (%s)", attr_name);
+			return -EINVAL;
+		}

It's unnecessary. The value will be checked in intel_ntb_spad_write(). There

Quoted 9 lines
Quoted 5 lines

will be error remind in that.

Quoted 1 line

Nothing to do with intel_ntb_spad_write. If index is no checked, hw->spad_user_list[index] may be be out of memory and result in segmentation default.

Are you using this driver externally? Or you just check everything in DPDK.
This is actually only used for ntb example in file trans mode. And only 0 and 1 are used for index.

Well, I just reviewed codes and found this bug.

Quoted 28 lines
Quoted 18 lines
Quoted 18 lines
Quoted 13 lines
drivers/raw/ntb/ntb.c +0 -0
   		(*hw->ntb_ops->spad_write)(dev, hw->spad_user_list[index],
   					   1, attr_value);
   		NTB_LOG(DEBUG, "Set attribute (%s) Value (%" PRIu64 ")", @@
-1174,6 +1178,10 @@ ntb_attr_get(struct rte_rawdev *dev, const char
*attr_name,
   		if (hw->ntb_ops->spad_read == NULL)
   			return -ENOTSUP;
   		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
drivers/raw/ntb/ntb.c +2 -0
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Attribute (%s) out of range",

attr_name);

drivers/raw/ntb/ntb.c

Quoted 2 lines
drivers/raw/ntb/ntb.c +2 -0
+			return -EINVAL;
+		}

Same as above.

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
   		*attr_value = (*hw->ntb_ops->spad_read)(dev,
   				hw->spad_user_list[index], 0);
   		NTB_LOG(DEBUG, "Attribute (%s) Value (%" PRIu64 ")",

--
2.7.4

.

.

Acked-by on v1 1/2
#8 lore raw

Re: [dpdk-dev] [PATCH 1/2] raw/ntb: check spad user index

In reply to Min Hu (Connor)
Quoted 51 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Wednesday, April 21, 2021 10:08
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Li, Xiaoyun <[email protected]>; Wu, Jingjing <[email protected]>
Subject: [PATCH 1/2] raw/ntb: check spad user index

From: Chengwen Feng <[email protected]>

This patch adds checking spad user index validity when set or get attr.

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")
---
 drivers/raw/ntb/ntb.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/raw/ntb/ntb.c index renamed from drivers/raw/ntb/ntb.c +0 -0

6dd213e..0f0e3f2 100644

drivers/raw/ntb/ntb.c +4 -0
@@ -1080,6 +1080,10 @@ ntb_attr_set(struct rte_rawdev *dev, const char
 *attr_name,
 		if (hw->ntb_ops->spad_write == NULL)
 			return -ENOTSUP;
 		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Invalid attribute (%s)", attr_name);
+			return -EINVAL;
+		}
 		(*hw->ntb_ops->spad_write)(dev, hw->spad_user_list[index],
 					   1, attr_value);

NTB_LOG(DEBUG, "Set attribute (%s) Value (%" PRIu64 ")", @@
-1174,6 +1178,10 @@ ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,

drivers/raw/ntb/ntb.c +2 -0
 		if (hw->ntb_ops->spad_read == NULL)
 			return -ENOTSUP;
 		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Attribute (%s) out of range",

attr_name);

drivers/raw/ntb/ntb.c +2 -1
+			return -EINVAL;
+		}
 		*attr_value = (*hw->ntb_ops->spad_read)(dev,
 				hw->spad_user_list[index], 0);
 		NTB_LOG(DEBUG, "Attribute (%s) Value (%" PRIu64 ")",
--
Quoted 1 line

2.7.4

#7 lore raw

Re: [dpdk-dev] [PATCH 1/2] raw/ntb: check spad user index

In reply to Min Hu (Connor)

21/04/2021 08:08, Min Hu (Connor):

Quoted 16 lines · Xiaoyun
Quoted 15 lines

From: Min Hu (Connor) <[email protected]>

Quoted 14 lines · Xiaoyun
Quoted 13 lines

From: Min Hu (Connor) <[email protected]>

drivers/raw/ntb/ntb.c ntb_attr_set(struct rte_rawdev *dev, const char *attr_name, · line 1086

Quoted 8 lines

From: Chengwen Feng <[email protected]>

drivers/raw/ntb/ntb.c +4 -0
   		index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+		if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+			NTB_LOG(ERR, "Invalid attribute (%s)", attr_name);
+			return -EINVAL;
+		}

It's unnecessary. The value will be checked in intel_ntb_spad_write(). There will be error remind in that.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Nothing to do with intel_ntb_spad_write. If index is no checked, hw->spad_user_list[index] may be be out of memory and result in segmentation default.

Are you using this driver externally? Or you just check everything in DPDK.
This is actually only used for ntb example in file trans mode. And only 0 and 1 are used for index.

Well, I just reviewed codes and found this bug.

Are you using some tools to detect bugs?

#9 lore raw

Re: [dpdk-dev] [PATCH 1/2] raw/ntb: check spad user index

In reply to Li, Xiaoyun

22/04/2021 07:05, Li, Xiaoyun:

Quoted 11 lines
Quoted 9 lines

From: Chengwen Feng <[email protected]>

This patch adds checking spad user index validity when set or get attr.

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")

Series applied, thanks.