]> git.proxmox.com Git - mirror_ubuntu-focal-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)
commit83d90219a5df8d950855ce73229a97b63605c317
treed7679fccd772b1c7c9815e8e617566ce7d057181
parent3b7dabf029478bb80507a6c4500ca94132a2bc0b
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