Skip to content

Commit 1e47ee8

Browse files
committed
netfilter: nf_conntrack: fix BUG_ON while removing nf_conntrack with netns
canqun zhang reported that we're hitting BUG_ON in the nf_conntrack_destroy path when calling kfree_skb while rmmod'ing the nf_conntrack module. Currently, the nf_ct_destroy hook is being set to NULL in the destroy path of conntrack.init_net. However, this is a problem since init_net may be destroyed before any other existing netns (we cannot assume any specific ordering while releasing existing netns according to what I read in recent emails). Thanks to Gao feng for initial patch to address this issue. Reported-by: canqun zhang <canqunzhang@gmail.com> Acked-by: Gao feng <gaofeng@cn.fujitsu.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 4610476 commit 1e47ee8

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎include/net/netfilter/nf_conntrack_core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ extern void nf_conntrack_cleanup(struct net *net);
3131
extern int nf_conntrack_proto_init(struct net *net);
3232
extern void nf_conntrack_proto_fini(struct net *net);
3333

34+
extern void nf_conntrack_cleanup_end(void);
35+
3436
extern bool
3537
nf_ct_get_tuple(const struct sk_buff *skb,
3638
unsigned int nhoff,

‎net/netfilter/nf_conntrack_core.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,11 +1376,12 @@ void nf_conntrack_cleanup(struct net *net)
13761376
synchronize_net();
13771377
nf_conntrack_proto_fini(net);
13781378
nf_conntrack_cleanup_net(net);
1379+
}
13791380

1380-
if (net_eq(net, &init_net)) {
1381-
RCU_INIT_POINTER(nf_ct_destroy, NULL);
1382-
nf_conntrack_cleanup_init_net();
1383-
}
1381+
void nf_conntrack_cleanup_end(void)
1382+
{
1383+
RCU_INIT_POINTER(nf_ct_destroy, NULL);
1384+
nf_conntrack_cleanup_init_net();
13841385
}
13851386

13861387
void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)

‎net/netfilter/nf_conntrack_standalone.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ static int __init nf_conntrack_standalone_init(void)
575575
static void __exit nf_conntrack_standalone_fini(void)
576576
{
577577
unregister_pernet_subsys(&nf_conntrack_net_ops);
578+
nf_conntrack_cleanup_end();
578579
}
579580

580581
module_init(nf_conntrack_standalone_init);

0 commit comments

Comments
 (0)