[PATCH] qemu: fd: Fix monitor usage of qemuFDPassDirectGetPath

Peter Krempa posted 1 patch 1 year, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/c949da683e81a31b94a53cf53adc2bc6b54e3238.1654264452.git.pkrempa@redhat.com
src/qemu/qemu_fd.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
[PATCH] qemu: fd: Fix monitor usage of qemuFDPassDirectGetPath
Posted by Peter Krempa 1 year, 11 months ago
We need to use the 'name' variable and just overwrite it with the FD
number when FDs are passed on the monitor. Otherwise we will read NULL
path if the FD is accessed before being passed on the monitor. The idea
of this helper is to simplify the monitor code so it would be
counterproductive to have other behaviour.

Fixes the following symptom:

 $ virsh attach-interface cd network default --model virtio
 error: Failed to attach interface
 error: internal error: unable to execute QEMU command 'netdev_add': File descriptor named '(null)' has not been found

Fixes: bca9047906fd73fd30f275dd45b64998fbbcf6de
Resolves: https://gitlab.com/libvirt/libvirt/-/issues/318
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2092856
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_fd.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_fd.c b/src/qemu/qemu_fd.c
index 6311161657..51a8133fde 100644
--- a/src/qemu/qemu_fd.c
+++ b/src/qemu/qemu_fd.c
@@ -235,7 +235,6 @@ qemuFDPassGetPath(qemuFDPass *fdpass)

 struct _qemuFDPassDirect {
     int fd;
-    char *path;
     char *name;

     bool passed; /* passed to qemu via monitor */
@@ -251,7 +250,6 @@ qemuFDPassDirectFree(qemuFDPassDirect *fdpass)

     VIR_FORCE_CLOSE(fdpass->fd);
     g_free(fdpass->name);
-    g_free(fdpass->path);
     g_free(fdpass);
 }

@@ -295,7 +293,8 @@ qemuFDPassDirectTransferCommand(qemuFDPassDirect *fdpass,
         return;

     virCommandPassFD(cmd, fdpass->fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
-    fdpass->path = g_strdup_printf("%d", fdpass->fd);
+    g_free(fdpass->name);
+    fdpass->name = g_strdup_printf("%d", fdpass->fd);
     fdpass->fd = -1;
 }

@@ -318,7 +317,6 @@ qemuFDPassDirectTransferMonitor(qemuFDPassDirect *fdpass,
     if (qemuMonitorSendFileHandle(mon, fdpass->name, fdpass->fd) < 0)
         return -1;

-    fdpass->path = g_strdup(fdpass->name);
     VIR_FORCE_CLOSE(fdpass->fd);
     fdpass->passed = true;

@@ -358,5 +356,5 @@ qemuFDPassDirectGetPath(qemuFDPassDirect *fdpass)
     if (!fdpass)
         return NULL;

-    return fdpass->path;
+    return fdpass->name;
 }
-- 
2.35.3
Re: [PATCH] qemu: fd: Fix monitor usage of qemuFDPassDirectGetPath
Posted by Ján Tomko 1 year, 11 months ago
On a Friday in 2022, Peter Krempa wrote:
>We need to use the 'name' variable and just overwrite it with the FD
>number when FDs are passed on the monitor. Otherwise we will read NULL
>path if the FD is accessed before being passed on the monitor. The idea
>of this helper is to simplify the monitor code so it would be
>counterproductive to have other behaviour.
>
>Fixes the following symptom:
>
> $ virsh attach-interface cd network default --model virtio
> error: Failed to attach interface
> error: internal error: unable to execute QEMU command 'netdev_add': File descriptor named '(null)' has not been found
>
>Fixes: bca9047906fd73fd30f275dd45b64998fbbcf6de
>Resolves: https://gitlab.com/libvirt/libvirt/-/issues/318
>Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2092856
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/qemu/qemu_fd.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano