bhyve: add basic tests
Add sanity checks for:
* bhyve -l help
* bhyve -s help
* bhyve -o help
* bhyve -o config.dump=1
Validate that commands run successfully, have no duplicates,
sorted where applicable, and the dumped configuration can be consumed
again with the -k option.
Reviewed by: ngie, Osvaldo Janeri Filho <ojanerif at amd.com>
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D60981
Revert "mmc: Allow HS400ES with HS400 at a single I/O voltage"
llm-postcr reports multiple issues with this as-is.
This reverts commit e70868afa99d40087363d6478488a9904459be71.
proc: Fix an execve race in proc_getauxv()
The SV_PROC_FLAG(p, SV_ILP32) test in proc_getauxv() is racy once we
unblock execve, resulting in a potential OOB read of heap memory.
Postpone the proc_vmspace_unref() call until after we've calculated the
auxv size.
Reviewed by: kib
Reported by: Albert E. of Metnir
Fixes: a22c044cce41 ("kern_proc.c: ensure stability of the vmspace we read the strings from")
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D62107
dhclient: Fix validation of IP and UDP lengths
decode_udp_ip_header() assumed that the sizes recorded in the IP and UDP
headers are valid, but if not, OOB memory accesses are possible.
Add checks, and use unsigned types for buffer sizes and offsets.
Add regression tests.
Reported by: Brendan Davidson <binary141 at gmail.com>
Reviewed by: emaste
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D62120
iflib: Drain the receive watchdog callout on detach
Nothing stops ifr_watchdog when an interface goes away. If it is armed
when the interface detaches, the callout stays on the callout wheel
after iflib_rx_structures_free() has freed the queue containing it,
corrupting the wheel, or fires and enqueues a task that has already been
detached.
The window is small: the callout is armed for one tick, only when a
receive buffer refill fails, and the detach has to follow right after.
The former iflib_pseudo_deregister() drained the callout until
102540192c71 moved its teardown into iflib_tqg_detach() without the
drain, and iflib_device_deregister() never did. Drain it in
iflib_tqg_detach(). The callout cannot be rearmed by then:
_task_fn_rx() only arms it while the interface is running, and
iflib_device_deregister() has already called iflib_stop(), which clears
the running state and then drains the receive tasks.
[5 lines not shown]
iichid(4): Expect I2C address provided by iicbus(4) to be in 8-bit
format rather than in 7-bit to chase "acpi_iicbus: shift the ACPI slave
address into the form iicbus(4) stores" commit.
acpi_iicbus: shift the ACPI slave address into the form iicbus(4) stores
An I2cSerialBus resource carries the 7-bit slave address, but iicbus(4)
stores and passes around the 8-bit form -- ofw_iicbus(4) shifts a device-tree
"reg" value for the same reason, and the AML address space handler in this
file already shifts before issuing a transfer. Without the shift every
device enumerated from ACPI is addressed at half its address, and a driver
that probes by reading a register sees no ack.
Reviewed by: wulf
Differential Revision: https://reviews.freebsd.org/D60062
powerpc64: Fix disappearing low memory on radix MMU systems (POWER9)
The FreeBSD radix implementation piggybacks on the physical memory
allocation function from the HPT implementation, but did not share
the same state information for number of physical memory ranges.
This led to a situation where the HPT physical memory allocator
would attempt to shift the physical memory ranges in the shared
range table, but would use the wrong number of entries, thus
overwriting the large segment of low memory that should have been
available for e.g. 32-bit DMA.
Incorrect physical memory map:
real memory = 33997058048 (32422 MB)
available KVA = 34359619583 (32767 MB)
Physical memory chunk(s):
0x0000000000003000 - 0x0000000000002fff, 0 bytes (0 pages)
0x000000000000e000 - 0x000000000000ffff, 8192 bytes (2 pages)
0x0000000000094000 - 0x0000000000ffffff, 16171008 bytes (3948 pages)
[28 lines not shown]
powerpc64: Fix disappearing low memory on radix MMU systems (POWER9)
The FreeBSD radix implementation piggybacks on the physical memory
allocation function from the HPT implementation, but did not share
the same state information for number of physical memory ranges.
This led to a situation where the HPT physical memory allocator
would attempt to shift the physical memory ranges in the shared
range table, but would use the wrong number of entries, thus
overwriting the large segment of low memory that should have been
available for e.g. 32-bit DMA.
Incorrect physical memory map:
real memory = 33997058048 (32422 MB)
available KVA = 34359619583 (32767 MB)
Physical memory chunk(s):
0x0000000000003000 - 0x0000000000002fff, 0 bytes (0 pages)
0x000000000000e000 - 0x000000000000ffff, 8192 bytes (2 pages)
0x0000000000094000 - 0x0000000000ffffff, 16171008 bytes (3948 pages)
[28 lines not shown]
ibcore: Avoid quadratic uverbs ID allocation
FreeBSD's LinuxKPI xa_alloc() starts at index zero for each allocation.
The per-file uverbs XArray holds protection domains, completion queues,
queue pairs, and memory regions. As the number of live objects grows,
each new handle probes all occupied lower IDs, making large connection
setups increasingly expensive.
Keep the optimization in the OFED uverbs caller: track the next candidate
ID in ib_uverbs_file, reserve under the XArray lock, and advance the
cursor on success. On a collision, search forward and wrap through the
32-bit handle space. Existing lookup, commit, erase, and destruction
paths are unchanged. Freed lower IDs are reused after wraparound.
Signed-off-by: Lewandowski, Rafal <rafal.lewandowski at intel.com>
Reviewed by: bartosz.sobczak_intel.com, kib
MFC after: 2 weeks
Sponsored by: Intel Corporation
Differential Revision: https://reviews.freebsd.org/D60405
pf: fix sctp normalisation cleanup
If we fail to allocate the dst scrub structure we should free the src
one too, but we passed src rather than src->scrub.
Reported by: llm-postcr
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit e53632189f09d7b5c6664fef51cbe4429e4b3243)
pf tests: test pfTablesTblCount in snmp_pf
This works fine on main, but not on stable/15 so add a test.
PR: 300818
MFC after: 3 days
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit 5131335c7d48eaec427aa9ed27862ca56e3e95bc)
dummynet: validate object length before fixed-size copies in do_config()
do_config() checks that each command's o.len fits in the remaining
buffer, but the DN_LINK, DN_PROFILE, DN_SCH and DN_FS cases then copy a
fixed sizeof(struct) out of the command, which can be larger than o.len.
A command with o.len == sizeof(struct dn_id) reads past the end of the
sockopt buffer (DN_PROFILE copies about 4 KB).
Reject a command whose o.len is shorter than the structure it carries.
Add a test.
Reviewed by: kp
MFC after: 1 week
Sponsored by: Advanced Micro Devices, Inc.
Signed-off-by: Osvaldo Janeri Filho <ojanerif at amd.com>
Differential Revision: https://reviews.freebsd.org/D61440
(cherry picked from commit 42d358453d056e70bd112c63247e89c1ecf575d5)
pf: fix sctp normalisation cleanup
If we fail to allocate the dst scrub structure we should free the src
one too, but we passed src rather than src->scrub.
Reported by: llm-postcr
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit e53632189f09d7b5c6664fef51cbe4429e4b3243)
dummynet: validate object length before fixed-size copies in do_config()
do_config() checks that each command's o.len fits in the remaining
buffer, but the DN_LINK, DN_PROFILE, DN_SCH and DN_FS cases then copy a
fixed sizeof(struct) out of the command, which can be larger than o.len.
A command with o.len == sizeof(struct dn_id) reads past the end of the
sockopt buffer (DN_PROFILE copies about 4 KB).
Reject a command whose o.len is shorter than the structure it carries.
Add a test.
Reviewed by: kp
MFC after: 1 week
Sponsored by: Advanced Micro Devices, Inc.
Signed-off-by: Osvaldo Janeri Filho <ojanerif at amd.com>
Differential Revision: https://reviews.freebsd.org/D61440
(cherry picked from commit 42d358453d056e70bd112c63247e89c1ecf575d5)
pf: fix nat46 ICMP handling
When porting from OpenBSD I typo'd the variable where we store the ICMP
type, in the nat46 direction. The nat64 direction was correct. Fix this
so ICMP translation works for nat46.
Add a test case for this, as well as basic TCP and UDP cases because
nat46 was entirely untested.
PR: 300461
MFC after: 1 week
Submitted by: Charles Marshall <charles at wozi.com> (pf patch)
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit 5165da26f31f576328d99d5ac736bdfd1aa04fe8)
pf tests: test pfTablesTblCount in snmp_pf
This works fine on main, but not on stable/15 so add a test.
PR: 300818
MFC after: 3 days
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit 5131335c7d48eaec427aa9ed27862ca56e3e95bc)
pf: improve anchor string validation
Ensure that these are not overly long.
Add a test case.
Reported by: Kevin Day <kevin at your.org>
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit a396a0218cc59cff48547fdf97d9e1a8c306f090)
pf: Free the stack key when attaching it collides
pf_state_key_attach() attaches the wire key first and then the stack
key, setting sks to NULL before the second pass. When the stack key
collides with an existing state, the error path removes the wire key
again but then frees sks, which is NULL by then: the stack key leaks.
pfsync hits this. A peer that gets a plain state in a bulk update
before a redirected state whose stack key is the plain state's key
fails to import the redirected state, leaks its stack key, and leaks
another one with every later update of that state.
Free sk, the key of the pass that collided (skw on the wire pass), and
add a test.
Reviewed by: kp
Fixes: 371bd29d4b22 ("pf: fix potential state key leak")
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
[3 lines not shown]
pf: improve anchor string validation
Ensure that these are not overly long.
Add a test case.
Reported by: Kevin Day <kevin at your.org>
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit a396a0218cc59cff48547fdf97d9e1a8c306f090)
pf: Free the stack key when attaching it collides
pf_state_key_attach() attaches the wire key first and then the stack
key, setting sks to NULL before the second pass. When the stack key
collides with an existing state, the error path removes the wire key
again but then frees sks, which is NULL by then: the stack key leaks.
pfsync hits this. A peer that gets a plain state in a bulk update
before a redirected state whose stack key is the plain state's key
fails to import the redirected state, leaks its stack key, and leaks
another one with every later update of that state.
Free sk, the key of the pass that collided (skw on the wire pass), and
add a test.
Reviewed by: kp
Fixes: 371bd29d4b22 ("pf: fix potential state key leak")
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
[3 lines not shown]
IPv6: rc boot time improvements
If IPv6 is enabled we call rtsol on that interface so waiting in
rtsold is counterproductive; if one was to just use rtsold -F then
they are on their own for having the addresses usable during the
remaining startup time.
Rather than sleeping dad_count + 1 seconds we are now checking for
any tentative addresses on the interface and only then sleep
dad_count up-to 2 times. This should save us at least a dad_count
with the seconds with Optimistic DAD enabled (default) but there
are too many assumptions invovled anyway.
(RETRANS_TIMER in the kernel being 1000ms being one).
The reason why we need to sleep more than dad_count (1s default)
seems to be that first DAD for the link-local address clears and
only then solicited (or other global) addresses are handled.
Co-authored-by: Pouria Mousavizadeh Tehrani <pouria at FreeBSD.org>
[3 lines not shown]
amd64/vmm: Do not fall back to the VMCS for vmxctx registers
vmx_setreg() first calls vmxctx_setreg() and, if that fails, handles the
register as a VMCS field. This relies on vmxctx_setreg() failing only
for registers that are not kept in the vCPU context. Were it to reject
a value for one of its own registers, the error would be dropped and
the request passed on to vmcs_setreg(), which would fail it only
because the register has no VMCS field.
Check whether the register is kept in the vCPU context instead, and if
so return the result of vmxctx_setreg() directly. This lets
vmxctx_setreg() validate values and have its error returned as is. Do
the same in vmx_getreg(), so that the two functions read alike.
No functional change intended.
Reviewed by: markj
Approved by: markj
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61954
amd64/vmm: Restore vmxctx registers through vmxctx_setreg()
vmx_vcpu_snapshot() copies the guest registers kept in the vCPU context
straight between the context and the snapshot buffer, while
VM_SET_REGISTER stores them through vmxctx_setreg(). A check added to
vmxctx_setreg() would thus not apply to values restored from a
snapshot.
Add vmxctx_snapshot_reg(), modelled on vmcs_snapshot_reg(), and use it
for every register in the vCPU context, so that both paths store values
the same way. The snapshot format does not change.
No functional change intended.
Reviewed by: markj
Approved by: markj
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61953
amd64/vmm: Reject reserved DR6 bits supplied by userspace
On Intel hosts the guest's DR6 is kept in the vCPU context and loaded
into the host's register before guest entry. VM_SET_REGISTER and the
snapshot restore path store any value there. Loading a value with any
of bits 63:32 set raises #GP, which panics the host.
Fail with EINVAL instead.
Reviewed by: markj
Approved by: markj
Fixes: 65eefbe42218 (Save and restore guest debug registers.)
MFC after: 1 week
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61732
libvmmapi: Compare mapping lengths in vm_mmap_memseg()
vm_mmap_memseg() returns success without mapping anything when a
mapping with the same segment, offset, protection and flags already
starts at the requested address, but it does not compare the length.
A longer request then reports success for pages it did not map, and a
shorter one for a mapping that vm_munmap_memseg() cannot remove with
the same range. No caller in the tree makes such a request.
Fail with EEXIST when the length differs, as for the other attributes,
and document that behavior. Read the existing mapping into its own
structure rather than over the arguments.
Reviewed by: markj
Approved by: markj
Fixes: 9b1aa8d622e8 (Restructure memory allocation in bhyve to support "devmem".)
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61530
bhyve: Preserve string I/O registers on faults before progress
When a string I/O instruction faults on its first transfer, the emulator
injects the exception but still writes the masked index and count back
to the guest. With a 32-bit address size in 64-bit mode this clears
the upper halves of RSI or RDI and of RCX, although no transfer
completed and the processor reports such a fault with the registers
unchanged.
Return before updating the registers whenever no transfer completed,
whether an error, a guest fault or an injected exception stopped the
first one. Exception injection has already restarted the instruction.
A repeated instruction with a zero count is handled as before.
Reviewed by: markj
Approved by: markj
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61499
bhyve: Preserve upper RAX bits for byte and word input
Scalar IN merges the input into a 32-bit EAX temporary and writes that
value to RAX. This clears bits 63:32 for byte and word inputs, which
must preserve the bits outside AL or AX.
Use vie_update_register() to update the accumulator at the operand
width. This preserves the remaining bits for byte and word inputs and
retains zero-extension for dword inputs.
Reviewed by: markj
Approved by: markj
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61498
route/fib_algo: Fix nexthop reference leak on FLM_BATCH
handle_rtable_change_cb() references the new nexthop before calling
the algorithm. If the algorithm asks to batch the change by
returning FLM_BATCH, queue_rtable_change() references the same
nexthop again for the queued entry, while apply_rtable_changes()
only unreferences the old nexthop of each entry.
Reference new nhop once in handle_rtable_change_cb(), before
deciding whether the change is queued or passed to the algorithm,
and do not reference it again in fill_change_entry(). This also
leaves the queue reallocation as the only way for
queue_rtable_change() to fail.
Currently, dxr is the only algorithm returning FLM_BATCH.
Fixes: 6b8ef0d428c9 ("Add batched update support for the fib algo.")
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D61577
[2 lines not shown]