All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
To: svt-core@virtuozzo.com
Cc: alexander.ivanov@virtuozzo.com, andrey.zhadchenko@virtuozzo.com,
	den@openvz.org, andrey.drobyshev@virtuozzo.com
Subject: [PATCH hci-8.1 / hci-8.2 5/5] vhost-blk: don't leak the vhost fd across cpr-exec
Date: Thu, 19 Nov 2026 19:08:55 +0200	[thread overview]
Message-ID: <20261119170855.472905-6-andrey.drobyshev@virtuozzo.com> (raw)
In-Reply-To: <20261119170855.472905-1-andrey.drobyshev@virtuozzo.com>

The vhost fd is opened with a plain open(), so it has no close-on-exec
flag.  cpr-exec clears that flag only on the fds it preserves and closes
nothing else, so the old fd is carried into the new QEMU, which opens
its own one in realize.  Every cpr-exec thus leaks an fd and a kernel
vhost-blk instance per disk.

Open it with qemu_open(), which sets O_CLOEXEC and reports the errno, and
close it with qemu_close() on the realize error path.

Fixes: 0ff3cb5ff28f ("block: add vhost-blk backend")
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
 hw/block/vhost-blk.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index a9b99ec4bc9..8ecb6a441e4 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -639,9 +639,8 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
         virtio_add_queue(vdev, conf->queue_size, vhost_blk_handle_output);
     }
 
-    s->vhostfd = open("/dev/vhost-blk", O_RDWR);
+    s->vhostfd = qemu_open("/dev/vhost-blk", O_RDWR, errp);
     if (s->vhostfd < 0) {
-        error_setg(errp, "vhost-blk: unable to open /dev/vhost-blk");
         goto cleanup;
     }
 
@@ -667,7 +666,7 @@ cleanup:
     }
     g_free(vqs);
     if (s->vhostfd >= 0) {
-        close(s->vhostfd);
+        qemu_close(s->vhostfd);
         s->vhostfd = -1;
     }
     if (s->backend_fd >= 0) {
-- 
2.47.1


  parent reply	other threads:[~2026-11-19 17:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 17:08 [PATCH hci-8.1 / hci-8.2 0/5] vhost-blk: a bunch of cleanups and small fixes Andrey Drobyshev
2026-11-19 17:08 ` [PATCH hci-8.1 / hci-8.2 1/5] vhost-blk: drop redundant vhost_blk_stop() call Andrey Drobyshev
2026-11-19 17:11   ` no-reply
2026-11-19 17:08 ` [PATCH hci-8.1 / hci-8.2 2/5] vhost-blk: drop dead NULL check of the vm state handler Andrey Drobyshev
2026-11-19 17:11   ` no-reply
2026-11-19 17:08 ` [PATCH hci-8.1 / hci-8.2 3/5] vhost-blk: fix vqs leak on unrealize Andrey Drobyshev
2026-11-19 17:12   ` no-reply
2026-11-19 17:08 ` [PATCH hci-8.1 / hci-8.2 4/5] vhost-blk: stop the device " Andrey Drobyshev
2026-11-19 17:13   ` no-reply
2026-11-19 17:08 ` Andrey Drobyshev [this message]
2026-11-19 17:13   ` [PATCH hci-8.1 / hci-8.2 5/5] vhost-blk: don't leak the vhost fd across cpr-exec no-reply
2026-11-20 12:36 ` [PATCH hci-8.1 / hci-8.2 0/5] vhost-blk: a bunch of cleanups and small fixes Andrey Zhadchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119170855.472905-6-andrey.drobyshev@virtuozzo.com \
    --to=andrey.drobyshev@virtuozzo.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=svt-core@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.