Skip to contentSkip to conversation

tcpopt: don't create exthdr expression without datatype

PATCH New Florian Westphal 1 participant 1 message Dec 15, 2023 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 tcpopt: don't create exthdr expression without datatype

The reproducer crashes during concat evaluation, as the exthdr expression lacks a datatype.

This should never happen, i->dtype must be set.

In this case the culprit is tcp option parsing, it will wire up a non-existent template, because the "nop" option has no length field (1 byte only).

---
 src/tcpopt.c                                                   | 2 +-
 tests/shell/testcases/bogons/nft-f/tcp_option_without_template | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
 create mode 100644 tests/shell/testcases/bogons/nft-f/tcp_option_without_template
src/tcpopt.c +1 -1
index 8111a50718ac..f977e417536a 100644
@@ -224,7 +224,7 @@ struct expr *tcpopt_expr_alloc(const struct location *loc,
 	}
 
 	tmpl = &desc->templates[field];
-	if (!tmpl)
+	if (!tmpl || !tmpl->dtype)
 		return NULL;
 
 	expr = expr_alloc(loc, EXPR_EXTHDR, tmpl->dtype,
tests/shell/testcases/bogons/nft-f/tcp_option_without_template new file +1 -0
new file mode 100644
index 000000000000..fd732fd31aa5
@@ -0,0 +1 @@
+add rule f i tcp option nop length . @ih,32,3 1
Signature · 1 line
2.41.0