]> git.baikalelectronics.ru Git - kernel.git/commit
netfilter: nfnl_cthelper: fix a race when walk the nf_ct_helper_hash table
authorLiping Zhang <zlpnobody@gmail.com>
Sat, 25 Mar 2017 04:09:15 +0000 (12:09 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 27 Mar 2017 11:47:29 +0000 (13:47 +0200)
commitaeab0bc33c1ccddc7790880fb77edb96cd3a01cb
treed7679fccd772b1c7c9815e8e617566ce7d057181
parentf43d3a3f89e6a5a4b75c2369416e1d4fe44a9a5f
netfilter: nfnl_cthelper: fix a race when walk the nf_ct_helper_hash table

The nf_ct_helper_hash table is protected by nf_ct_helper_mutex, while
nfct_helper operation is protected by nfnl_lock(NFNL_SUBSYS_CTHELPER).
So it's possible that one CPU is walking the nf_ct_helper_hash for
cthelper add/get/del, another cpu is doing nf_conntrack_helpers_unregister
at the same time. This is dangrous, and may cause use after free error.

Note, delete operation will flush all cthelpers added via nfnetlink, so
using rcu to do protect is not easy.

Now introduce a dummy list to record all the cthelpers added via
nfnetlink, then we can walk the dummy list instead of walking the
nf_ct_helper_hash. Also, keep nfnl_cthelper_dump_table unchanged, it
may be invoked without nfnl_lock(NFNL_SUBSYS_CTHELPER) held.

Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nfnetlink_cthelper.c