[libvirt] [PATCH] Avoid segv if ncf_init fails

If ncf_init() fails, it takes responsibility to call ncf_close() when appropriate. Having libvirt call it results in a double close, which ends up segv'ing. --- src/interface/netcf_driver.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-) diff --git a/src/interface/netcf_driver.c b/src/interface/netcf_driver.c index b5c3664..c44ba62 100644 --- a/src/interface/netcf_driver.c +++ b/src/interface/netcf_driver.c @@ -142,10 +142,6 @@ static virDrvOpenStatus interfaceOpenInterface(virConnectPtr conn, return 0; netcf_error: - if (driverState->netcf) - { - ncf_close(driverState->netcf); - } virMutexDestroy (&driverState->lock); mutex_error: VIR_FREE(driverState); -- 1.6.5.15.gc274d

On Fri, Oct 23, 2009 at 03:13:17PM -0400, Laine Stump wrote:
If ncf_init() fails, it takes responsibility to call ncf_close() when appropriate. Having libvirt call it results in a double close, which ends up segv'ing.
Hmm, it would be good if ncf_init set the passed in pointer to NULL when it failed, then your existing cleanup check would have been safe.
--- src/interface/netcf_driver.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/src/interface/netcf_driver.c b/src/interface/netcf_driver.c index b5c3664..c44ba62 100644 --- a/src/interface/netcf_driver.c +++ b/src/interface/netcf_driver.c @@ -142,10 +142,6 @@ static virDrvOpenStatus interfaceOpenInterface(virConnectPtr conn, return 0;
netcf_error: - if (driverState->netcf) - { - ncf_close(driverState->netcf); - } virMutexDestroy (&driverState->lock); mutex_error: VIR_FREE(driverState); --
ACK Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Fri, 2009-10-23 at 20:31 +0100, Daniel P. Berrange wrote:
On Fri, Oct 23, 2009 at 03:13:17PM -0400, Laine Stump wrote:
If ncf_init() fails, it takes responsibility to call ncf_close() when appropriate. Having libvirt call it results in a double close, which ends up segv'ing.
Hmm, it would be good if ncf_init set the passed in pointer to NULL when it failed, then your existing cleanup check would have been safe.
Agreed - that that doesn't happen was an oversight. I'll fix that. David

On Tue, 2009-10-27 at 14:23 +0000, David Lutterkort wrote:
On Fri, 2009-10-23 at 20:31 +0100, Daniel P. Berrange wrote:
On Fri, Oct 23, 2009 at 03:13:17PM -0400, Laine Stump wrote:
If ncf_init() fails, it takes responsibility to call ncf_close() when appropriate. Having libvirt call it results in a double close, which ends up segv'ing.
Hmm, it would be good if ncf_init set the passed in pointer to NULL when it failed, then your existing cleanup check would have been safe.
Agreed - that that doesn't happen was an oversight. I'll fix that.
Spoke too soon - ncf_init returns -2 when allocations fail so badly that we can't even allocate the struct netcf (in which case ncf_init should reset the pointer to NULL, but doesn't - that's the bug that needs to be addressed) It can also return -1 for all kinds of other failures; in that case you have a struct netcf that's good enough to pass to ncf_error to get more error details. David

On 10/27/2009 10:28 AM, David Lutterkort wrote:
On Tue, 2009-10-27 at 14:23 +0000, David Lutterkort wrote:
On Fri, 2009-10-23 at 20:31 +0100, Daniel P. Berrange wrote:
On Fri, Oct 23, 2009 at 03:13:17PM -0400, Laine Stump wrote:
If ncf_init() fails, it takes responsibility to call ncf_close() when appropriate. Having libvirt call it results in a double close, which ends up segv'ing.
Hmm, it would be good if ncf_init set the passed in pointer to NULL when it failed, then your existing cleanup check would have been safe.
Agreed - that that doesn't happen was an oversight. I'll fix that.
Spoke too soon - ncf_init returns -2 when allocations fail so badly that we can't even allocate the struct netcf (in which case ncf_init should reset the pointer to NULL, but doesn't - that's the bug that needs to be addressed)
It can also return -1 for all kinds of other failures; in that case you have a struct netcf that's good enough to pass to ncf_error to get more error details.
Hmm. I guess I should setup my error scenario again and see if it was returning -2 - it was pretty simple to reproduce, I would just run libvirtd as non-root and connect to it with virsh. If it was returning -2. I'll send a new patch for libvirt that, if the return is -1, retrieves the extra error stuff and reports it, then does ncf_close().
David
participants (3)
-
Daniel P. Berrange
-
David Lutterkort
-
Laine Stump