pkg: Add support for mldsa (ML-DSA-87) signatures
pkg(8) gained an "mldsa" signer backed by OpenSSL's ML-DSA-87
implementation. Teach the bootstrap to verify it so that a repository
signed with it can be bootstrapped.
As in pkg(8), the signed message is the hex-encoded SHA-512 digest of
pkg.pkg, for both PUBKEY and FINGERPRINTS verification, and only
ML-DSA-87 keys are accepted. The signer is only built when OpenSSL is
3.5 or later.
While here, report the actual signer type rather than "rsa" when the
signer for a fingerprint signature cannot be found, and document
SIGNATURE_TYPE=PUBKEY and PUBKEY in pkg(7).
Reviewed by: kevans
MFC after: 1 week
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D62408
pkg: Accept SHA-512 certificate fingerprints
Accept SHA-512 certificate fingerprints ("function: sha512") in the
trusted and revoked fingerprint directories, as pkg(8) does. Trusted
and revoked fingerprints are each compared against the certificate
digest of their own type, so a revocation of either type applies.
Reviewed by: kevans
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62408
pkg: Fix signature length after the $PKGSIGN$ marker
parse_sigtype() only subtracted the length of "<type>$" from the
signature size, not the full "$PKGSIGN:<type>$" marker, so
read_pubkey() copied 9 bytes past the end of the signature buffer
into the signature. The ECC signer happened to tolerate this because
its DER parser ignores trailing bytes, but a signer that checks the
signature length exactly will reject every typed pubkey signature.
Also search for the closing '$' with memchr() bounded by the buffer
length rather than relying on the buffer being NUL-terminated.
While here, drop an unneeded __DECONST: BIO_new_mem_buf() takes a
const pointer.
Reviewed by: kevans
Fixes: 3d0a0dda3a7d ("pkg: finish adding the ECC signer...")
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62407
linux(4): accept EPOLLOUT on inotify, timerfd and epoll descriptors
On Linux, epoll_ctl() accepts any event mask on a pollable file; a
descriptor that can never become writable simply never reports
EPOLLOUT. We turn EPOLLOUT into an EVFILT_WRITE knote, but inotify,
timerfd and kqueue descriptors only support EVFILT_READ, so the call
fails with EINVAL.
Go's runtime registers every non-blocking descriptor with
EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET. When that fails for an inotify
descriptor, fsnotify ends up reading it in a loop that only ever gets
EAGAIN. With a Go CLI tool under the Linuxulator this kept about eight
cores busy per idle process and wrote megabytes of error logs per
second. Because the read knote is added before the write knote fails,
the descriptor was also left half registered, and a later
EPOLL_CTL_ADD returned EEXIST.
Drop the write bits for these three descriptor types before building
the kevents, so the registration succeeds and only read readiness is
[7 lines not shown]
bhyve: make UART TCP backend not disconnect on EAGAIN
Currently, uart_rxfifo_putchar() disconnects a TCP client when
ttywrite() returns -1. However, EAGAIN does not mean the client
has disconnected.
Thus, ignore EAGAIN and do not disconnect a client unnecessarily.
In this case the character is dropped, as the stdio and tty backends
already do.
Reviewed by: aokblast
Reported by: llm-postcr
Fixes: 1f903953fbf8 ("bhyve: Add raw tcp to uart backend")
MFC after: 3 days
MFC to: stable/15
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D62404
vmm: Use an rms lock to synchronize ioctls
Certain vmm ioctls, such as VM_RAISE_MSI, do not synchronize with
VM_REINIT. This can lead to use-after-frees, as VM_REINIT will free and
reallocate various bits of VM state, such as per-vCPU vlapic structures.
Handle this with a per-VM read-mostly lock which synchronizes ioctl
handlers and VM_REINIT calls. Handlers which freeze a vCPU do not need
additional synchronization and don't acquire the lock at all.
An alternate approach would be to change VM_REINIT to avoid freeing and
allocating new structures when possible. This would fix the obvious
memory safety bugs, but the implementation is more complicated, and it
seems better to explicitly synchronize.
Reported by: Myeonghun Pak
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61044
LinuxKPI: pci: implement pci_clear_and_set_config_dword()
Implement pci_clear_and_set_config_dword() as a combination of
read and write config_dword. Note while the read function returns
an error value its current implementation can never fail so we do
not have to deal with the error case.
This is needed by an rtw89 update.
MFC after: 3 days
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D60687
LinuxKPI: add field_get() and FIELD_GET_SIGNED()
An updated rtw89 driver uses both so add them with the added
__FIELD_GET() not doing any extra checks. We assume the Linux
counterpart will do that and drivers will fail them there, so
no need to add assertions here.
MFC after: 3 days
Reviwed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D60716
LinuxKPI: firmware: ensure name stays valid
The name argument passed into request_firmware_nowait() may only be
valid locally in the calling function and could be out of scope by the
time the task runs; make a copy to ensure it stays valid over the
callback.
MFC after: 3 days
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D60630
LinuxKPI: add spinlock_bh guard support
We will likely have to add more DEFINE_LOCK_GUARD_1 cleanup.h
defintions for various lock types. Add the one for spinlock_bh
as a wireless driver update needs it.
MFC after: 3 days
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D60631
LinuxKPI: rework cleanup.h to use CLASS
After adding DEFINE_CLASS and CLASS in f2a2e02ae54b to cleanup.h
cleanup that file some from the original implementation:
- Rename CLEANUP_NAME to LKPI_CLASS_NAME to (a) match the CLASS
implementation idea and (b) tell it is an internal macro and not
a LinuxKPI one.
- consistently use LKPI_CLASS_NAME() rather than doing multiple ##.
- consistently use _constructor and _destructor instead of _create
and _destroy.
- consistently use _name instead of _n and _type instead of _t; the
latter helps a lot to keep the typedef _type LKPI_CLASS_NAME(_name, _t)
apart.
- With this the former DECLARE now matches CLASS so remove the former
in favour of the latter.
- With this DEFINE_GUARD() can now be implemented as a single
LINUXKPI_]DEFINE_CLASS() call.
- In guard() and scoped_guard() start using __UNIQUE_ID() which was
added in 8b05d84be9e28 rather than manually using ## __COUNTER__.
[7 lines not shown]
vtnet_ctrl_announce_ack_cmd: Remove busdma
This function was added after busdma was added to vtnet, but there
were bugs in the busdma functionality and that got backed out. The
busdma bits need to be stripped from vtnet_ctrl_announce_ack_cmd as
well.
Direct commit to releng/15.2.
PR: 301485
Reviewed by: adrian
Approved by: re (cperciva)
Differential Revision: https://reviews.freebsd.org/D62436
icmp6: re-derive rth after the second m_pullup in icmp6_notify_error
The routing-header pullup may reallocate the mbuf. rth still points
into the old one and is used to read ip6r_nxt.
Reviewed by: markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62410
rtld: add unwind info to the 32-bit powerpc trampolines
_rtld_bind_start and _rtld_bind_secureplt_start set up a stack frame but
don't tell the unwinder about it, so a backtrace taken in the binder
stops there.
Approved by: jhibbits (blanket)
Fixes: 78599c32efed ("Add CFI start/end proc directives to arm64, i386, and ppc")
rtld: keep FP and vector registers out of the C code on 32-bit powerpc
clang expects __tls_get_addr() to preserve the floating-point and vector
registers, and _rtld_bind_start only saves the integer ones. When lib32
is built for a CPU with AltiVec or VSX, the first TLS access in a
dlopen()ed library clobbers vs0, v2 and v3 in the caller, because
clang vectorizes rtld's memset() and memcpy().
Build the 32-bit rtld without AltiVec, VSX and hard float, like the
64-bit one.
Approved by: jhibbits (blanket)
powerpc/powernv: clear the OPAL async completion flag after use
When the heartbeat picks up an async completion, it marks the token as
completed. opal_wait_completion() never cleared that mark, so the next
request made with the same token could get the old message back while
firmware was still working on the new one.
The mark is cleared when a token is allocated, so only callers that
reuse a token are affected. opal_flash does that for every block, but
firmware finishes flash requests before the call returns.
Reported by: llm-postcr
Approved by: jhibbits (blanket)
MFC after: 1 week
rtld: keep FP and vector registers out of the C code on powerpc64
_rtld_bind_start only saves r3-r10 around the binder, but functions also
take arguments in f1-f13 and v2-v13. The binder doesn't clobber them
today only because clang happens to use vs0 for the copies and the
memset() it vectorizes there.
Build rtld without AltiVec, VSX and hard float so that it stays this
way, like amd64 and i386 do with SSE. glibc does the same for its
binder.
Reported by: llm-postcr
Approved by: jhibbits (blanket)
MFC after: 1 week
linuxulator/powerpc: don't single step signal handlers
linux_rt_sendsig() kept MSR[SE] set for the handler, so a PT_STEP that
delivers a signal stopped on the handler's first instruction. Since
7a7733ff01cc the saved MSR[SE] also comes back at rt_sigreturn(), and
the debugger got a second SIGTRAP after the handler.
Clear it for the handler, like sendsig() does. The saved context keeps
it, so the step ends after one instruction of the interrupted code.
Reported by: llm-postcr
Approved by: jhibbits (blanket)
powerpc: don't single step a thread created while stepping
cpu_copy_thread() copies the trap frame of the thread that creates the
new one, MSR[SE] included. thr_new(2) doesn't care, cpu_set_upcall()
builds a new MSR, but a Linux clone(CLONE_THREAD) keeps the copy. The
new thread then takes a trace trap on its first instruction: the
debugger gets a SIGTRAP from a thread it never stepped, and if it has
detached by then, the process dies.
Clear it there too, like cpu_fork() does.
Reported by: llm-postcr
Approved by: jhibbits (blanket)
rtld: add unwind info to the powerpc64 trampolines
_rtld_bind_start and _rtld_tls_get_addr_slow set up a stack frame but
don't tell the unwinder about it, so a backtrace taken in the binder or
in the slow path of __tls_get_addr() stops at the trampoline.
Reported by: llm-postcr
Reviewed by: jhibbits
Fixes: 78599c32efed ("Add CFI start/end proc directives to arm64, i386, and ppc")
Fixes: 365638b0d498 ("rtld: preserve the FP and vector registers in __tls_get_addr() on powerpc64")
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62383
powerpc: zero the FPU save area in PT_SETVSRREGS when it was not valid
PT_SETVSRREGS marks the saved FPU registers valid and fills in the VSX
halves of VSR0-31. The FP registers and the FPSCR are left alone, and
on a thread that hasn't used the FPU since exec they still hold whatever
the previous program left there.
So after a PT_SETVSRREGS on such a thread PT_GETFPREGS and a core dump
show the FP registers of the program that ran before the exec, and the
new program gets them on its first FP instruction.
Zero the save area first when it wasn't valid, like set_fpregs() does.
Reported by: llm-postcr
Reviewed by: jhibbits
Fixes: 2ab5877e45d8 ("powerpc: use the register validity flags in the vector ptrace requests")
MFC with: 2ab5877e45d8
Differential Revision: https://reviews.freebsd.org/D62379
kern.post.mk: Really fix ports module build
The package target was never needed; we install directly from the
staging directory.
Fixes: b393df657811 ("kern.post.mk: Fix unprivileged ports module build")
pkill: Fix typo in test
The cleanup function for pkill -j <jname> had the wrong name.
PR: 301350
Fixes: 93f8c45c0314 ("pkill: Convert pgrep / pkill -j tests to ATF")
unix: increase net.local.(stream|seqpacket).(recv|send)space to 64 KiB
The limit of 8 KiB comes straight from the 80-ies, when memory sizes were
two orders of magnitude less. Microbenchmarking clearly shows that
increased maximum buffer size is needed to improve bulk transfer
performance over unix(4). Most operating system have larger default
sizes. This brings us another reason for increase. A buggy application,
that treats a stream socket as a datagram socket, shall work on Linux as
long as its messages are smaller than socket buffer size without any
issues 99.99% of time. But on FreeBSD it will instantly fail. In the
ports system there are already applications that suggest increase of this
sysctls for the application to work. We don't want to be a bug catcher
for bad applications in the default configuration.
Note that buffer size increase will not increase memory usage even on a
system with a million unix(4) sockets at normal runtime, as long as
applications are written properly and receivers drain their sockets and
system has enough CPU time for them to do that.
[5 lines not shown]
imgact_elf: accept PT_INTERP segments up to 4096 bytes
The Yocto/Poky relocatable SDK NUL-pads the interpreter path in
PT_INTERP out to 4096 bytes (within Linux's POSIX PATH_MAX) so that
'relocate_sdk.py' can rewrite the path in place. The kernel rejected
any PT_INTERP with p_filesz > BSD's MAXPATHLEN (1024) with
"Invalid PT_INTERP" and ENOEXEC, so none of the SDK's binaries could
be run under the Linuxulator.
- The PT_INTERP segment may now be up to 'PT_INTERP_SEG_MAXSZ'
bytes, which may be greater than 'MAXPATHLEN'.
- The interpreter path within the segment must still be shorter
than 'MAXPATHLEN' -- when violated results in 'ENAMETOOLONG'
when the interpreter is looked up.
Approved by: re (cperciva)
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D62075
(cherry picked from commit 7ee8d41ebb2ffb13e50ea59fd5bc43155123f323)
(cherry picked from commit cada5351b20f3dd1e146d558d0f44a8f9a1f9b52)
Revert "virtio_net: Use bus_dma for rxq/txq buffers"
This code is causing data corruption in 15.2-RC1 and needs to be fixed
before it lands in a release.
This reverts commit 6695c6bd0bf248927f34479a9ea2e13a6bf7db3d.
Approved by: re (cperciva)
Revert "virtio_net: Use bus_dma for command/ack buffers"
This code is causing data corruption in 15.2-RC1 and needs to be fixed
before it lands in a release.
This reverts commit 9291bb153595a4b10ef86cd3fee5b783835db819.
Approved by: re (cperciva)
vm_page: Make every shared unbusy a release
vm_page_sunbusy() and vm_page_busy_release() drop a shared busy that
other threads still hold with a relaxed atomic_fcmpset_int(). Only the
last sharer's update is a release, but any sharer can modify the page.
The next thread to busy the page exclusively synchronizes with the last
sharer's release, so on weakly ordered CPUs it need not see the changes
by a sharer that was not the last.
Found by: Claude Code (Opus 5.5)
Reviewed by: kib, markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62391