{"id":2230056,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2230056/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/20260429062138.22767-1-fw@strlen.de/","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":"<20260429062138.22767-1-fw@strlen.de>","date":"2026-04-29T06:21:35","name":"[nf] netfilter: nf_tables: fix netdev hook allocation memleak with dormant tables","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"4ff484942d2970355302e62c3f43ef9894a50d58","submitter":{"id":1025,"url":"http://patchwork.ozlabs.org/api/1.1/people/1025/?format=json","name":"Florian Westphal","email":"fw@strlen.de"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/20260429062138.22767-1-fw@strlen.de/mbox/","series":[{"id":501995,"url":"http://patchwork.ozlabs.org/api/1.1/series/501995/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=501995","date":"2026-04-29T06:21:35","name":"[nf] netfilter: nf_tables: fix netdev hook allocation memleak with dormant tables","version":1,"mbox":"http://patchwork.ozlabs.org/series/501995/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2230056/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2230056/checks/","tags":{},"headers":{"Return-Path":"\n <netfilter-devel+bounces-12282-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 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-12282-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=91.216.245.30","smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=strlen.de","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=Chamillionaire.breakpoint.cc"],"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)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g56fD1CRDz1xqf\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 16:22:12 +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 217F6301E587\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 06:21:54 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id CA68E37BE7A;\n\tWed, 29 Apr 2026 06:21:52 +0000 (UTC)","from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc\n [91.216.245.30])\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 8F1E537B007\n\tfor <netfilter-devel@vger.kernel.org>; Wed, 29 Apr 2026 06:21:50 +0000 (UTC)","by Chamillionaire.breakpoint.cc (Postfix, from userid 1003)\n\tid 50E6560420; Wed, 29 Apr 2026 08:21:48 +0200 (CEST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777443712; cv=none;\n b=UnBL0AhzLVpsuGV65U3wdB8za/L5gF5VPwMN935V0YZeAKgUS8CtJ9Nh9eoaP0NRAVfZQuZ8brgbwalunEJWw4+YeMJ2veGOOtQJlmNcH/dYz1n3Vwsgs4KFo2Zx4DGHOUZ87L4rBZ4hXOqhXrJHUOk9mxlu+9cyZcOiK0tU5zw=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777443712; c=relaxed/simple;\n\tbh=M+oYmqtCO26emISCdDhdGOHAZL4H/4wNXWifpheiMik=;\n\th=From:To:Cc:Subject:Date:Message-ID:MIME-Version;\n b=hawDtOpg/BlwnyRrKbAm0zvvuc0Zz5PxsW3oHelMyndRFdA9RgJwngNNIU1IXalsY0YZmfU20mt3kVZJLs89IuG9PjsmTXsloChNHmcVzPX3tRedf23+PVQd9WU12SIig9RyJUivoR8hqfmWyT+L9uC73R5U30N/E6EZrwTxdKU=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=strlen.de;\n spf=pass smtp.mailfrom=Chamillionaire.breakpoint.cc;\n arc=none smtp.client-ip=91.216.245.30","From":"Florian Westphal <fw@strlen.de>","To":"<netfilter-devel@vger.kernel.org>","Cc":"Florian Westphal <fw@strlen.de>","Subject":"[PATCH nf] netfilter: nf_tables: fix netdev hook allocation memleak\n with dormant tables","Date":"Wed, 29 Apr 2026 08:21:35 +0200","Message-ID":"<20260429062138.22767-1-fw@strlen.de>","X-Mailer":"git-send-email 2.54.0","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":"sashiko says:\n could the related code in __nf_tables_abort() leak the struct nft_hook objects when the table is dormant?\n\n In __nf_tables_abort(), when rolling back a NEWCHAIN transaction that\n updates hooks, the code conditionally unregisters and frees the hooks only\n if the table is not dormant [..]\n            if (!(table->flags & NFT_TABLE_F_DORMANT)) {\n                nft_netdev_unregister_hooks(net,\n                                            &nft_trans_chain_hooks(trans),\n                                            true);\n            }\n            ...\n            nft_trans_destroy(trans);\n\nUnfortunately netdev family mixes hook registration and allocation.\nPush table struct down and only check for the flag to unregister.\n\nFixes: 216e7bf7402c (\"netfilter: nf_tables: skip netdev hook unregistration if table is dormant\")\nSigned-off-by: Florian Westphal <fw@strlen.de>\n---\n net/netfilter/nf_tables_api.c | 34 ++++++++++++++++++++--------------\n 1 file changed, 20 insertions(+), 14 deletions(-)","diff":"diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c\nindex d20ce5c36d31..ae5984b62ac3 100644\n--- a/net/netfilter/nf_tables_api.c\n+++ b/net/netfilter/nf_tables_api.c\n@@ -407,6 +407,7 @@ static void nft_netdev_unregister_trans_hook(struct net *net,\n }\n \n static void nft_netdev_unregister_hooks(struct net *net,\n+\t\t\t\t\tconst struct nft_table *table,\n \t\t\t\t\tstruct list_head *hook_list,\n \t\t\t\t\tbool release_netdev)\n {\n@@ -414,8 +415,10 @@ static void nft_netdev_unregister_hooks(struct net *net,\n \tstruct nf_hook_ops *ops;\n \n \tlist_for_each_entry_safe(hook, next, hook_list, list) {\n-\t\tlist_for_each_entry(ops, &hook->ops_list, list)\n-\t\t\tnf_unregister_net_hook(net, ops);\n+\t\tif (!(table->flags & NFT_TABLE_F_DORMANT)) {\n+\t\t\tlist_for_each_entry(ops, &hook->ops_list, list)\n+\t\t\t\tnf_unregister_net_hook(net, ops);\n+\t\t}\n \t\tif (release_netdev)\n \t\t\tnft_netdev_hook_unlink_free_rcu(hook);\n \t}\n@@ -452,20 +455,25 @@ static void __nf_tables_unregister_hook(struct net *net,\n \tstruct nft_base_chain *basechain;\n \tconst struct nf_hook_ops *ops;\n \n-\tif (table->flags & NFT_TABLE_F_DORMANT ||\n-\t    !nft_is_base_chain(chain))\n+\tif (!nft_is_base_chain(chain))\n \t\treturn;\n \tbasechain = nft_base_chain(chain);\n \tops = &basechain->ops;\n \n+\t/* must also be called for dormant tables */\n+\tif (nft_base_chain_netdev(table->family, basechain->ops.hooknum)) {\n+\t\tnft_netdev_unregister_hooks(net, table, &basechain->hook_list,\n+\t\t\t\t\t    release_netdev);\n+\t\treturn;\n+\t}\n+\n+\tif (table->flags & NFT_TABLE_F_DORMANT)\n+\t\treturn;\n+\n \tif (basechain->type->ops_unregister)\n \t\treturn basechain->type->ops_unregister(net, ops);\n \n-\tif (nft_base_chain_netdev(table->family, basechain->ops.hooknum))\n-\t\tnft_netdev_unregister_hooks(net, &basechain->hook_list,\n-\t\t\t\t\t    release_netdev);\n-\telse\n-\t\tnf_unregister_net_hook(net, &basechain->ops);\n+\tnf_unregister_net_hook(net, &basechain->ops);\n }\n \n static void nf_tables_unregister_hook(struct net *net,\n@@ -11281,11 +11289,9 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)\n \t\t\tbreak;\n \t\tcase NFT_MSG_NEWCHAIN:\n \t\t\tif (nft_trans_chain_update(trans)) {\n-\t\t\t\tif (!(table->flags & NFT_TABLE_F_DORMANT)) {\n-\t\t\t\t\tnft_netdev_unregister_hooks(net,\n-\t\t\t\t\t\t\t\t    &nft_trans_chain_hooks(trans),\n-\t\t\t\t\t\t\t\t    true);\n-\t\t\t\t}\n+\t\t\t\tnft_netdev_unregister_hooks(net, table,\n+\t\t\t\t\t\t\t    &nft_trans_chain_hooks(trans),\n+\t\t\t\t\t\t\t    true);\n \t\t\t\tfree_percpu(nft_trans_chain_stats(trans));\n \t\t\t\tkfree(nft_trans_chain_name(trans));\n \t\t\t\tnft_trans_destroy(trans);\n","prefixes":["nf"]}