Skip to content

Commit c22921d

Browse files
q2venummakynes
authored andcommitted
netfilter: iptables: Fix potential null-ptr-deref in ip6table_nat_table_init().
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(). Fixes: fdacd57 ("netfilter: x_tables: never register tables by default") Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 5830aa8 commit c22921d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

net/ipv6/netfilter/ip6table_nat.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,27 @@ static struct pernet_operations ip6table_nat_net_ops = {
147147

148148
static int __init ip6table_nat_init(void)
149149
{
150-
int ret = xt_register_template(&nf_nat_ipv6_table,
151-
ip6table_nat_table_init);
150+
int ret;
152151

152+
/* net->gen->ptr[ip6table_nat_net_id] must be allocated
153+
* before calling ip6t_nat_register_lookups().
154+
*/
155+
ret = register_pernet_subsys(&ip6table_nat_net_ops);
153156
if (ret < 0)
154157
return ret;
155158

156-
ret = register_pernet_subsys(&ip6table_nat_net_ops);
159+
ret = xt_register_template(&nf_nat_ipv6_table,
160+
ip6table_nat_table_init);
157161
if (ret)
158-
xt_unregister_template(&nf_nat_ipv6_table);
162+
unregister_pernet_subsys(&ip6table_nat_net_ops);
159163

160164
return ret;
161165
}
162166

163167
static void __exit ip6table_nat_exit(void)
164168
{
165-
unregister_pernet_subsys(&ip6table_nat_net_ops);
166169
xt_unregister_template(&nf_nat_ipv6_table);
170+
unregister_pernet_subsys(&ip6table_nat_net_ops);
167171
}
168172

169173
module_init(ip6table_nat_init);

0 commit comments

Comments
 (0)