public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Tristan Madani <tristmd@gmail.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Phil Sutter <phil@nwl.cc>, Florian Westphal <fw@strlen.de>,
	netfilter-devel@vger.kernel.org, netdev@vger.kernel.org,
	stable@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/2] netfilter: ip_tables: guard ipt_unregister_table_pre_exit against NULL ops
Date: Wed, 29 Apr 2026 23:19:03 -0000	[thread overview]
Message-ID: <177750474339.3016150.13196470704394042910@talencesecurity.com> (raw)
In-Reply-To: <177750472539.3004201.15967003942391945312@talencesecurity.com>

ipt_register_table() adds the table to the per-netns list via
xt_register_table() before assigning the per-net ops copy to
new_table->ops.  If cleanup_net runs during this window,
ipt_unregister_table_pre_exit() finds the table via xt_find_table()
and passes the NULL ops pointer to nf_unregister_net_hooks(), causing
a general protection fault.

Guard against this by checking table->ops before calling
nf_unregister_net_hooks().  If ops is NULL the table is still being
set up; the register path will either complete and register the hooks
normally, or fail and clean up via __ipt_unregister_table().

Fixes: ae689334225f ("netfilter: xtables: Bring back xt_register_table()")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
 net/ipv4/netfilter/ip_tables.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index XXXXXXX..XXXXXXX 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -1795,7 +1795,7 @@ void ipt_unregister_table_pre_exit(struct net *net, const char *name)
 {
 	struct xt_table *table = xt_find_table(net, NFPROTO_IPV4, name);

-	if (table)
+	if (table && table->ops)
 		nf_unregister_net_hooks(net, table->ops, hweight32(table->valid_hooks));
 }


  reply	other threads:[~2026-04-29 23:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 17:56 [PATCH 0/2] netfilter: fix NULL ops race in iptable lazy init Tristan Madani
2026-04-29 17:56 ` [PATCH 1/2] netfilter: ip_tables: allocate hook ops before making table visible Tristan Madani
2026-04-29 17:56 ` [PATCH 2/2] netfilter: ip6_tables: " Tristan Madani
2026-04-29 18:17 ` [PATCH 0/2] netfilter: fix NULL ops race in iptable lazy init Phil Sutter
2026-04-29 21:03 ` Tristan Madani
2026-04-29 23:18 ` [PATCH v2 0/2] netfilter: fix NULL ops dereference " Tristan Madani
2026-04-29 23:19   ` Tristan Madani [this message]
2026-04-30 13:27     ` [PATCH v2 1/2] netfilter: ip_tables: guard ipt_unregister_table_pre_exit against NULL ops Florian Westphal
2026-04-30 21:49       ` Tristan Madani
2026-04-30 22:16         ` Florian Westphal
2026-05-01 20:41           ` Tristan Madani
2026-05-01 22:00             ` Florian Westphal
2026-04-29 23:19   ` [PATCH v2 2/2] netfilter: ip6_tables: guard ip6t_unregister_table_pre_exit " Tristan Madani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=177750474339.3016150.13196470704394042910@talencesecurity.com \
    --to=tristmd@gmail.com \
    --cc=fw@strlen.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox