Skip to contentSkip to conversation

libvhost-user: fail SET_LOG_BASE if mmap() of the log fails

PATCH New Kevin Nguyen 1 participant 1 message Nov 22

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libvhost-user: fail SET_LOG_BASE if mmap() of the log fails

If mmap() of the dirty log fd fails, vu_set_log_base_exec() only prints an error, then unmaps the previous log, stores MAP_FAILED in dev->log_table and replies as if the request succeeded. The next request completed with VHOST_F_LOG_ALL set writes through (uint8_t *)-1 and the backend crashes with SIGSEGV.

Leave the existing log untouched and call vu_panic() instead, without sending a reply. Setting log_table to NULL would avoid the crash but silently stop dirty logging, so a migration could complete with missing pages. The SET_LOG_BASE reply has no status field, so dropping the connection is the only way to tell the frontend that logging failed.

Also save errno before close(fd), which may clobber it.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4793

---
 subprojects/libvhost-user/libvhost-user.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.c +4 -1
index df21581033..f47612f9e7 100644
@@ -1159,6 +1159,7 @@ vu_set_log_base_exec(VuDev *dev, VhostUserMsg *vmsg)
     int fd;
     uint64_t log_mmap_size, log_mmap_offset;
     void *rc;
+    int err;
 
     if (vmsg->fd_num != 1 ||
         vmsg->size != sizeof(vmsg->payload.log)) {
@@ -1174,9 +1175,11 @@ vu_set_log_base_exec(VuDev *dev, VhostUserMsg *vmsg)
 
     rc = mmap(0, log_mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
               log_mmap_offset);
+    err = errno;
     close(fd);
     if (rc == MAP_FAILED) {
-        perror("log mmap error");
+        vu_panic(dev, "log mmap error: %s", strerror(err));
+        return false;
     }
 
     if (dev->log_table) {

---
base-commit: 8f66cb79044c370e3813c56ceb7a75a5ca2d0a0e
change-id: 20261121-libvhost-user-log-mmap-6f24f5fc1aab

Best regards,

Signature · 1 line
Kevin Nguyen <[email protected]>