Skip to content

Commit 3b7dabf

Browse files
Liping Zhangummakynes
authored andcommitted
netfilter: invoke synchronize_rcu after set the _hook_ to NULL
Otherwise, another CPU may access the invalid pointer. For example: CPU0 CPU1 - rcu_read_lock(); - pfunc = _hook_; _hook_ = NULL; - mod unload - - pfunc(); // invalid, panic - rcu_read_unlock(); So we must call synchronize_rcu() to wait the rcu reader to finish. Also note, in nf_nat_snmp_basic_fini, synchronize_rcu() will be invoked by later nf_conntrack_helper_unregister, but I'm inclined to add a explicit synchronize_rcu after set the nf_nat_snmp_hook to NULL. Depend on such obscure assumptions is not a good idea. Last, in nfnetlink_cttimeout, we use kfree_rcu to free the time object, so in cttimeout_exit, invoking rcu_barrier() is not necessary at all, remove it too. Signed-off-by: Liping Zhang <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent f83bf8d commit 3b7dabf

File tree

5 files changed

+7
-1
lines changed

5 files changed

+7
-1
lines changed

net/ipv4/netfilter/nf_nat_snmp_basic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,7 @@ static int __init nf_nat_snmp_basic_init(void)
13041304
static void __exit nf_nat_snmp_basic_fini(void)
13051305
{
13061306
RCU_INIT_POINTER(nf_nat_snmp_hook, NULL);
1307+
synchronize_rcu();
13071308
nf_conntrack_helper_unregister(&snmp_trap_helper);
13081309
}
13091310

net/netfilter/nf_conntrack_ecache.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ void nf_conntrack_unregister_notifier(struct net *net,
290290
BUG_ON(notify != new);
291291
RCU_INIT_POINTER(net->ct.nf_conntrack_event_cb, NULL);
292292
mutex_unlock(&nf_ct_ecache_mutex);
293+
/* synchronize_rcu() is called from ctnetlink_exit. */
293294
}
294295
EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);
295296

@@ -326,6 +327,7 @@ void nf_ct_expect_unregister_notifier(struct net *net,
326327
BUG_ON(notify != new);
327328
RCU_INIT_POINTER(net->ct.nf_expect_event_cb, NULL);
328329
mutex_unlock(&nf_ct_ecache_mutex);
330+
/* synchronize_rcu() is called from ctnetlink_exit. */
329331
}
330332
EXPORT_SYMBOL_GPL(nf_ct_expect_unregister_notifier);
331333

net/netfilter/nf_conntrack_netlink.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,6 +3442,7 @@ static void __exit ctnetlink_exit(void)
34423442
#ifdef CONFIG_NETFILTER_NETLINK_GLUE_CT
34433443
RCU_INIT_POINTER(nfnl_ct_hook, NULL);
34443444
#endif
3445+
synchronize_rcu();
34453446
}
34463447

34473448
module_init(ctnetlink_init);

net/netfilter/nf_nat_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,8 @@ static void __exit nf_nat_cleanup(void)
903903
#ifdef CONFIG_XFRM
904904
RCU_INIT_POINTER(nf_nat_decode_session_hook, NULL);
905905
#endif
906+
synchronize_rcu();
907+
906908
for (i = 0; i < NFPROTO_NUMPROTO; i++)
907909
kfree(nf_nat_l4protos[i]);
908910

net/netfilter/nfnetlink_cttimeout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ static void __exit cttimeout_exit(void)
646646
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
647647
RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, NULL);
648648
RCU_INIT_POINTER(nf_ct_timeout_put_hook, NULL);
649+
synchronize_rcu();
649650
#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
650-
rcu_barrier();
651651
}
652652

653653
module_init(cttimeout_init);

0 commit comments

Comments
 (0)