netfilter: nft_exthdr: stop the TCP option walk at EOL
Subsystems (2)
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")
Signed-off-by Ryosuke Iwahashi <[email protected]>
---
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
@@ -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;
Florian Westphal
maintainerQuoted 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?