[libvirt] [PATCH] qemu: Fix serial stub console allocation

Erik Skultety posted 1 patch 6 years, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/921aa74c664d752630bc52bdf8e7180590099ffe.1496056243.git.eskultet@redhat.com
There is a newer version of this series
src/qemu/qemu_hotplug.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[libvirt] [PATCH] qemu: Fix serial stub console allocation
Posted by Erik Skultety 6 years, 11 months ago
When adding the aliased serial stub console, the structure wasn't
properly allocated (VIR_ALLOC instead of virDomainChrDefNew) which then
resulted in SIGSEGV in virDomainChrSourceIsEqual during a serial device
coldplug.

https://bugzilla.redhat.com/show_bug.cgi?id=1434278

Signed-off-by: Erik Skultety <eskultet@redhat.com>
---
 src/qemu/qemu_hotplug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 4a7d99725..34ddb95f8 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1810,7 +1810,7 @@ qemuDomainChrPreInsert(virDomainDefPtr vmdef,
         if (!vmdef->consoles && VIR_ALLOC(vmdef->consoles) < 0)
             return -1;
 
-        if (VIR_ALLOC(vmdef->consoles[0]) < 0) {
+        if (!(vmdef->consoles[0] = virDomainChrDefNew(NULL))) {
             VIR_FREE(vmdef->consoles);
             return -1;
         }
@@ -1841,7 +1841,7 @@ qemuDomainChrInsertPreAllocCleanup(virDomainDefPtr vmdef,
     /* Remove the stub console added by qemuDomainChrPreInsert */
     if (vmdef->nserials == 0 && vmdef->nconsoles == 1 &&
         chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) {
-        VIR_FREE(vmdef->consoles[0]);
+        virDomainChrDefFree(vmdef->consoles[0]);
         VIR_FREE(vmdef->consoles);
         vmdef->nconsoles = 0;
     }
-- 
2.13.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Fix serial stub console allocation
Posted by Peter Krempa 6 years, 11 months ago
On Mon, May 29, 2017 at 13:11:09 +0200, Erik Skultety wrote:
> When adding the aliased serial stub console, the structure wasn't
> properly allocated (VIR_ALLOC instead of virDomainChrDefNew) which then
> resulted in SIGSEGV in virDomainChrSourceIsEqual during a serial device
> coldplug.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1434278
> 
> Signed-off-by: Erik Skultety <eskultet@redhat.com>
> ---
>  src/qemu/qemu_hotplug.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index 4a7d99725..34ddb95f8 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
> @@ -1810,7 +1810,7 @@ qemuDomainChrPreInsert(virDomainDefPtr vmdef,
>          if (!vmdef->consoles && VIR_ALLOC(vmdef->consoles) < 0)
>              return -1;
>  
> -        if (VIR_ALLOC(vmdef->consoles[0]) < 0) {
> +        if (!(vmdef->consoles[0] = virDomainChrDefNew(NULL))) {

With this the code will not call qemuDomainChrSourcePrivateNew in the
qemu driver, which is called everywhere. Are you sure this is okay? If
so please add a comment that xmlopt is not necessary here.

Otherwise it should be simple to pass xmlopt here.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Fix serial stub console allocation
Posted by Erik Skultety 6 years, 10 months ago
On Mon, May 29, 2017 at 02:33:04PM +0200, Peter Krempa wrote:
> On Mon, May 29, 2017 at 13:11:09 +0200, Erik Skultety wrote:
> > When adding the aliased serial stub console, the structure wasn't
> > properly allocated (VIR_ALLOC instead of virDomainChrDefNew) which then
> > resulted in SIGSEGV in virDomainChrSourceIsEqual during a serial device
> > coldplug.
> >
> > https://bugzilla.redhat.com/show_bug.cgi?id=1434278
> >
> > Signed-off-by: Erik Skultety <eskultet@redhat.com>
> > ---
> >  src/qemu/qemu_hotplug.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> > index 4a7d99725..34ddb95f8 100644
> > --- a/src/qemu/qemu_hotplug.c
> > +++ b/src/qemu/qemu_hotplug.c
> > @@ -1810,7 +1810,7 @@ qemuDomainChrPreInsert(virDomainDefPtr vmdef,
> >          if (!vmdef->consoles && VIR_ALLOC(vmdef->consoles) < 0)
> >              return -1;
> >
> > -        if (VIR_ALLOC(vmdef->consoles[0]) < 0) {
> > +        if (!(vmdef->consoles[0] = virDomainChrDefNew(NULL))) {
>
> With this the code will not call qemuDomainChrSourcePrivateNew in the
> qemu driver, which is called everywhere. Are you sure this is okay? If
> so please add a comment that xmlopt is not necessary here.

I hopefully checked all places where we're handling char devices and when
dealing with consoles, we always special case the backcompat serial console 0
in a way where instead of the console's own def, we rather pass the serial[0]'s
data. I'll add a comment as suggested.

Erik

>
> Otherwise it should be simple to pass xmlopt here.


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list