vmm: Avoid redundant AMD DEBUGCTL writes
Skip clearing and restoring DEBUGCTL when the saved host value is
zero. The entry path leaves DEBUGCTL zero, and LBR virtualization
restores that host value on VM exit. A rejected guest entry also
returns with the pre-VMRUN DEBUGCTL value. Guest accesses to DEBUGCTL
remain intercepted.
Preserve the existing writes for nonzero host state. Avoiding the
redundant writes can also avoid intercepted MSR accesses when bhyve
runs under another hypervisor.
Reviewed by: markj, bnovkov
Approved by: markj (mentor)
Sponsored by: Alchemilla Ventures Private Limited
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D61218
vmm: Avoid redundant Intel DEBUGCTL writes
Skip clearing and restoring IA32_DEBUGCTL when the saved host value
is zero.
VM exit clears the register. If VM entry fails, the entry path has
already cleared any nonzero host value, so restoring zero is also
unnecessary in that case. Preserve the existing writes for nonzero
host state.
Avoiding these writes can also avoid intercepted MSR accesses when
bhyve runs under another hypervisor.
Reviewed by: markj, bnovkov
Approved by: markj (mentor)
Sponsored by: Alchemilla Ventures Private Limited
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D61219
vfs: fail VOP_DEALLOCATE passes that make no progress
VOP_DEALLOCATE(9) permits a filesystem to return a partial result, and
vn_deallocate_impl() simply loops until the range is consumed. If a
filesystem returns success without shrinking the remaining length, we
spin forever with the rangelock held and no way to interrupt the thread.
Return EIO if a pass doesn't make progress so that a buggy filesystem
doesn't wedge the caller.
Document the progress requirement in VOP_DEALLOCATE(9) and the new EIO
condition in fspacectl(2).
I did wonder if this should be made interruptible for, e.g., slow I/O
over NFS, but I've declined to touch it for now.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D61496
tmpfs: fix a hang reachable through hole-punching
Deallocate requests that clip only the start of a single page need to be
taken into account as well- it misses the first branch because
startofs == 0, but then it also misses the last branch because the start
and end are on the same page.
Handling this case in either branch is equally valid, so I've
arbitrarily chosen the first branch since it already has single-page
logic.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D61490
tmpfs: fix append-only file handling for writes and hole-punching
Write protection assumed that O_APPEND handling at open time is
sufficient, but the flag can be cleared with F_SETFL. That's maybe
worth rejecting, but that's harder to do without some clear layering
violations.
Hole-punching also violates the spirit of append-only, so reject that
on files that are append-only.
Note that we don't reject IMMUTABLE here- UFS seems to historically
not care if a file transitions to IMMUTABLE after it's opened, so follow
suit here instead of trying to tighten it up. ZFS will apparently use
the more constraining logic, but that's OK for now.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D61491
vfs: fail VOP_ALLOCATE passes that make no progress
vn_fallocate() loops over VOP_ALLOCATE until the requested range has
been allocated, permitting partial results. It only asserts that each
pass makes progress, so on a non-INVARIANTS kernel a filesystem that
returns success without shrinking the remaining length leaves the caller
spinning forever.
Drop the assertion and just return EIO in that case, as was just done
for vn_deallocate_impl(). The NFS server already does the same in its
own VOP_ALLOCATE loop.
Document the progress requirement in VOP_ALLOCATE(9) and the new EIO
condition in posix_fallocate(2).
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D61497
traceroute6: do not print an ECN report for an echo reply
packet_ok() takes the ECN bits from the IPv6 header quoted by an
ICMPv6 error message. The destination answers an ICMPv6 probe (-I)
with an echo reply, which repeats the ICMPv6 data of the probe but not
its IPv6 header, so for that reply the main loop used whatever an
earlier packet had left in ecn.
With -E the ECN report for the destination therefore repeated the
bits quoted by an earlier ICMPv6 error. If no ICMPv6 error had been
received before, because the destination is one hop away, the first
hops are skipped with -f or the routers on the path are silent, ecn
was still uninitialized:
$ traceroute6 -E -I -n -q 1 ::1
traceroute6 to ::1 (::1) from ::1, 64 hops max, 20 byte packets
1 ::1 0.055 ms (ecn=bleached)
Print the ECN report only when there is a quoted header. Document
[7 lines not shown]
traceroute: do not use a stale or NULL quoted header with -E
packet_ok() points the global hip at the IP header quoted by an ICMP
error message and nothing resets it afterwards. The destination
answers an ICMP probe (-I) with an echo reply, which repeats the ICMP
data of the probe but not its IP header, so for that reply the main
loop used whatever an earlier packet had left in hip.
With -E the ECN report for the destination was therefore read from
the payload of the echo reply. If no ICMP error had been received
before, because the destination is one hop away, the first hops are
skipped with -f or the routers on the path are silent, hip was still
NULL and traceroute crashed:
$ traceroute -E -I 127.0.0.1
traceroute to 127.0.0.1 (127.0.0.1), 64 hops max, 48 byte packets
Segmentation fault
With -D the stale quote was compared with the probe.
[10 lines not shown]
tests/ssl_sendfile: fix flakyness under load
When loopback TCP delivery is faster than our sending thread it may take
several writes to full buffer reliably.
PR: 299447
syslogd/tests: wait for tcpdump before sending the message
The forwarded and relayed format tests could send the message before tcpdump
attached to lo0, so "tcpdump -c 1" never saw it and the test hung until the
300s timeout. Also make syslogd_stop_on_ports stop every port it is given.
Reviewed by: markj
Approved by: markj
Sponsored by: Netflix
Differential Revision: https://ron-dev.freebsd.org/FreeBSD/src/pulls/108
axgbe: return positive errno values from the sysctl handlers
Return positive errno values from the FreeBSD sysctl handlers so that
userland reports the proper error instead of "Unknown error: -22".
Convert the negative phy_config_aneg() result at the sysctl boundary,
matching axgbe_if_media_change(), and retain the PHY code's internal
error convention.
Differential Revision: https://reviews.freebsd.org/D61400
(cherry picked from commit c89613ded9237811d35a42788e9728fe0404e26b)
axgbe: bound the sysctl parser writes in get_val()
Reject tokens and option counts that exceed the fixed parser buffers,
and fix the terminating NUL offset. Have the sysctl handlers propagate
parser errors before applying settings.
Handle SYSL_U32 options and reject failed numeric conversions instead of
using an uninitialized value. Fix the duplex case falling through to an
error, and initialize the link-setting strings for unexpected speeds.
Differential Revision: https://reviews.freebsd.org/D61339
(cherry picked from commit 5523a8ba6f618fa5c853450dd551d8a5f06715ca)
modstat: check errno before calling feature_present
feature_present will overwrite errno if COMPAT_FREEBSD13 is not present.
Approved by: re (cperciva)
Reported by: llm-postcr
Fixes: ef726c645300 ("modstat: allow compat support to fail in tests")
(cherry picked from commit acd270c8c6542b45e404078b28e1a732106aa76c)
(cherry picked from commit ed8dc5e715fff0a0c9f60416362924315bb49381)
modstat: allow compat support to fail in tests
v1 and v2 versions of stuct module_stat are now gated by COMPAT_ ifdefs
so allow the otherwise valid query to fail with EINVAL.
Approved by: re (cperciva)
Effort: CHERI upstreaming
Reviewed by: markj
Reported by: llm-postcr
Sponsored by: Innovate UK
Fixes: 1ebf46ecb627 ("modstat: don't copyout while holding a lock")
Differential Revision: https://reviews.freebsd.org/D61460
(cherry picked from commit ef726c645300870b6bdf3573079b1f89f3b45c74)
(cherry picked from commit 4a9770b9256c7119da287b15a6e7900298e6d514)
modstat: don't copyout while holding a lock
If a user arranges for a page fault to never be filled (e.g., via a
FUSE file system), this can hold the shared lock forever.
To make this all work, refactor kern_modstat and freebsd32_modstat to
malloc a temporary buffer and fill it before copying it out rather
than doing a bunch of copies.
Add COMPAT_* ifdefs around compat code. The module_stat_v1 code is
really for a.out binaries in practice and thus a bit questionable.
Approved by: re (cperciva)
Reviewed by: markj
Reported by: llm-postcr
Sponsored by: Innovate UK
Fixes: 7f8c2056db1e ("modstat: avoid copying from freed memory")
Differential Revision: https://reviews.freebsd.org/D61432
[2 lines not shown]
modstat: avoid copying from freed memory
If a module is unloaded after the module is looked up in kern_modstat,
but before one of the copyout's occurs, then the memory being copied
might be freed and reused leading to an information disclosure.
The LLM was particularly concerned about a TOCTOU issue in the length
of the name, but it seems likely that there are issues with all the
copyout's. As such, hold the shared lock throughout.
Approved by: re (cperciva)
Reviewed by: markj
Reported by: llm-postcr
MFC after: 3 days
Sponsored by: Innovate UK
Fixes: 9b3851e9e3b1 ("- Lock down the ``module'' structure...")
Differential Revision: https://reviews.freebsd.org/D61398
(cherry picked from commit 7f8c2056db1e39e44c3eda15aa4e53f7fc971cd8)
(cherry picked from commit 80fed5b6b5bdf712603b90a236796e35ed7e604c)
powerpc/pmap: Use dcbz to zero pages in the radix pmap
pagezero() was a plain store loop (bzero), which under the kernel build
flags (-mno-vsx -msoft-float) compiles to byte stores. dcbz
establishes a zeroed cache line directly in the cache without a
read-for-ownership fetch from memory, roughly halving the memory
transactions of page zeroing.
Measured on POWER9 (Raptor Blackbird, DD2.3, bare metal), zeroing a
cold 256 MB buffer with 128-byte scalar loops:
byte stores (current libkern memset) 8.6 GB/s
doubleword (std) stores 26.8 GB/s
dcbz 34.6 GB/s
dcbz raises an alignment interrupt on caching-inhibited mappings, and
the kernel does not emulate it, so mmu_radix_zero_page() falls back to
bzero() for any page whose memattr is not the write-back default. The
internal pagezero() callers only touch freshly allocated page-table
[13 lines not shown]
linux: do not truncate the listxattr() size
listxattr() sized its buffer with min(), which truncates the 64-bit
size to 32 bits, so a size of 2^32 + k allocated k bytes while the
copy-out guard used the full size. The walk then read record lengths
past the buffer and copied kernel heap out to the caller, and could
panic the kernel. Any user can reach it through a user.* attribute on
a file it owns.
Use MIN(), and fail with EIO if a record runs past the data returned.
Approved by: re (cperciva)
Reviewed by: adrian, markj
Approved by: adrian (mentor)
Differential Revision: https://reviews.freebsd.org/D61006
Signed-off-by: Nick Price <nprice at FreeBSD.org>
(cherry picked from commit fbe4835e6b1eec36103a5ce97efbab11b3b5fc72)
(cherry picked from commit a46d6ae4c0b6f6e8eb74b13da6f607d2ead74be7)
ktls: Check the record type message holds its byte
sosend_generic() read the TLS record type past a TLS_SET_RECORD_TYPE
control message holding only a cmsghdr, and sent that stale byte.
Approved by: re (cperciva)
Approved by: markj
Fixes: b2e60773c6b0 ("Add kernel-side support for in-kernel TLS.")
Sponsored by: Netflix
(cherry picked from commit bd4975e5fb051c2b2e8d5218940b7e8ef87b5bdf)
(cherry picked from commit 42e7802e24fefd1cef6913ab162cda2c7bdc477f)
tcp: improve consistency
Use an inline function tcp_adapt_iss_check() to perform the check
consistently instead of replicating the code multiple times. These
checks already became inconsistent.
A fix for PR 298560 requires more calls to tcp_adapt_iss_check().
Reviewed by: Peter Lei
Fixes: fa2ad70a4511 ("tcp: make ghost ACK handling more conformant")
MFC after: 3 days
MFC to: stable/14
MFC to: stable/15
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D61685
bhyve: Do not abort when the VM is destroyed during an exit
When a VM is destroyed (bhyvectl --destroy) while a vCPU thread is
handling an exit in bhyve, every call on the VM fails. vm_loop()
handles that for vm_run() and ends bhyve with BHYVE_EXIT_ERROR, but a
vCPU in the middle of an exit hits one of the assert(error == 0) after
a register update or an exception injection (emulate_inout(),
vmexit_rdmsr(), vm_inject_fault()), or reports "Failed to emulate
instruction" and returns VMEXIT_ABORT: bhyve dies of SIGABRT and
leaves a core. With a guest doing a lot of port I/O or MSR accesses
that bhyve emulates, a forced stop hits this regularly.
Add vm_check_destroyed(), which exits with BHYVE_EXIT_ERROR, as
vm_loop() does, if the VM is gone. Call it before those asserts and
on the instruction emulation failure paths on amd64, arm64 and
riscv. A failure on a VM that still exists asserts or aborts as
before.
Signed-off-by: Wanpeng Qian <wanpengqian at gmail.com>
[4 lines not shown]
amd64/pt.c: Clear ToPa PMI status for stray interrupts
An inactive tracing session might encounter stray ToPA PMI
interrupts, in which case the interrupt handler skips processing
the interrupt but fails to reset the ToPA status bit.