netfilter: iptables: Fix potential null-ptr-deref in ip6table_nat_table_init().

[ Upstream commit c22921df777de5606f1047b1345b8d22ef1c0b34 ]

ip6table_nat_table_init() accesses net->gen->ptr[ip6table_nat_net_ops.id],
but the function is exposed to user space before the entry is allocated
via register_pernet_subsys().

Let's call register_pernet_subsys() before xt_register_template().

BUG=b/361043348
TEST=presubmit
RELEASE_NOTE=Fixes CVE-2024-42269 in the Linux kernel

cos-patch: security-moderate
Fixes: fdacd57c79b7 ("netfilter: x_tables: never register tables by default")
Change-Id: I8b314a00e166cf0fa0b892fcf19fb9bddb0bdd7b
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Arnav Kansal <rnv@google.com>
Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/79225
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
Reviewed-by: Oleksandr Tymoshenko <ovt@google.com>
Reviewed-by: Kevin Berry <kpberry@google.com>
1 file changed