]> git.ipfire.org Git - thirdparty/libvirt.git/commit
Add a mutex to serialize updates to firewall
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 22 Jan 2014 18:13:30 +0000 (18:13 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 10 Mar 2014 13:02:20 +0000 (13:02 +0000)
commitb7d051af2084f2880a638a680e0d2a7b595f1e64
tree199be84e933a61470187a487b54432ffff1a7a64
parent1439dddbfb5d08046e0d2f29f322f067cafff550
Add a mutex to serialize updates to firewall

The nwfilter conf update mutex previously serialized
updates to the internal data structures for firewall
rules, and updates to the firewall itself. The latter
was recently turned into a read/write lock, and filter
instantiation allowed to proceed in parallel. It was
believed that this was ok, since each filter is created
on a separate iptables/ebtables chain.

It turns out that there is a subtle lock ordering problem
on virNWFilterObjPtr instances. __virNWFilterInstantiateFilter
will hold a lock on the virNWFilterObjPtr it is instantiating.
This in turn invokes virNWFilterInstantiate which then invokes
virNWFilterDetermineMissingVarsRec which then invokes
virNWFilterObjFindByName. This iterates over every single
virNWFilterObjPtr in the list, locking them and checking their
name. So if 2 or more threads try to instantiate a filter in
parallel, they'll all hold 1 lock at the top level in the
__virNWFilterInstantiateFilter method which will cause the
other thread to deadlock in virNWFilterObjFindByName.

The fix is to add an exclusive mutex to serialize the
execution of __virNWFilterInstantiateFilter.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 925de19ed7f13e0d12d0b993496d314bab886589)

Conflicts:
src/nwfilter/nwfilter_gentech_driver.c
src/nwfilter/nwfilter_driver.c
src/nwfilter/nwfilter_gentech_driver.c
src/nwfilter/nwfilter_gentech_driver.h