Commit Graph

558 Commits

Author SHA1 Message Date
dv 94c519221d Fix typo in comment about pledges (send -> sendfd).
No functional change.
2022-11-06 11:54:08 +00:00
dv 0fef3eb39e vmd(8): remove unfinished user accounting.
User accounting and enforcement was never finished. tedu the thing
until someone wants to pick it up and finish it.

Originally found by Matthew Martin.

ok mlarkin@, kn@. input from tb@.
2022-10-31 14:02:11 +00:00
jmc 438512a5e8 some macro fixes, mostly Cm -> Ic;
from josiah frentsos
2022-10-14 06:43:26 +00:00
jmc 755afa6321 macro tweaks; from josiah frentsos
ok deraadt
2022-09-24 15:22:59 +00:00
martijn f94ca20ec5 Add (partial) support for agentx in vmd.
Metrics can be found under mib-2.236 and VM-MIB (RFC7666).

Stress tested by and happy noises from Mischa Peters
OK dv@
2022-09-13 10:28:19 +00:00
cheloha f53d796ad2 vmd(8): compute i8254 read-back command latch from singular timestamp
The intent of the i8254 read-back command is (most likely) to permit
simultaneously latching two or three counters at once along with their
statuses.

To simulate this, we should compute olatch from one timestamp per
read-back command, not one timestamp per counter.

Improved with a tweak by dv@.

Link: https://marc.info/?l=openbsd-tech&m=166213670605453&w=2

ok dv@ mlarkin@
2022-09-02 21:33:51 +00:00
dv 33de4f9469 vmm(4): send all port io emulation to userland
Simplify things by sending any io exits from IN/OUT instructions
to userland instead of trying to emulate anything in the kernel.
vmm was sending most pertinent exits to vmd anyways, so this
functionally changes little.

An added benefit is this solves an issue reported by tb@ where i386
OpenBSD guests would probe for a pc keyboard repeatedly and cause
excessive vm exits. (The emulation in vmm was not properly handling
these port reads.)

While here, make the assignment of the VEI_DIR_{IN,OUT} enum values
not assume the underlying integer the compiler may assign.

ok mlarkin@
2022-09-01 22:01:40 +00:00
dv 18126f0e25 Initial support for mmio assist for vmm(4)
Provide the basic information required for a userland assist in
emulating instructions touching mmio regions, sending as much
information as is provided by the host hardware.

No decode or assist provided at the moment by vmd(8).

ok mlarkin@
2022-08-30 17:09:21 +00:00
stsp 3aa949fec5 SWITCH section in ifconfig(8) no longer exists; point people at VEB instead 2022-08-04 11:50:51 +00:00
dv d4e7144e28 vmd(8): fix off by one in vm memory range check
When inspecting if a gpa falls into a known memory range, vmd was
considering it valid 1 byte past the end resulting in selecting the
wrong starting range for the search.

ok mlarkin@
2022-06-29 17:39:54 +00:00
dv b1ba853453 vmd: create a copy of bios at 4g boundary
Newer Linux kernels call into the bios to perform a reboot and our
version of SeaBIOS assumes there's a "copy" of the bios ending at
4g. When SeaBIOS reads from this area, since vmd doesn't perform
mmio yet, guests terminate with an unhandled fault.

Carve out some space ending at 4g and copy the bios there. Technically
we could load garbage there, but give SeaBIOS what it wants for
now.

ok mlarkin@
2022-06-26 06:49:09 +00:00
dv 4a1c7b02a3 use correct logging or error calls
ftruncate sets errno, so use fatal() and not fatalx().

Checking for under-reads of read(2) isn't going to set errno so
use errx().

ok abieber@
2022-05-20 22:06:47 +00:00
dv 2eec084373 fix typos in comments
No functional change. Pointed out by Martin Vahlensieck.
2022-05-13 16:46:34 +00:00
dv 7933afb4f7 vmd: fix rebooting a received vm
Rebooting a received vm resulted in vmd(8) exiting as a result of
flawed state tracking in the parent process.

When stopping a vm, clear the VM_RECEIVE_STATE flag. When starting
a vm, make sure the parent process collapses any existing memory
ranges after the vm is sent to the vmm process (responsible for
launching the vm).

ok mlarkin@
2022-05-08 14:44:54 +00:00
dv ead1b14692 vmctl(8)/vmd(8): convert disk sizes from MB to bytes
Continue converting other parts to storing data in bytes instead
of MB. In this case, the logic for disk sizes was being scaled.

This fixes issues reported by Martin Vahlensieck where vmctl could
no longer create disks larger than 7 MiB after previous commits to
change storing memory sizes as bytes.

While this keeps the vm memory limit check in vmctl's size parser,
it skips the limit check for disks. The error messages adjust
accordingly and this removes the double error message logging.

Update comments and function types accordingly.

ok marlkin@
2022-05-04 23:17:25 +00:00
dv e545c54c39 vmm/vmd/vmctl: standardize memory units to bytes
At different points in the vm lifecycle vmm(4), vmctl(8), and vmd(8)
refer to a vm's memory range sizes in either bytes or megabytes.
This is needlessly complex.

Switch to using bytes everywhere and adjust types and constants
accordingly. While this makes it possible to specify vm's with
memory in fractions of megabytes, the logic requiring whole
megabyte values remains.

Feedback from deraadt@, mlarkin@, and Matthew Martin.

ok mlarkin@
2022-05-03 21:39:18 +00:00
dv ed010ab236 Free vm_info_result in error paths.
vmd(8)'s get_info_vm() mallocs vm_info_result structs when using
the VMM_IOC_INFO ioctl. The error paths failed to free the resulting
objects.

Diff adapted from suggestions by jca@. ok mlarkin@.
2022-04-10 19:36:58 +00:00
dv 30dd31d210 Resolve clang unused-but-set warnings in vmd's vioscsi.c.
A few of the vioscsi functions have debug logging in DPRINTF's and
are the only use of some declared variables. This tucks any debug-only
variables into the DPRINTF or behind an #if DEBUG.

ok from deraadt@ caveated I don't add code before any declarations.
2022-03-07 14:17:47 +00:00
dv fbbcf6cd7f vmd(8): gracefully handle hitting data limits when starting a vm
With recent changes to login.conf(5) to restrict daemon datasize
to a finite value, users can now hit resource limits when attempting
to start a vm.

This change fixes the error path when hitting the limit. vmd(8)
will no longer abort and memory error messages are relayed to the
user.

While here, address potential under-reads/writes using atomicio
when relaying data between the child vm process and vmd's vmm
process.

Original diff from tedu@. OK mlarkin@.
2022-03-01 21:46:19 +00:00
guenther 6668a73640 When it's the possessive of 'it', it's spelled "its", without the
apostrophe.
2022-01-28 06:33:26 +00:00
mlarkin 418ce7a985 vmd: Remove a warning about non-32KHz timebases
Remove a warning that has outlived its usefulness.

From Brian Conway, thanks.
2022-01-15 23:39:11 +00:00
jmc 565a3eb61f adjust Xr for fw_update to section 8;
ok afresh sthen deraadt
2022-01-05 17:39:24 +00:00
claudio ec4b63a0df Try to handle possible vm_register() failures and return an error back
to the caller instead of most probably crashing because of a NULL pointer
access. This fixes also another -Wunused-but-set-variable warning.
OK benno@ dv@
2022-01-04 15:25:05 +00:00
claudio 79ac00b5ed Remove unused imsg type IMSG_VMDOP_RECEIVE_VM_RESPONSE.
OK benno@ dv@
2022-01-04 15:22:53 +00:00
claudio 0c8271c801 Another -Wunused-but-set-variable fix.
Based on input from dv@
2022-01-04 15:21:40 +00:00
claudio 98142e86aa Fix some simple -Wunused-but-set-variable warnings.
OK benno@ dv@
2022-01-04 15:18:44 +00:00
claudio 3227aa04a0 Add back support for -B net -b bsd.rd which emulates a PXE install and
results in an autoinstall. This can be used to quickly create new OpenBSD
installs.
OK dv@
2021-12-30 08:12:23 +00:00
deraadt e16a722a8a including sys/cdefs.h manually started as a result of netbsd trying to
macro-build a replacement for sccsid, and was done without any concern
for namespace damage.  Unfortunately this practice started infecting
other code as others were unaware they didn't need the file.
ok millert guenther
2021-12-13 18:28:39 +00:00
deraadt 24fb43d058 mostly avoid sys/param.h with a local nitems()
ok mlarkin
2021-11-29 05:17:35 +00:00
claudio 6126134de5 switch(4) is being retired, sthen@ already removed the bits in the code
adjust the man page as well.
OK sthen@ kn@ patrick@
2021-11-11 09:33:36 +00:00
sthen 40d1acf556 Remove switch(4) pieces, feedback/missing piece millert@ ok claudio@ mlarkin@ 2021-11-10 20:49:04 +00:00
jan 2bbc068ab0 Fix bootorder string for disk
ok mlarkin@
2021-11-05 10:18:50 +00:00
jan 49d91399e2 Fix broken "boot device cdrom" feature after a fix in seabios.
seabios fixes wrong LUN handling upstream.  Thus, we have to adapt the LUN
of our cdrom bootorder string, too.

ok brynet@, dv@
2021-11-04 17:50:05 +00:00
naddy 08f6ba1906 Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments.  Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@
2021-10-15 15:01:27 +00:00
dv 1b25072036 remove unused functions and cleanup vmd.h
Discussed with mlarkin@. These functions were implemented but never
used. While in vmd.h, fix the order to match current vmd(8) reality.
2021-09-01 11:08:21 +00:00
dv 321f3ee39b Mask viornd descriptor value to prevent out of bound reads.
viornd did not mask the descriptor value in the avialable ring
allowing guest values to read past the end of the descriptor table.

While here, change fatal to fatalx because errno is not set.

Reported by Ilja van Sprundel

ok mlarkin@
2021-08-29 18:01:32 +00:00
dv 1668094347 mask next descriptor value and fix chunk_size calculation
Guest can cause out of bounds read with a malformed descriptor. In same
loop, also fix a chunk size calculation.

Reported by Ilja van Sprundel.

ok mlarkin@
2021-08-29 12:17:38 +00:00
dv 802c227e3a check for null vioblk info
If {c,m}alloc fail, info could be NULL and result in NULL deref.

Reported by Ilja van Sprundel.

ok mlarkin@
2021-08-29 11:41:27 +00:00
dv 1daeb7baba correct device status write size
Reported by Ilja van Sprundel.

ok mlarkin@
2021-08-29 11:14:27 +00:00
dv 6571ecea4f remove old descriptor dump function
Used originally to aid dev. Unneeded.

ok mlarkin@
2021-08-29 11:09:05 +00:00
dv 2d54575624 vmd(8): remove invalid errno values from config_setvm
Refactor config_setvm to directly return error code on failure
instead of returning -1 and setting errno. It was setting unsupported
values not defined in <errno.h>.

OK mlarkin@
2021-07-18 11:55:45 +00:00
dv 39d683862c vmd(8): simplify vcpu logic, removing uart & vionet reads
Remove legacy state handling on the ns8250 and virtio network devices
originally put in place before using libevent for async device
events. The vcpu thread doesn't need to process device data as it is
handled by the libevent thread.

This has the benefit of simplifying some of the message passing
between threads introduced to the ns8250 uart since both the vcpu
and libevent threads were processing read events.

No functional change intended. Tested by many, including abieber@,
weerd@, Mischa Peters, and Matthias Schmidt. (Thanks.)

OK mlarkin@
2021-07-16 16:21:22 +00:00
dv 6c31e103a2 vmd(8): support variable length vionet rx descriptor chains
The original implementation of the virtio network device assumed a
driver would only provide a 2-descriptor chain for receiving packets.
The virtio spec allows for variable length chains and drivers, in
practice, construct them when they use a sufficiently large MTU.

This change lets the device use variable length chains provided by
the driver, thus allowing for drivers to set an MTU up to the
underlying host-side tap(4)'s limit of TUNMRU (16384).

Size limitations are now enforced on both tx and rx-side dropping
anything violating the underlying tap(4) min and max limits.

More work is needed to increase the read(2) buffer in use by vmd
to prevent packet truncation.

OK mlarkin@
2021-06-21 02:38:18 +00:00
dv a47d50ec87 vmd(8): handle VIRTIO_BLK_T_GET_ID, check descriptor r/w flags
Linux guests like to issue VIRTIO_BLK_T_GET_ID commands in attempts
to read the device serial number. It's not part of the virtio spec,
but has been part of QEMU and Bhyve for multiple years. It will be
landing in the next version of virtio (1.2), so this stubs out
handling for the request type. The added benefit is it helps squelch
log noise from Linux guests.

For now, no serial number is set and the request status is set to
VIRTIO_BLK_S_UNSUPP to tell the driver we don't support it.

While here, swap the response to VIRTIO_BLK_T_FLUSH{,_OUT} to be
also returning VIRTIO_BLK_S_UNSUPP. It's not negotiated nor
implemented. Lastly, add checks for validating the vioblk device
is only reading/writing descriptors with approrpriate read/write-only
flags per the virtio spec.

With input from claudio@, OK mlarkin@
2021-06-17 22:03:33 +00:00
dv 6eb4c859e9 cleanup vmd(8) includes and header files
Lots of organic growth other the years lead to unnecessary includes
(proc.h everywhere) and odd dependencies between header files. This
cleans things up a bit to help with upcoming cleanup around dhcp
code.

No functional change.

"go for it" mlarkin@
2021-06-16 16:55:02 +00:00
claudio 86bbdb7473 Filter out packets that are not IPv4. This code came from dhcp programs
where this filtering was done in bpf but here vmd needs to make sure to
not look at non IPv4 packets.
OK florian@ and dv@
2021-06-15 10:38:53 +00:00
dv 53f59f88a9 vmd(8): deduplicate vioblk command logic
No need for each case in the switch block to have the same logic
for updating the used ring and writing the state back to the guest.
Move it outside the switch. No functional change.

ok mlarkin@
2021-06-11 21:46:00 +00:00
dv 540e29f5c7 vmctl(8)/vmd(8): communicate TERMINATE_VM_EVENT imsgs on vm stop.
Instead of translating imsg types, update vmclt(8) to handle receiving
IMSG_VMDOP_TERMINATE_VM_EVENT messages on vm termination.

This finishes the work previously committed for supporting multiple
waiters or the cancellation of a client waiting on a vm shutdown.
vmd no longer needs to translate an IMSG_VMDOP_TERMINATE_VM_RESPONSE
into an *_EVENT.

ok mlarkin@
2021-06-10 19:50:05 +00:00
dv 067df31655 vmd(8): malicious dhcp packets on local ifs can cause stack overflows
A sufficiently large dhcp packet can cause a stack overflow in vmd's
internal dhcp server used for providing ip addresses to local guest
interfaces. (This does not affect non-local interfaces.)

The primary changes drop larger packets and change the memory copying
logic to use a compile-time constant. The dhcp option processing
also additional prevention for out of bound reads.

While here, improve construction of the dhcp response's hostname
handling to guard against overflowing the response dhcp options.

Vulnerability reported by Maxime Villard.

ok claudio@
2021-06-08 14:37:48 +00:00
dv 6153f04ab7 vmd(8): allow locking a randomly assigned lladdr
Provide a default value of a zero'd mac address so a user can still
specify the interface should be "locked" (only transmitting ethernet
packets with a matching source address). vmd will assign a random
address at vm launch.

As an example, this is now valid:

  vm "name" {
    interface {
      locked lladdr
    }
    ...
  }

From Martin Vahlensieck
ok claudio@
2021-06-02 14:40:46 +00:00