[libvirt] [PATCH] qemu: sanity check vhost user FD before passing to QEMU

Daniel P. Berrangé posted 1 patch 4 years, 6 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20190930114002.5922-1-berrange@redhat.com
src/qemu/qemu_command.c | 6 ++++++
1 file changed, 6 insertions(+)
[libvirt] [PATCH] qemu: sanity check vhost user FD before passing to QEMU
Posted by Daniel P. Berrangé 4 years, 6 months ago
Ensure that the FD we're passing to QEMU is actually open, so we get a
sane error message upfront instead of telling QEMU to use a closed FD.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/qemu/qemu_command.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 77470a6037..8c979fdf65 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4704,6 +4704,12 @@ qemuBuildVhostUserChardevStr(const char *alias,
 {
     char *chardev = NULL;
 
+    if (*fd == -1) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Attempt to pass closed vhostuser FD"));
+        return NULL;
+    }
+
     if (virAsprintf(&chardev, "socket,id=chr-vu-%s,fd=%d", alias, *fd) < 0)
         return NULL;
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: sanity check vhost user FD before passing to QEMU
Posted by Michal Privoznik 4 years, 6 months ago
On 9/30/19 1:40 PM, Daniel P. Berrangé wrote:
> Ensure that the FD we're passing to QEMU is actually open, so we get a
> sane error message upfront instead of telling QEMU to use a closed FD.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   src/qemu/qemu_command.c | 6 ++++++
>   1 file changed, 6 insertions(+)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal

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