[libvirt] Potential race condition problem

Benjamin Wang (gendwang) gendwang at cisco.com
Sat Sep 29 07:07:15 UTC 2012


Hi,
   Currently virInitialize() method defined in libvirt.c has the following code:
int
virInitialize(void)
{
    if (initialized)
        return 0;

    initialized = 1;

    if (virThreadInitialize() < 0 ||
        virErrorInitialize() < 0 ||
        virRandomInitialize(time(NULL) ^ getpid()) ||
        virNodeSuspendInit() < 0)
        return -1;

......
}

When two threads access virInitialize method, there is no lock for the "initialized" parameter. If the first thread enters this method and set "initialized" to 1,
the second thread could see that "initialized" is 1(Because initialized is not volatiled, I say could). In some situation, before the first thread finishes all the initialization,
the second thread could use some resources which should be initialized in Initialize method.
If you have any comments, please let me know. Thanks!

B.R.
Benjamin Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120929/495f9b93/attachment-0001.htm>


More information about the libvir-list mailing list