{"id":2233361,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2233361/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/20260506100728.2664-8-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":"<20260506100728.2664-8-fw@strlen.de>","date":"2026-05-06T10:07:19","name":"[v3,nf,7/8] netfilter: ebtables: close dangling table module init race","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"57dfd77378560a3482fb30eefe675f70e1ea2124","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/20260506100728.2664-8-fw@strlen.de/mbox/","series":[{"id":502948,"url":"http://patchwork.ozlabs.org/api/1.1/series/502948/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=502948","date":"2026-05-06T10:07:14","name":"netfilter: xtables: fix module load and teardown races","version":3,"mbox":"http://patchwork.ozlabs.org/series/502948/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2233361/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2233361/checks/","tags":{},"headers":{"Return-Path":"\n <netfilter-devel+bounces-12458-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=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=netfilter-devel+bounces-12458-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\n [IPv6:2600:3c0a:e001:db::12fc:5321])\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 4g9WKp2QhLz1yJx\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 20:08:14 +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 F2141300A38A\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  6 May 2026 10:08:10 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 06CE03FB7F4;\n\tWed,  6 May 2026 10:08:10 +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 93D0B3F7880\n\tfor <netfilter-devel@vger.kernel.org>; Wed,  6 May 2026 10:08:06 +0000 (UTC)","by Chamillionaire.breakpoint.cc (Postfix, from userid 1003)\n\tid 68F8560D41; Wed, 06 May 2026 12:08:04 +0200 (CEST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778062089; cv=none;\n b=bayZ+iHGCdUksgtDiEF+kU8FIWRodp/D0mHU8/QQw6Pd9cHWefmLTFh/D+D2vV6fhi4XYmrHnUhpY1hHRTXzDxFVVwSu2yHt1FqTnKkWp1veXxNBuoNUEKycynU2weXcu7H9mqL5Ok1oOJn92lKBiCda/xbhkvGOcio3fa3CvlI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778062089; c=relaxed/simple;\n\tbh=NATWsAYtPPhUJ4K6Lqbf2G53tIuEblC3ewFI5ErIgW8=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=KVPS0KGVmcLv0JkrK3Y0wLuJiGv/4WE+0sxlh2n7GQw7cWGxjtmQGOa6wLK/Xt0XSRV+l2G6aTCw97y7Jax4gm4tlD+jooe8b2d8HAWjekhb5S4Jtgpb1f67Sw7ZPe+YMgmdjLh+gIW/x1bm+OmE0T6Y3qHXQm6gQFT776avHVE=","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":"tristan@talencesecurity.com,\n\tFlorian Westphal <fw@strlen.de>","Subject":"[PATCH v3 nf 7/8] netfilter: ebtables: close dangling table module\n init race","Date":"Wed,  6 May 2026 12:07:19 +0200","Message-ID":"<20260506100728.2664-8-fw@strlen.de>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<20260506100728.2664-1-fw@strlen.de>","References":"<20260506100728.2664-1-fw@strlen.de>","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 reported for a related patch:\n In modules like iptable_raw.c, [..], if register_pernet_subsys() fails,\n the rollback might call kfree(rawtable_ops) before [..]\n During this window, could a concurrent userspace process find the globally\n visible template, trigger table_init(), [..]\n\nThe table init functions must always register the template last.\n\nOtherwise, set/getsockopt can instantiate a table in a namespace\nwhile the required pernet ops (contain the destructor) isn't available.\nThis change is also required in x_tables, handled in followup change.\n\nFixes: 87663c39f898 (\"netfilter: ebtables: do not hook tables by default\")\nReviewed-by: Tristan Madani <tristan@talencesecurity.com>\nSigned-off-by: Florian Westphal <fw@strlen.de>\n---\n v3: no changes.\n net/bridge/netfilter/ebtable_broute.c | 12 +++++-------\n net/bridge/netfilter/ebtable_filter.c | 12 +++++-------\n net/bridge/netfilter/ebtable_nat.c    | 10 ++++------\n 3 files changed, 14 insertions(+), 20 deletions(-)","diff":"diff --git a/net/bridge/netfilter/ebtable_broute.c b/net/bridge/netfilter/ebtable_broute.c\nindex e6f9e343b41f..f05c79f215ea 100644\n--- a/net/bridge/netfilter/ebtable_broute.c\n+++ b/net/bridge/netfilter/ebtable_broute.c\n@@ -112,18 +112,16 @@ static struct pernet_operations broute_net_ops = {\n \n static int __init ebtable_broute_init(void)\n {\n-\tint ret = ebt_register_template(&broute_table, broute_table_init);\n+\tint ret = register_pernet_subsys(&broute_net_ops);\n \n \tif (ret)\n \t\treturn ret;\n \n-\tret = register_pernet_subsys(&broute_net_ops);\n-\tif (ret) {\n-\t\tebt_unregister_template(&broute_table);\n-\t\treturn ret;\n-\t}\n+\tret = ebt_register_template(&broute_table, broute_table_init);\n+\tif (ret)\n+\t\tunregister_pernet_subsys(&broute_net_ops);\n \n-\treturn 0;\n+\treturn ret;\n }\n \n static void __exit ebtable_broute_fini(void)\ndiff --git a/net/bridge/netfilter/ebtable_filter.c b/net/bridge/netfilter/ebtable_filter.c\nindex 02b6501c15a5..0fc03b07e62a 100644\n--- a/net/bridge/netfilter/ebtable_filter.c\n+++ b/net/bridge/netfilter/ebtable_filter.c\n@@ -93,18 +93,16 @@ static struct pernet_operations frame_filter_net_ops = {\n \n static int __init ebtable_filter_init(void)\n {\n-\tint ret = ebt_register_template(&frame_filter, frame_filter_table_init);\n+\tint ret = register_pernet_subsys(&frame_filter_net_ops);\n \n \tif (ret)\n \t\treturn ret;\n \n-\tret = register_pernet_subsys(&frame_filter_net_ops);\n-\tif (ret) {\n-\t\tebt_unregister_template(&frame_filter);\n-\t\treturn ret;\n-\t}\n+\tret = ebt_register_template(&frame_filter, frame_filter_table_init);\n+\tif (ret)\n+\t\tunregister_pernet_subsys(&frame_filter_net_ops);\n \n-\treturn 0;\n+\treturn ret;\n }\n \n static void __exit ebtable_filter_fini(void)\ndiff --git a/net/bridge/netfilter/ebtable_nat.c b/net/bridge/netfilter/ebtable_nat.c\nindex 9985a82555c4..8a10375d8909 100644\n--- a/net/bridge/netfilter/ebtable_nat.c\n+++ b/net/bridge/netfilter/ebtable_nat.c\n@@ -93,16 +93,14 @@ static struct pernet_operations frame_nat_net_ops = {\n \n static int __init ebtable_nat_init(void)\n {\n-\tint ret = ebt_register_template(&frame_nat, frame_nat_table_init);\n+\tint ret = register_pernet_subsys(&frame_nat_net_ops);\n \n \tif (ret)\n \t\treturn ret;\n \n-\tret = register_pernet_subsys(&frame_nat_net_ops);\n-\tif (ret) {\n-\t\tebt_unregister_template(&frame_nat);\n-\t\treturn ret;\n-\t}\n+\tret = ebt_register_template(&frame_nat, frame_nat_table_init);\n+\tif (ret)\n+\t\tunregister_pernet_subsys(&frame_nat_net_ops);\n \n \treturn ret;\n }\n","prefixes":["v3","nf","7/8"]}