Skip to contentSkip to conversation

netfilter: nft_exthdr: stop the TCP option walk at EOL

PATCH In review Ryosuke Iwahashi 2 participants 2 messages Nov 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 netfilter: nft_exthdr: stop the TCP option walk at EOL

RFC 9293 section 3.1 requires zero padding after the TCP End of Option List (EOL). The nftables expressions that read, set or strip TCP options keep searching this padding for the target option.

Stop the search for other option kinds at the first EOL. Keep the existing behavior for explicit EOL matches.

Fixes 935b7f643018 ("netfilter: nft_exthdr: add TCP option matching")

---
v2: Resend without line wrapping.

 net/netfilter/nft_exthdr.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
net/netfilter/nft_exthdr.c +12 -3
index 861bab93f435..ce5494cfd4e8 100644
@@ -204,8 +204,11 @@ static void nft_exthdr_tcp_eval(const struct nft_expr *expr,
 	for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) {
 		optl = optlen(opt, i);
 
-		if (priv->type != opt[i])
+		if (priv->type != opt[i]) {
+			if (opt[i] == TCPOPT_EOL)
+				break;
 			continue;
+		}
 
 		if (i + optl > tcphdr_len || priv->len + priv->offset > optl)
 			goto err;
@@ -264,8 +267,11 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,
 
 		optl = optlen(opt, i);
 
-		if (priv->type != opt[i])
+		if (priv->type != opt[i]) {
+			if (opt[i] == TCPOPT_EOL)
+				break;
 			continue;
+		}
 
 		if (i + optl > tcphdr_len || priv->len + priv->offset > optl)
 			goto err;
@@ -347,8 +353,11 @@ static void nft_exthdr_tcp_strip_eval(const struct nft_expr *expr,
 		unsigned int j;
 
 		optl = optlen(opt, i);
-		if (priv->type != opt[i])
+		if (priv->type != opt[i]) {
+			if (opt[i] == TCPOPT_EOL)
+				break;
 			continue;
+		}
 
 		if (i + optl > tcphdr_len)
 			goto drop;
maintainer
#1 lore raw
Quoted 6 lines · Ryosuke Iwahashi

RFC 9293 section 3.1 requires zero padding after the TCP End of Option List (EOL). The nftables expressions that read, set or strip TCP options keep searching this padding for the target option.

Stop the search for other option kinds at the first EOL. Keep the existing behavior for explicit EOL matches.

Why should this be changed?