Hi,

vmd(8) may close file descriptor 0 as not all fd fields are properly
initialized with -1.  While there avoid closing -1.

ok?

bluhm

Index: usr.sbin/vmd/vmd.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/vmd/vmd.c,v
retrieving revision 1.98
diff -u -p -r1.98 vmd.c
--- usr.sbin/vmd/vmd.c  15 Jul 2018 14:36:54 -0000      1.98
+++ usr.sbin/vmd/vmd.c  9 Sep 2018 23:13:50 -0000
@@ -1248,11 +1249,11 @@ vm_register(struct privsep *ps, struct v
        vm->vm_paused = 0;
        vm->vm_user = usr;
 
-       for (i = 0; i < vcp->vcp_ndisks; i++)
+       for (i = 0; i < VMM_MAX_DISKS_PER_VM; i++)
                vm->vm_disks[i] = -1;
-       for (i = 0; i < vcp->vcp_nnics; i++) {
+       for (i = 0; i < VMM_MAX_NICS_PER_VM; i++)
                vm->vm_ifs[i].vif_fd = -1;
-
+       for (i = 0; i < vcp->vcp_nnics; i++) {
                if ((sw = switch_getbyname(vmc->vmc_ifswitch[i])) != NULL) {
                        /* inherit per-interface flags from the switch */
                        vmc->vmc_ifflags[i] |= (sw->sw_flags & VMIFF_OPTMASK);
Index: usr.sbin/vmd/vmm.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/vmd/vmm.c,v
retrieving revision 1.88
diff -u -p -r1.88 vmm.c
--- usr.sbin/vmd/vmm.c  13 Jul 2018 08:42:49 -0000      1.88
+++ usr.sbin/vmd/vmm.c  9 Sep 2018 23:13:04 -0000
@@ -646,20 +646,22 @@ vmm_start_vm(struct imsg *imsg, uint32_t
                        close(vm->vm_disks[i]);
                        vm->vm_disks[i] = -1;
                }
-
                for (i = 0 ; i < vcp->vcp_nnics; i++) {
                        close(vm->vm_ifs[i].vif_fd);
                        vm->vm_ifs[i].vif_fd = -1;
                }
-
-               close(vm->vm_kernel);
-               vm->vm_kernel = -1;
-
-               close(vm->vm_cdrom);
-               vm->vm_cdrom = -1;
-
-               close(vm->vm_tty);
-               vm->vm_tty = -1;
+               if (vm->vm_kernel != -1) {
+                       close(vm->vm_kernel);
+                       vm->vm_kernel = -1;
+               }
+               if (vm->vm_cdrom != -1) {
+                       close(vm->vm_cdrom);
+                       vm->vm_cdrom = -1;
+               }
+               if (vm->vm_tty != -1) {
+                       close(vm->vm_tty);
+                       vm->vm_tty = -1;
+               }
 
                /* read back the kernel-generated vm id from the child */
                if (read(fds[0], &vcp->vcp_id, sizeof(vcp->vcp_id)) !=

Reply via email to