Skip to contentSkip to conversation

ethdev: fix pointer check in GENEVE and RAW flow copy

PATCH Applied Denis Lyulin 2 participants 2 messages May 19

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ethdev: fix pointer check in GENEVE and RAW flow copy

When rte_flow_conv_item_spec() is called from rte_flow_conv_pattern(), the spec, last and mask pointers are checked separately. If the API is used incorrectly, the spec pointer may be NULL while last and mask may be valid pointers. Also call of rte_flow_conv() with RTE_FLOW_CONV_OP_ITEM_MASK and item->spec == NULL may lead to the same problem.

In rte_flow_conv_item_spec() for GENVE_OPT and RAW item types the spec pointer is used even if the function is called to copy last or mask. It may cause a NULL pointer (spec) dereference.

This commit adds extra check of item->spec and if it is NULL, does not copy further data relying on it

Fixes 841a0445442d ("ethdev: fix GENEVE option item conversion")
---
 lib/ethdev/rte_flow.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
lib/ethdev/rte_flow.c +11 -7
index fe8f43caff..7a51b667cf 100644
@@ -672,13 +672,17 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 			   }),
 			   size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size);
 		off = sizeof(*dst.raw);
-		if (type == RTE_FLOW_CONV_ITEM_SPEC ||
-		    (type == RTE_FLOW_CONV_ITEM_MASK &&
-		     ((spec.raw->length & mask.raw->length) >=
-		      (last.raw->length & mask.raw->length))))
+		if (type == RTE_FLOW_CONV_ITEM_SPEC && spec.raw)
 			tmp = spec.raw->length & mask.raw->length;
-		else
+		else if (type == RTE_FLOW_CONV_ITEM_MASK && spec.raw && last.raw &&
+			 ((spec.raw->length & mask.raw->length) >=
+			  (last.raw->length & mask.raw->length)))
+			tmp = spec.raw->length & mask.raw->length;
+		else if (last.raw)
 			tmp = last.raw->length & mask.raw->length;
+		else
+			tmp = 0;
+
 		if (tmp) {
 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.raw->pattern));
 			if (size >= off + tmp) {
@@ -696,8 +700,8 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		spec.geneve_opt = item->spec;
 		src.geneve_opt = data;
 		dst.geneve_opt = buf;
-		tmp = spec.geneve_opt->option_len << 2;
-		if (size > 0 && src.geneve_opt->data) {
+		tmp = spec.geneve_opt ? (spec.geneve_opt->option_len << 2) : 0;
+		if (size > 0 && tmp > 0 && src.geneve_opt->data) {
 			deep_src = (void *)((uintptr_t)(dst.geneve_opt + 1));
 			dst.geneve_opt->data = rte_memcpy(deep_src,
 							  src.geneve_opt->data,
Signature · 1 line
2.34.1
#1 lore raw
Quoted 14 lines · On Tue, 19 May 2026 10:23:35 +0300 Denis Lyulin <[email protected]> wrote:

When rte_flow_conv_item_spec() is called from rte_flow_conv_pattern(), the spec, last and mask pointers are checked separately. If the API is used incorrectly, the spec pointer may be NULL while last and mask may be valid pointers. Also call of rte_flow_conv() with RTE_FLOW_CONV_OP_ITEM_MASK and item->spec == NULL may lead to the same problem.

In rte_flow_conv_item_spec() for GENVE_OPT and RAW item types the spec pointer is used even if the function is called to copy last or mask. It may cause a NULL pointer (spec) dereference.

This commit adds extra check of item->spec and if it is NULL, does not copy further data relying on it

Quoted 8 lines
Fixes 841a0445442d ("ethdev: fix GENEVE option item conversion")

---

Applied to next-net