
On Fri, Jan 24, 2020 at 13:40:03 +0100, Michal Privoznik wrote:
Since v5.6.0-48-g270583ed98 we try to cache domain capabilities, i.e. store filled virDomainCaps in a hash table in virQEMUCaps for future use. However, there's a race condition in the way it's implemented. We use virQEMUCapsGetDomainCapsCache() to obtain the pointer to the hash table, then we search the hash table for cached data and if none is found the domcaps is constructed and put into the table. Problem is that this is all done without any locking, so if there are two threads trying to do the same, one will succeed and the other will fail inserting the data into the table.
Also, the API looks a bit fishy - obtaining pointer to the hash table is dangerous.
The solution is to use a mutex that guards the whole operation with the hash table. Then, the API can be changes to return virDomainCapsPtr directly.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1791790
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> ---
diff to v1: - Dropped the callback in favor of passing necessary values as arguments
Reviewed-by: Peter Krempa <pkrempa@redhat.com>