Skip to contentSkip to conversation

net/iavf: check for NULL pointer before dereference

PATCH In review Bruce Richardson 2 participants 3 messages Jul 10 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/iavf: check for NULL pointer before dereference

Static analysis with Coverity flags a possible NULL pointer dereference of "hdr1" when handling IPv4 or IPv6 fragements in iavf_fdir_parse_pattern. This is likely a false positive, since the flow pattern protocol sequences are checked before this function is called, so all paths leading to a hdr1 dereference start with an ethernet protocol, which sets hdr1 to a non-NULL value.

However, this is a rather brittle situation, so to prevent any future issues if a new set of allowed protocols is added with IP but no Ethernet matching patterns, add explicit NULL checks for hdr1 before it's used each time.

Coverity Id: 503768

---
 drivers/net/intel/iavf/iavf_fdir.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/intel/iavf/iavf_fdir.c +16 -0
index 8940132dff..ea620863ca 100644
@@ -806,6 +806,14 @@ iavf_fdir_parse_pattern(__rte_unused struct iavf_adapter *ad,
 				 * ethertype, if the spec and mask is valid,
 				 * set ethertype into input set.
 				 */
+				/* ETH should be present via pattern pre-validation. */
+				if (hdr1 == NULL) {
+					rte_flow_error_set(error, EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ITEM,
+						   item,
+						   "Missing ETH header before IPv4 fragment.");
+					return -rte_errno;
+				}
 				input_set |= IAVF_INSET_ETHERTYPE;
 				VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr1, ETH,
 								 ETHERTYPE);
@@ -911,6 +919,14 @@ iavf_fdir_parse_pattern(__rte_unused struct iavf_adapter *ad,
 				 * ethertype, if the spec and mask is valid,
 				 * set ethertype into input set.
 				 */
+				/* ETH should be present via pattern pre-validation. */
+				if (hdr1 == NULL) {
+					rte_flow_error_set(error, EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ITEM,
+						   item,
+						   "Missing ETH header before IPv6 fragment.");
+					return -rte_errno;
+				}
 				input_set |= IAVF_INSET_ETHERTYPE;
 				VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr1, ETH,
 								 ETHERTYPE);
Signature · 1 line
2.53.0
Acked-by on v1 1/1
#1 lore raw
Quoted 1 line

Subject: [PATCH] net/iavf: check for NULL pointer before dereference

check-git-log complains NULL --> null

Quoted 8 lines

Static analysis with Coverity flags a possible NULL pointer dereference of "hdr1" when handling IPv4 or IPv6 fragements in iavf_fdir_parse_pattern. This is likely a false positive, since the flow pattern protocol sequences are checked before this function is called, so all paths leading to a hdr1 dereference start with an ethernet protocol, which sets hdr1 to a non-NULL value.

Quoted 6 lines

However, this is a rather brittle situation, so to prevent any future issues if a new set of allowed protocols is added with IP but no Ethernet matching patterns, add explicit NULL checks for hdr1 before it's used each time.

Coverity Id: 503768

"issue" instead of "id"

Quoted 2 lines
Quoted 50 lines
---
 drivers/net/intel/iavf/iavf_fdir.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/intel/iavf/iavf_fdir.c +1 -0
index 8940132dff..ea620863ca 100644
@@ -806,6 +806,14 @@ iavf_fdir_parse_pattern(__rte_unused struct
 iavf_adapter *ad,
 				 * ethertype, if the spec and mask is valid,
 				 * set ethertype into input set.
 				 */
+				/* ETH should be present via pattern pre-

validation. */

drivers/net/intel/iavf/iavf_fdir.c +3 -0
+				if (hdr1 == NULL) {
+					rte_flow_error_set(error, EINVAL,
+

RTE_FLOW_ERROR_TYPE_ITEM,

drivers/net/intel/iavf/iavf_fdir.c +2 -0
+						   item,
+						   "Missing ETH header before

IPv4 fragment.");

drivers/net/intel/iavf/iavf_fdir.c +2 -0
+					return -rte_errno;
+				}
 				input_set |= IAVF_INSET_ETHERTYPE;

VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr1, ETH,

drivers/net/intel/iavf/iavf_fdir.c +1 -0
 								 ETHERTYPE);
@@ -911,6 +919,14 @@ iavf_fdir_parse_pattern(__rte_unused struct
 iavf_adapter *ad,
 				 * ethertype, if the spec and mask is valid,
 				 * set ethertype into input set.
 				 */
+				/* ETH should be present via pattern pre-

validation. */

drivers/net/intel/iavf/iavf_fdir.c +3 -0
+				if (hdr1 == NULL) {
+					rte_flow_error_set(error, EINVAL,
+

RTE_FLOW_ERROR_TYPE_ITEM,

drivers/net/intel/iavf/iavf_fdir.c +2 -0
+						   item,
+						   "Missing ETH header before

IPv6 fragment.");

drivers/net/intel/iavf/iavf_fdir.c +2 -0
+					return -rte_errno;
+				}
 				input_set |= IAVF_INSET_ETHERTYPE;

VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr1, ETH,
ETHERTYPE);
--
2.53.0

author Applied
#2 lore raw
Quoted 12 lines · Ciara
Quoted 1 line

Subject: [PATCH] net/iavf: check for NULL pointer before dereference

check-git-log complains NULL --> null

Quoted 8 lines

Static analysis with Coverity flags a possible NULL pointer dereference of "hdr1" when handling IPv4 or IPv6 fragements in iavf_fdir_parse_pattern. This is likely a false positive, since the flow pattern protocol sequences are checked before this function is called, so all paths leading to a hdr1 dereference start with an ethernet protocol, which sets hdr1 to a non-NULL value.

Quoted 9 lines
Quoted 6 lines

However, this is a rather brittle situation, so to prevent any future issues if a new set of allowed protocols is added with IP but no Ethernet matching patterns, add explicit NULL checks for hdr1 before it's used each time.

Coverity Id: 503768

"issue" instead of "id"

Fixed on apply

Quoted 5 lines
Quoted 2 lines

Applied to dpdk-next-net-intel.

/Bruce