fwget: Add ACPI device support
Some devices that need firmware have neither a PCI nor a USB id, like
the Cirrus Logic CS35L54 speaker amplifiers (ACPI CSC3554) of the HP
ZBook Ultra G1a. Add an acpi subsystem that matches ACPI hardware ids
from devinfo(8) against per-vendor scripts, search it by default, and
map CSC3554 to its firmware package.
Reviewed by: manu, christos, imp
Approved by: manu, christos, imp
Pull Request: https://ron-dev.freebsd.org/FreeBSD/src/pulls/126
libpfctl: fix reading of struct pfr_tstats.pfrts_cnt
The kernel returns this as a uint64_t, but we only have an int.
Read this via a temporary value and downcast.
Reported by: llm-postcr
Sponsored by: Rubicon Communications, LLC ("Netgate")
snmp_pf: fix pfTablesTblNumber
Actually set the number of tables we have.
MFC after: 1 week
Fixes: 9e8d2962aad3 ("pf: convert DIOCRGETTSTATS to netlink")
Sponsored by: Rubicon Communications, LLC ("Netgate")
pf: do not copy tag/match_tag/qid/pqid from userspace
We assign those based on the tag/match_tag/... names. Assigning them
from userspace risks corruption if we free the rule on error and
tag_unref() them.
Reported by: llm-postcr
Sponsored by: Rubicon Communications, LLC ("Netgate")
snmp_pf: fix table indexes
Initialise 'i' so that the index we assign to tables is predictable.
Reported by: maxim at FreeBSD.org
MFC after: 1 week
Fixes: 9e8d2962aad3 ("pf: convert DIOCRGETTSTATS to netlink")
Sponsored by: Rubicon Communications, LLC ("Netgate")
bhyve: List tpm.ctrl_path in the configuration schema
fbb1b886cbd0 added the tpm.ctrl_path option but not its schema entry,
so "bhyve -o help" does not list it, and tools that look for the option
there do not use it.
Reported by: llm-postcr
Fixes: fbb1b886cbd0 ("bhyve: Reinitialise swtpm's TPM at startup")
Sponsored by: Defenso
Signed-off-by: Quentin Thébault <quentin.thebault at defenso.fr>
Reviewed by: kevans, novel
Differential Revision: https://reviews.freebsd.org/D62285
stdio: Add test cases for scansets
Add test cases that exercise scanf() / wscanf() scansets, including
hyphenated ranges and the missing closing bracket bug we recently fixed.
MFC after: 1 week
Reviewed by: kevans, emaste
Differential Revision: https://reviews.freebsd.org/D62201
stdio: Handle unterminated scansets
In both vfscanf() and vfwscanf(), if the end of the format string was
reached before the closing bracket of a scanset, we treated the NUL as
the closing bracket and continued to read beyond the end of the format
string. Add an error check to catch this case.
MFC after: 1 week
Reported by: Nick L. Leppelmeier <nicklpmr at gmail.com>
Reviewed by: kevans, emaste
Differential Revision: https://reviews.freebsd.org/D62199
stdio: Implement ranges for wchar scansets
The C and POSIX standards allow but do not require hyphenated ranges to
be supported in scanf() / wscanf() scansets. We implemented them for
scanf() but not for wscanf(). Do so using similar logic as for scanf().
This is hard to do efficiently for wide characters, which can in theory
span the full 32-bit range (and even the actual range of about 1 million
Unicode codepoints is difficult to handle), so we don't try to be
efficient, but just focus on producing the same results for wscanf() as
for scanf().
MFC after: 1 week
Reviewed by: kevans, emaste
Differential Revision: https://reviews.freebsd.org/D62200
loader.efi: Measure boot policy and loaded contents with a TPM
Use the EFI TCG2 protocol, or the legacy TCG protocol on TPM 1.2
firmware, to extend the loader PCRs and record EV_IPL events in the
firmware event log.
Extend PCR 8 with the final kernel environment and the type, name, and
arguments of each loaded boot input. Prefix both record types with
versioned, NUL-terminated domain strings. These make the records
self-identifying and define an explicit measured policy encoding. Store
the complete measured pre-images in the event data so attestation and
diagnostic tools can audit the values without an out of band copy.
Extend PCR 9 with the initialized contents of kernels, modules, and raw
boot inputs, but record only descriptive labels rather than copying file
contents into the event log.
The Lua module table has no defined traversal order. Retain content
ranges as loader-private metadata, then sort the final file list before
[32 lines not shown]
edk2: Import Loadfile2.h and TcgService.h from edk2-stable202502
Verbatim import of these files, with unix line endings.
Sponsored by: Netflix
(cherry picked from commit e960cb4c033c8f65af1e8b09310c1bd5414f21ac)
tpm20: Bring in the edk2 includes for TPM 2.0 support
Bring these in from edk2-stable202502. They will be used in a
forthcoming TPM 2.0 support code.
Sponsored by: Netflix
(cherry picked from commit 1aa241b4ee657b8a62a0d86b91f82cf792f08dca)
snd_hda: Enable the headset microphone on Framework ALC295 laptops
The ALC295's jack is configured in headphone-only mode by default. Set
it to CTIA headset mode so that the headset microphone can work,
otherwise the pin configuration patches alone are not enough.
One caveat, as a result of jack presence detection not working properly,
is that a user has to switch between internal and headset microphones
using mixer(8). The "monitor" knob corresponds to the internal mic, and
"mic" to the headset one.
This patch currently covers the Framework 11th Gen (0x0001), AMD Ryzen
7040 13in (0x0006), and AMD Ryzen AI 300 (0x000b).
Linux commit 5a36767 used as a reference.
See also: https://github.com/torvalds/linux/commit/5a36767a41650518f35ea0bae9a2d6e775f1aed1
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D60527
iflib: Expose locked datapath quiescence for driver resets
Provide iflib_quiesce() for driver-managed resets which must stop the
framework datapath before dismantling device resources. Require the
context lock, preserve administrative flags, and reject detach, power
transitions, and recursive lifecycle calls without requesting a restart.
Make the stop path wait for queue tasks, callouts, and inline hardware
users before invoking IFDI_STOP and releasing packet mappings. Mask
interrupts again after draining task tails which may have reenabled them.
Drain mp_ring under its existing consumer ownership. When the ring is
empty, reserve all producer space so late transmitters take the existing
ring-full path and return ENETDOWN. Reopen the ring after successful
initialization. Keep completion polling inside consumer ownership.
Simple TX uses its existing producer count, mutex, and deferred-free
slot. Check ALTQ admission under the send queue lock so stop can purge
pending packets before a restart.
[10 lines not shown]
Merge pkgconf 3.0.10 into main
This change just fixes a version number in the build system.
Reviewed by: emaste
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61935
powerpc: use the register validity flags in the vector ptrace requests
PT_SETVRREGS and PT_SETVSRREGS set PCB_VEC and PCB_VSX, which say the
thread owns the unit, instead of PCB_VECREGS and PCB_FPREGS, which say
the saved registers are valid. Ownership should only come from the
unavailable trap or cpu_switchin(), and the trap asserts it isn't set
yet, so setting the VSX registers of a traced child that hasn't used
the FPU panics an INVARIANTS kernel on the child's first VSX
instruction. Tracing your own child is enough, no privilege needed.
The getters had the matching problem: they returned the saved
registers only while the thread owned the unit, so a thread stopped
with valid but unloaded registers showed the debugger zeroes.
The thread is stopped, so the PCB is what counts. Set and test the
validity flags instead.
Reviewed by: jhibbits
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62035
mpi3mr: Fix HostTag conversion in timestamp sync
In mpi3mr_timestamp_sync(), HostTag is a 16-bit field (U16) in
Mpi3IoUnitControlRequest_t. It was incorrectly initialized using
htole64(MPI3MR_HOSTTAG_INITCMDS) instead of htole16().
On little-endian architectures (amd64, arm64), htole64(1) leaves the
value as 1, which fits into a 16-bit integer without value truncation.
However, on big-endian architectures (such as powerpc64), htole64(1)
byte-swaps the 64-bit value to 0x0100000000000000 (72057594037927936).
Assigning this to a U16 causes truncation to 0 and triggers a fatal
compiler build failure under -Werror=constant-conversion:
implicit conversion from 'unsigned long' to 'U16' (aka 'unsigned short')
changes value from 72057594037927936 to 0 [-Wconstant-conversion]
Fix this by using htole16(), consistent with all other HostTag
initializations in the driver.
[2 lines not shown]
mpi3mr: Validate event bounds and tighten error handling
Validate firmware event payload lengths in top-half and bottom-half
event handlers for device status change, prepare-for-reset, energy pack
change, cable management, and device info change events to prevent
buffer over-reads on truncated or malformed firmware packets. Propagate
validation status from the device status top-half handler to prevent
scheduling bottom-half worker processing for invalid packets.
In addition, unlock the admin request spinlock when rejecting
submissions on unrecoverable controllers to avoid deadlocks. Synchronize
event queue teardown with the dedicated firmware event lock rather than
the main driver mutex to match worker queue locking, and add null checks
for memory allocations in CAM attach and bitmap scanning routines.
Reviewed by: ssaxena
Differential Revision: https://reviews.freebsd.org/D60344
mpi3mr: Validate event payload sizes before deferred event processing
When processing asynchronous firmware events deferred to bottom-half
workers, the driver previously cast and dereferenced event payload
buffers directly into target structures - specifically device status
change and device configuration page structures - without verifying
whether the received payload was large enough to contain the expected
structure.
If a truncated, corrupted, or zero-length event was queued by top-half
processing, accessing these fields caused out-of-bounds memory reads
beyond the allocated event payload buffer. In addition, persistent
target identifiers in device addition events were extracted without
converting from little-endian format to host endianness.
Validate that event payload sizes are at least as large as the target
event structures before dereferencing fields, and ensure persistent
device identifiers are properly converted from little-endian to host
byte order.
[3 lines not shown]
mpi3mr: Enforce runtime bounds on SGL segments and CDB lengths
Several runtime boundary checks in the I/O submission path previously
relied only on debug assertions or lacked complete validation:
1. When preparing scatter-gather lists for DMA, segment count validation
relied only on a debug assertion that is omitted in production
builds. If a command exceeded the controller's maximum supported
segment count, the driver proceeded to build the scatter-gather list
past allocated descriptor memory.
2. In the filter for unsupported SATA commands, the target structure's
type-specific union was dereferenced without first checking the
device form factor, risking type confusion on NVMe or Virtual Disk
targets. In addition, CDB bytes were read only from the inline array,
ignoring pointer-based commands.
3. In the SCSI command submission path, incoming command lengths were
not checked against the 32-byte capacity of the hardware request
frame, risking frame overflow.
[7 lines not shown]
mpi3mr: Update driver version to 8.20.0.4.0
Update the driver version to 8.20.0.4.0.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D60346
mpi3mr: Use sx lock for IOCTL serialization
Holding a non-sleepable mutex across IOCTL processing violates
locking invariants, as copying data to and from user space can
page fault and firmware completion waits sleep via pause().
Replace the mutex with a sleepable sx (shared/exclusive) lock to
serialize driver and MPT IOCTL execution across sleepable boundaries.
Initialize the sx lock during controller setup and release it during
driver teardown.
Reviewed by: ssaxena
Differential Revision: https://reviews.freebsd.org/D60345
mpi3mr: Fix management command timeouts and teardown ordering during detach
During driver unload under active I/O, the driver resets the controller
via Message Unit Reset (MUR). Firmware sends completion events during
the reset, but the driver was discarding them because the shutdown flag
was set. Dropping these completions caused pending management IOCTLs to
time out, leaving the controller in a faulted state that prevented clean
re-initialization on subsequent driver reloads.
In addition, userland character device nodes were detached after the
hardware reset, allowing new IOCTLs to arrive while hardware cleanup was
underway.
Fix these issues by:
1. Removing the shutdown check in event processing so in-flight
completions finish normally instead of timing out.
2. Detaching userland device nodes before tearing down hardware
resources to prevent new IOCTLs from arriving during unload.
[3 lines not shown]
mpi3mr: Validate request queue ID and consumer index bounds in completions
When processing command completions, the driver receives completion
descriptors containing the request queue ID and the updated request
queue consumer index. Previously, the driver trusted these values
without bounds checking.
If an invalid queue ID was reported for an operational completion, using
it to index the operational queue array caused an out-of-bounds access.
In addition, if a consumer index exceeded the queue capacity (in either
an admin or operational completion), the driver stored an out-of-bounds
index into its internal tracking.
Validate that the operational request queue ID is within the range of
allocated queues before indexing, and verify that the consumer index is
within queue depth for both admin and operational queues before updating
tracking.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D60339
mpi3mr: Validate entry counts against payload length in topology events
When the controller notifies the driver of SAS or PCIe topology changes,
the firmware event notification includes a payload length and an entry
count indicating the number of PHY or port descriptors attached to the
event. Previously, the top-half event handlers iterated over the entry
count without verifying whether the payload buffer was actually large
enough to contain all reported entries. A malformed event with an entry
count exceeding the buffer length would result in reading memory beyond
the event descriptor.
Validate that the reported event length covers the base topology header
and compute the maximum number of entries that fit within the payload.
If the entry count exceeds the available buffer, reject the event and
skip scheduling deferred bottom-half processing.
Reviewed by: ssaxena
Differential Revision: https://reviews.freebsd.org/D60336
mpi3mr: Bound event payload and log data copies to allocated buffer sizes
When processing asynchronous event notifications from controller
firmware, the driver trusted the firmware-reported event data length
without verifying whether it fit within the physical reply buffer frame.
If an event reported a length exceeding the reply frame size, copying
the payload into bottom-half event queues or saving diagnostic log data
caused memory reads beyond the reply buffer boundaries.
In addition, when saving log data into the driver's circular logging
buffer, the copy size was bounded against the total slot size rather
than the payload capacity, failing to account for the entry header and
causing writes to overflow into adjacent buffer slots.
Clamp all event data copy lengths to the maximum capacity of the reply
buffer frame, and account for entry header overhead when saving log data
to prevent buffer overflows.
Reviewed by: ssaxena
Differential Revision: https://reviews.freebsd.org/D60337
mpi3mr: Enforce frame alignment and bounds checks on reply and sense buffers
When the controller posts command completions or sense data, firmware
provides physical DMA addresses that the driver translates into virtual
addresses within its pre-allocated reply and sense buffer pools.
Previously, these address translation helpers lacked complete
validation:
1. The reply buffer lookup checked only the starting physical address
without verifying that the full frame size fit within the pool,
and did not check whether the address aligned to the fixed reply
frame stride.
2. The sense buffer lookup performed no bounds checking whatsoever,
blindly computing an offset from the pool base.
If firmware reported a corrupted address or an unaligned offset,
the driver computed an invalid virtual pointer, leading to memory
access outside the allocated buffer pools.
[8 lines not shown]
mpi3mr: Re-resolve target handle during error recovery and flush
When an I/O request encounters a timeout or requires error recovery
(such as aborts or target resets), the recovery routines previously
dereferenced the cached target structure pointer stored in the command.
If the target device was detached or removed from the system while the
timed-out request was pending, the target structure had already been
freed, causing error recovery and I/O flush routines to dereference
freed memory.
Store the target device's hardware handle in the command structure at
submission time, and re-resolve the target by handle from the active
device list during error recovery, task management, and I/O flushing. If
the target no longer exists in the active list, recovery routines skip
the command safely without dereferencing freed pointers.
Reviewed by: ssaxena
Differential Revision: https://reviews.freebsd.org/D60340
mpi3mr: Validate user buffer length against SGE overhead in RAID management
For RAID management passthrough commands, the driver embeds the
scatter-gather list directly inside the kernel DMA buffer immediately
following the user data payload. Previously, the driver did not verify
that the kernel buffer had sufficient room to hold both the user data
and the required scatter-gather element.
If a userland request supplied a buffer length that left less space than
a single scatter-gather element, unsigned subtraction underflowed the
available descriptor calculation. This bypassed subsequent bounds checks
and resulted in memory corruption when constructing the scatter-gather
list past the end of the allocated buffer.
Validate that the user buffer length leaves sufficient space for the
scatter-gather element overhead, safely rejecting oversized requests
before constructing the scatter-gather list.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D60334