Skip to contentSkip to conversation

spice-char: fix segfault in char_spice_finalize

PATCH In review Li Qiang 3 participants 4 messages Feb 21, 2017 – Mar 2, 2017

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH v2 1/1 spice-char: fix segfault in char_spice_finalize

In 'qemu_chr_open_spice_vmc' if the 'psubtype' is NULL, it will call 'char_spice_finalize'. But as the SpiceChardev is not inserted in the 'spice_chars' list, the 'QLIST_REMOVE' will cause a segfault. Add a detect to avoid it.

---
 spice-qemu-char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
spice-qemu-char.c +4 -1
index 6f46f46..4d1c76e 100644
@@ -215,7 +215,10 @@ static void char_spice_finalize(Object *obj)
     SpiceChardev *s = SPICE_CHARDEV(obj);
 
     vmc_unregister_interface(s);
-    QLIST_REMOVE(s, next);
+
+    if (s->next.le_prev) {
+        QLIST_REMOVE(s, next);
+    }
 
     g_free((char *)s->sin.subtype);
 #if SPICE_SERVER_VERSION >= 0x000c02
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#1 lore raw

Hi

----- Original Message -----

Quoted 6 lines

In 'qemu_chr_open_spice_vmc' if the 'psubtype' is NULL, it will call 'char_spice_finalize'. But as the SpiceChardev is not inserted in the 'spice_chars' list, the 'QLIST_REMOVE' will cause a segfault. Add a detect to avoid it.

Quoted 24 lines
---
 spice-qemu-char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
spice-qemu-char.c +4 -2
index 6f46f46..4d1c76e 100644
@@ -215,7 +215,10 @@ static void char_spice_finalize(Object *obj)
     SpiceChardev *s = SPICE_CHARDEV(obj);
 
     vmc_unregister_interface(s);
-    QLIST_REMOVE(s, next);
+
+    if (s->next.le_prev) {
+        QLIST_REMOVE(s, next);
+    }
 
     g_free((char *)s->sin.subtype);
 #if SPICE_SERVER_VERSION >= 0x000c02
--

1.8.3.1

author
#2 lore raw

Hello Paolo,

Have you queued this patch?

2017-02-21 16:32 GMT+08:00 Marc-André Lureau <[email protected]>:

Quoted 37 lines

Hi

----- Original Message -----

Quoted 6 lines

In 'qemu_chr_open_spice_vmc' if the 'psubtype' is NULL, it will call 'char_spice_finalize'. But as the SpiceChardev is not inserted in the 'spice_chars' list, the 'QLIST_REMOVE' will cause a segfault. Add a detect to avoid it.

Quoted 24 lines
---
 spice-qemu-char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
spice-qemu-char.c +4 -2
index 6f46f46..4d1c76e 100644
@@ -215,7 +215,10 @@ static void char_spice_finalize(Object *obj)
     SpiceChardev *s = SPICE_CHARDEV(obj);
 
     vmc_unregister_interface(s);
-    QLIST_REMOVE(s, next);
+
+    if (s->next.le_prev) {
+        QLIST_REMOVE(s, next);
+    }
 
     g_free((char *)s->sin.subtype);
 #if SPICE_SERVER_VERSION >= 0x000c02
--

1.8.3.1

#3 lore raw
Quoted 3 lines · Li Qiang

Hello Paolo,

Have you queued this patch?

No, I thought Gerd would. Queued now.

Paolo

Quoted 42 lines

2017-02-21 16:32 GMT+08:00 Marc-André Lureau <[email protected] <mailto:[email protected]>>:

    Hi

    ----- Original Message -----
    > In 'qemu_chr_open_spice_vmc' if the 'psubtype' is NULL, it will
    > call 'char_spice_finalize'. But as the SpiceChardev is not inserted
    > in the 'spice_chars' list, the 'QLIST_REMOVE' will cause a segfault.
    > Add a detect to avoid it.
    >
    > Signed-off-by: Li Qiang <[email protected] <mailto:[email protected]>>

    Reviewed-by: Marc-André Lureau <[email protected]
    <mailto:[email protected]>>

    > ---
    >  spice-qemu-char.c | 5 ++++-
    >  1 file changed, 4 insertions(+), 1 deletion(-)
    >
    > diff --git a/spice-qemu-char.c b/spice-qemu-char.c
    > index 6f46f46..4d1c76e 100644
    > --- a/spice-qemu-char.c
    > +++ b/spice-qemu-char.c
    > @@ -215,7 +215,10 @@ static void char_spice_finalize(Object *obj)
    >      SpiceChardev *s = SPICE_CHARDEV(obj);
    >
    >      vmc_unregister_interface(s);
    > -    QLIST_REMOVE(s, next);
    > +
    > +    if (s->next.le_prev) {
    > +        QLIST_REMOVE(s, next);
    > +    }
    >
    >      g_free((char *)s->sin.subtype);
    >  #if SPICE_SERVER_VERSION >= 0x000c02
    > --
    > 1.8.3.1
    >
    >