{"id":2230588,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2230588/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/20260429215557.167114-2-pablo@netfilter.org/","project":{"id":26,"url":"http://patchwork.ozlabs.org/api/1.1/projects/26/?format=json","name":"Netfilter Development","link_name":"netfilter-devel","list_id":"netfilter-devel.vger.kernel.org","list_email":"netfilter-devel@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260429215557.167114-2-pablo@netfilter.org>","date":"2026-04-29T21:55:57","name":"[nf,v3,2/2] netfilter: nft_compat: run xt_check_hooks_{match,target}() from .validate","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"9549f2d61e8abf8490568e999ad63c24b7c439c5","submitter":{"id":1315,"url":"http://patchwork.ozlabs.org/api/1.1/people/1315/?format=json","name":"Pablo Neira Ayuso","email":"pablo@netfilter.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/20260429215557.167114-2-pablo@netfilter.org/mbox/","series":[{"id":502157,"url":"http://patchwork.ozlabs.org/api/1.1/series/502157/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=502157","date":"2026-04-29T21:55:56","name":"[nf,v3,1/2] netfilter: x_tables: add .check_hooks to matches and targets","version":3,"mbox":"http://patchwork.ozlabs.org/series/502157/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2230588/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2230588/checks/","tags":{},"headers":{"Return-Path":"\n <netfilter-devel+bounces-12308-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","netfilter-devel@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=netfilter.org header.i=@netfilter.org\n header.a=rsa-sha256 header.s=2025 header.b=Fgt7Nqfy;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=netfilter-devel+bounces-12308-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org\n header.b=\"Fgt7Nqfy\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=217.70.190.124","smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=netfilter.org","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=netfilter.org"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g5WN02TGzz1yHZ\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 30 Apr 2026 07:56:16 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 6F76A3026322\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 21:56:08 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 6C0E33932FC;\n\tWed, 29 Apr 2026 21:56:06 +0000 (UTC)","from mail.netfilter.org (mail.netfilter.org [217.70.190.124])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 41F3F30EF82\n\tfor <netfilter-devel@vger.kernel.org>; Wed, 29 Apr 2026 21:56:04 +0000 (UTC)","from localhost.localdomain (mail-agni [217.70.190.124])\n\tby mail.netfilter.org (Postfix) with ESMTPSA id 4301660269;\n\tWed, 29 Apr 2026 23:56:02 +0200 (CEST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777499766; cv=none;\n b=iqtW3duxGTNE0Ebfmr5W3EFwV/o6nbD8YA2kjuAzkVGjsk39w1pqQInhRR0wfEahJF8I6P8FE2b6X7kuHb7NEjdPPKamGT6CKUrjxPVLZFjB9Wipp3f10vvuI8GJ6nU0NezWY0/1LpZj4OSM26yzAj1wqK2Gl84hdpP5BHnwvtM=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777499766; c=relaxed/simple;\n\tbh=NXNMq9a1h0uiWbLB6twUoelkk7F0N9igbRmF5BshdjU=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=PjkDL0jXXsbWLAucjoWLr2gH74OnBU80BDVt+nrb5TgC+SPozMmAahfKuH36qGspHmqPYaaB94XRupXoe881y8Io1spstN/CJ0DiZToV6T42aVttGovltk4tTibISNQRLbT+skpYqnXLoLGX28/xnuh7Bcddd2jzJlZHWKc6znA=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=netfilter.org;\n spf=pass smtp.mailfrom=netfilter.org;\n dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org\n header.b=Fgt7Nqfy; arc=none smtp.client-ip=217.70.190.124","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org;\n\ts=2025; t=1777499762;\n\tbh=q+GQShBvMegxncMKMJWLwdqQu5Fq1P5ySPqngl58UsI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Fgt7NqfydZTAxJVOfJd/srAZ5yPh/ob0nD7t+6bWSjLNPG5ap4uJr5FxAShjO7G3i\n\t N7uX4oLkLQwEzAUVQNqepJG9TJF0LqY8bnT/5KO5MUafmW6VFtf5U7yy471HgM6oWJ\n\t vRKTF2D+nZGSlK8RlPTaKh6nWdwWXBMXt9ioyEACxzhbliQabtGCmr9nBfNl8pbUdg\n\t bBvcS3rOQ2wAD9a772IcXVsBg8xwFXnVfbvbZWVNqqUlxyqY6nQXrmHOfpFj9ZOn7Y\n\t 8F/VLrrqkKKT9PFIAG8WH6vTg+9w8Sc7y5ZBvQ22rKlu0rewknjQz8wYxl1cnkh6KF\n\t h6+x9eK1jobIg==","From":"Pablo Neira Ayuso <pablo@netfilter.org>","To":"netfilter-devel@vger.kernel.org","Cc":"fw@strlen.de","Subject":"[PATCH nf,v3 2/2] netfilter: nft_compat: run\n xt_check_hooks_{match,target}() from .validate","Date":"Wed, 29 Apr 2026 23:55:57 +0200","Message-ID":"<20260429215557.167114-2-pablo@netfilter.org>","X-Mailer":"git-send-email 2.47.3","In-Reply-To":"<20260429215557.167114-1-pablo@netfilter.org>","References":"<20260429215557.167114-1-pablo@netfilter.org>","Precedence":"bulk","X-Mailing-List":"netfilter-devel@vger.kernel.org","List-Id":"<netfilter-devel.vger.kernel.org>","List-Subscribe":"<mailto:netfilter-devel+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:netfilter-devel+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"Several matches and one target check that the hook is correct from\ncheckentry(), however, the basechain is only available from\nnft_table_validate().\n\nThis patch uses xt_check_hooks_{match,target}() from the nft_compat\nexpression .validate path.\n\nThis patch sets the table in the nft_ctx struct in nft_table_validate()\nwhich is required by this patch.\n\nBased on patch from Florian Westphal.\n\nFixes: 0ca743a55991 (\"netfilter: nf_tables: add compatibility layer for x_tables\")\nReported-by: Xiang Mei <xmei5@asu.edu>\nSigned-off-by: Pablo Neira Ayuso <pablo@netfilter.org>\n---\nv3: - remove redundant initialization of hook_mask in match\n    - remove redundant check for hook_mask in match\n    - adjust commit description to refer to check_hooks from .validate\n\n net/netfilter/nf_tables_api.c |  1 +\n net/netfilter/nft_compat.c    | 45 +++++++++++++++++++++++++++--------\n 2 files changed, 36 insertions(+), 10 deletions(-)","diff":"diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c\nindex d20ce5c36d31..38e33c66c618 100644\n--- a/net/netfilter/nf_tables_api.c\n+++ b/net/netfilter/nf_tables_api.c\n@@ -4205,6 +4205,7 @@ static int nft_table_validate(struct net *net, const struct nft_table *table)\n \tstruct nft_chain *chain;\n \tstruct nft_ctx ctx = {\n \t\t.net\t= net,\n+\t\t.table\t= (struct nft_table *)table,\n \t\t.family\t= table->family,\n \t};\n \tint err = 0;\ndiff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c\nindex decc725a33c2..0caa9304d2d0 100644\n--- a/net/netfilter/nft_compat.c\n+++ b/net/netfilter/nft_compat.c\n@@ -261,10 +261,10 @@ nft_target_init(const struct nft_ctx *ctx, const struct nft_expr *expr,\n \t\t\treturn ret;\n \t}\n \n-\tnft_target_set_tgchk_param(&par, ctx, target, info, &e, proto, inv);\n-\n \tnft_compat_wait_for_destructors(ctx->net);\n \n+\tnft_target_set_tgchk_param(&par, ctx, target, info, &e, proto, inv);\n+\n \tret = xt_check_target(&par, size, proto, inv);\n \tif (ret < 0) {\n \t\tif (ret == -ENOENT) {\n@@ -353,8 +353,6 @@ static int nft_target_dump(struct sk_buff *skb,\n static int nft_target_validate(const struct nft_ctx *ctx,\n \t\t\t       const struct nft_expr *expr)\n {\n-\tstruct xt_target *target = expr->ops->data;\n-\tunsigned int hook_mask = 0;\n \tint ret;\n \n \tif (ctx->family != NFPROTO_IPV4 &&\n@@ -377,11 +375,21 @@ static int nft_target_validate(const struct nft_ctx *ctx,\n \t\tconst struct nft_base_chain *basechain =\n \t\t\t\t\t\tnft_base_chain(ctx->chain);\n \t\tconst struct nf_hook_ops *ops = &basechain->ops;\n+\t\tunsigned int hook_mask = 1 << ops->hooknum;\n+\t\tstruct xt_target *target = expr->ops->data;\n+\t\tvoid *info = nft_expr_priv(expr);\n+\t\tstruct xt_tgchk_param par;\n+\t\tunion nft_entry e = {};\n \n-\t\thook_mask = 1 << ops->hooknum;\n \t\tif (target->hooks && !(hook_mask & target->hooks))\n \t\t\treturn -EINVAL;\n \n+\t\tnft_target_set_tgchk_param(&par, ctx, target, info, &e, 0, false);\n+\n+\t\tret = xt_check_hooks_target(&par);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\n \t\tret = nft_compat_chain_validate_dependency(ctx, target->table);\n \t\tif (ret < 0)\n \t\t\treturn ret;\n@@ -515,10 +523,10 @@ __nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr,\n \t\t\treturn ret;\n \t}\n \n-\tnft_match_set_mtchk_param(&par, ctx, match, info, &e, proto, inv);\n-\n \tnft_compat_wait_for_destructors(ctx->net);\n \n+\tnft_match_set_mtchk_param(&par, ctx, match, info, &e, proto, inv);\n+\n \treturn xt_check_match(&par, size, proto, inv);\n }\n \n@@ -614,8 +622,6 @@ static int nft_match_large_dump(struct sk_buff *skb,\n static int nft_match_validate(const struct nft_ctx *ctx,\n \t\t\t      const struct nft_expr *expr)\n {\n-\tstruct xt_match *match = expr->ops->data;\n-\tunsigned int hook_mask = 0;\n \tint ret;\n \n \tif (ctx->family != NFPROTO_IPV4 &&\n@@ -638,11 +644,30 @@ static int nft_match_validate(const struct nft_ctx *ctx,\n \t\tconst struct nft_base_chain *basechain =\n \t\t\t\t\t\tnft_base_chain(ctx->chain);\n \t\tconst struct nf_hook_ops *ops = &basechain->ops;\n+\t\tunsigned int hook_mask = 1 << ops->hooknum;\n+\t\tstruct xt_match *match = expr->ops->data;\n+\t\tsize_t size = XT_ALIGN(match->matchsize);\n+\t\tstruct xt_mtchk_param par;\n+\t\tunion nft_entry e = {};\n+\t\tvoid *info;\n \n-\t\thook_mask = 1 << ops->hooknum;\n \t\tif (match->hooks && !(hook_mask & match->hooks))\n \t\t\treturn -EINVAL;\n \n+\t\tif (NFT_EXPR_SIZE(size) > NFT_MATCH_LARGE_THRESH) {\n+\t\t\tstruct nft_xt_match_priv *priv = nft_expr_priv(expr);\n+\n+\t\t\tinfo = priv->info;\n+\t\t} else {\n+\t\t\tinfo = nft_expr_priv(expr);\n+\t\t}\n+\n+\t\tnft_match_set_mtchk_param(&par, ctx, match, info, &e, 0, false);\n+\n+\t\tret = xt_check_hooks_match(&par);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\n \t\tret = nft_compat_chain_validate_dependency(ctx, match->table);\n \t\tif (ret < 0)\n \t\t\treturn ret;\n","prefixes":["nf","v3","2/2"]}