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 --- net/netfilter/nft_exthdr.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c index 861bab93f435..ce5494cfd4e8 100644 --- a/net/netfilter/nft_exthdr.c +++ b/net/netfilter/nft_exthdr.c @@ -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;