Skip to contentSkip to conversation

net/i40e: fix null dereference in raw flow item

PATCH In review Ciara Loftus 3 participants 5 messages Mar 9 – Mar 11 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/i40e: fix null dereference in raw flow item

When a RTE_FLOW_ITEM_TYPE_RAW item is used with a non-zero length and a NULL pattern pointer in either the spec or mask, a segfault occurs as the pattern bytes are accessed unconditionally in a loop. Add NULL checks for both spec->pattern and mask->pattern before entering the loop that uses those fields.

Bugzilla ID: 1155

Fixes 6ced3dd72f5f ("net/i40e: support flexible payload parsing for FDIR")
---
 drivers/net/intel/i40e/i40e_flow.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/net/intel/i40e/i40e_flow.c +18 -0
index 2374b9bbca..6ad3013573 100644
@@ -2350,6 +2350,24 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
 				return -rte_errno;
 			}
 
+			if (raw_spec->length != 0) {
+				if (raw_spec->pattern == NULL) {
+					rte_flow_error_set(error, EINVAL,
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "NULL RAW spec pattern");
+					return -rte_errno;
+				}
+
+				if (raw_mask->pattern == NULL) {
+					rte_flow_error_set(error, EINVAL,
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "NULL RAW mask pattern");
+					return -rte_errno;
+				}
+			}
+
 			for (i = 0; i < raw_spec->length; i++) {
 				j = i + next_dst_off;
 				if (j >= RTE_ETH_FDIR_MAX_FLEXLEN ||
Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 34 lines · Ciara Loftus

When a RTE_FLOW_ITEM_TYPE_RAW item is used with a non-zero length and a NULL pattern pointer in either the spec or mask, a segfault occurs as the pattern bytes are accessed unconditionally in a loop. Add NULL checks for both spec->pattern and mask->pattern before entering the loop that uses those fields.

Bugzilla ID: 1155

Fixes 6ced3dd72f5f ("net/i40e: support flexible payload parsing for FDIR")
---
  drivers/net/intel/i40e/i40e_flow.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
drivers/net/intel/i40e/i40e_flow.c +11 -0
index 2374b9bbca..6ad3013573 100644
@@ -2350,6 +2350,24 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
  				return -rte_errno;
  			}
 
+			if (raw_spec->length != 0) {
+				if (raw_spec->pattern == NULL) {
+					rte_flow_error_set(error, EINVAL,
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "NULL RAW spec pattern");
+					return -rte_errno;
+				}
+
+				if (raw_mask->pattern == NULL) {
+					rte_flow_error_set(error, EINVAL,

drivers/net/intel/i40e/i40e_flow.c i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev, · line 2373

Quoted 10 lines
drivers/net/intel/i40e/i40e_flow.c +7 -0
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "NULL RAW mask pattern");
+					return -rte_errno;
+				}
+			}
+
  			for (i = 0; i < raw_spec->length; i++) {
  				j = i + next_dst_off;
  				if (j >= RTE_ETH_FDIR_MAX_FLEXLEN ||

Maybe also check if raw_mask length matches raw_spec?

Otherwise,

Signature · 2 lines
Thanks,
Anatoly
#2 lore raw

PATCH v2 1/1 net/i40e: validate raw flow items before dereferencing

In reply to Ciara Loftus

When a RTE_FLOW_ITEM_TYPE_RAW item is used with a non-zero length, the spec and mask pattern pointers are dereferenced unconditionally in a loop, causing a segfault if either is NULL. Additionally, no check is made that the spec and mask have equal lengths before iterating, which could result in out-of-bounds access.

Add validation before the loop: reject the item if either pattern pointer is NULL, or if the spec and mask lengths differ.

Bugzilla ID: 1155

Fixes 6ced3dd72f5f ("net/i40e: support flexible payload parsing for FDIR")

---
v2:
* Add an additional check for spec and mask length mismatch

---
 drivers/net/intel/i40e/i40e_flow.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/net/intel/i40e/i40e_flow.c +24 -0
index 2374b9bbca..4624edc758 100644
@@ -2350,6 +2350,30 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
 				return -rte_errno;
 			}
 
+			if (raw_spec->length != 0) {
+				if (raw_spec->pattern == NULL) {
+					rte_flow_error_set(error, EINVAL,
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "NULL RAW spec pattern");
+					return -rte_errno;
+				}
+				if (raw_mask->pattern == NULL) {
+					rte_flow_error_set(error, EINVAL,
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "NULL RAW mask pattern");
+					return -rte_errno;
+				}
+				if (raw_spec->length != raw_mask->length) {
+					rte_flow_error_set(error, EINVAL,
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "RAW spec and mask length mismatch");
+					return -rte_errno;
+				}
+			}
+
 			for (i = 0; i < raw_spec->length; i++) {
 				j = i + next_dst_off;
 				if (j >= RTE_ETH_FDIR_MAX_FLEXLEN ||
Signature · 1 line
2.43.0
Acked-by Anatoly Burakov on v2 1/1
#3 lore raw

Re: [PATCH v2] net/i40e: validate raw flow items before dereferencing

Quoted 6 lines · Ciara Loftus

When a RTE_FLOW_ITEM_TYPE_RAW item is used with a non-zero length, the spec and mask pattern pointers are dereferenced unconditionally in a loop, causing a segfault if either is NULL. Additionally, no check is made that the spec and mask have equal lengths before iterating, which could result in out-of-bounds access.

Quoted 8 lines

Add validation before the loop: reject the item if either pattern pointer is NULL, or if the spec and mask lengths differ.

Bugzilla ID: 1155

Fixes 6ced3dd72f5f ("net/i40e: support flexible payload parsing for FDIR")

Missed carrying-forward Anatoly's ack from v1:

Quoted 45 lines

---
v2:
* Add an additional check for spec and mask length mismatch

---
 drivers/net/intel/i40e/i40e_flow.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/net/intel/i40e/i40e_flow.c +24 -0
index 2374b9bbca..4624edc758 100644
@@ -2350,6 +2350,30 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
 				return -rte_errno;
 			}
 
+			if (raw_spec->length != 0) {
+				if (raw_spec->pattern == NULL) {
+					rte_flow_error_set(error, EINVAL,
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "NULL RAW spec pattern");
+					return -rte_errno;
+				}
+				if (raw_mask->pattern == NULL) {
+					rte_flow_error_set(error, EINVAL,
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "NULL RAW mask pattern");
+					return -rte_errno;
+				}
+				if (raw_spec->length != raw_mask->length) {
+					rte_flow_error_set(error, EINVAL,
+							   RTE_FLOW_ERROR_TYPE_ITEM,
+							   item,
+							   "RAW spec and mask length mismatch");
+					return -rte_errno;
+				}
+			}
+
 			for (i = 0; i < raw_spec->length; i++) {
 				j = i + next_dst_off;
 				if (j >= RTE_ETH_FDIR_MAX_FLEXLEN ||
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v2] net/i40e: validate raw flow items before dereferencing

Quoted 10 lines · Bruce Richardson
Quoted 9 lines · Ciara Loftus

When a RTE_FLOW_ITEM_TYPE_RAW item is used with a non-zero length, the spec and mask pattern pointers are dereferenced unconditionally in a loop, causing a segfault if either is NULL. Additionally, no check is made that the spec and mask have equal lengths before iterating, which could result in out-of-bounds access.

Add validation before the loop: reject the item if either pattern pointer is NULL, or if the spec and mask lengths differ.

Quoted 8 lines
Quoted 5 lines

Bugzilla ID: 1155

Fixes 6ced3dd72f5f ("net/i40e: support flexible payload parsing for FDIR")

Missed carrying-forward Anatoly's ack from v1:

Applied to dpdk-next-net-intel.
Thanks,
/Bruce