]> 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 11:56:45 +0000 (11:56 +0000)
commit925de19ed7f13e0d12d0b993496d314bab886589
tree9e5f61f2eb4eda3e6069c495329d75747f9f6ddc
parent356bf55e98b9e5d6abbd9a382abfe4e495f72314
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>
src/nwfilter/nwfilter_driver.c
src/nwfilter/nwfilter_gentech_driver.c
src/nwfilter/nwfilter_gentech_driver.h