netfilter: invoke synchronize_rcu after set the _hook_ to NULL
authorLiping Zhang <zlpnobody@gmail.com>
Sat, 25 Mar 2017 00:53:12 +0000 (08:53 +0800)
committerWilly Tarreau <w@1wt.eu>
Thu, 2 Nov 2017 06:16:19 +0000 (07:16 +0100)
commit09ab11ebb7c1f9a66507e382aea696338304f83a
treecfecf202c7bdbc73ef37bba3534ef18908a8d174
parenta77cf1b983190f7cefffb5ff5cf358d7944d04b0
netfilter: invoke synchronize_rcu after set the _hook_ to NULL

commit 3b7dabf029478bb80507a6c4500ca94132a2bc0b upstream.

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 <zlpnobody@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
net/ipv4/netfilter/nf_nat_snmp_basic.c
net/netfilter/nf_conntrack_ecache.c
net/netfilter/nf_conntrack_netlink.c
net/netfilter/nf_nat_core.c
net/netfilter/nfnetlink_cttimeout.c