FreeBSD/src 45dbec2 — sys/compat/linux linux_elf.c, sys/kern imgact_elf.c

linux: Fix handling of an empty argv

proc_getargv() can return an sbuf with length zero.  In the Linux
note_prpsinfo() handler, this would cause "len" to underflow to -2,
resulting in a giant out-of-bounds memchr() loop.

There is no reason to subtract anything from the sbuf length to begin
with, the nul terminator is not included there.  Simplify the code to
fix this bug, and modify the native note handler to match.

Reported by:    Laam Alif at Ibteda Digital Library
Fixes:          00d17cf342cd ("elf_note_prpsinfo: handle more failures from proc_getargv()")
Reviewed by:    des, kib
MFC after:      1 week
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D62449
DeltaFile
+4-7sys/compat/linux/linux_elf.c
+3-6sys/kern/imgact_elf.c
+7-132 files

FreeBSD/src 8acb50d — usr.sbin/bhyve uart_backend.c

bhyve: disable SIGPIPE for TCP uart backend

Currently, if a TCP uart client disconnects while the guest is writing
to the serial port, a subsequent write to the socket raises SIGPIPE and
kills the VM.

Set SO_NOSIGPIPE on the listening socket to prevent that. Accepted
connections inherit it.

Reviewed by:    markj
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/D62215

(cherry picked from commit cbfe766aac6f316007438c9f5557dd0c99bcbad3)
DeltaFile
+4-0usr.sbin/bhyve/uart_backend.c
+4-01 files

FreeBSD/src daff3ca — usr.sbin/bhyve pci_virtio_console.c

bhyve: disable SIGPIPE for vtcons

Currently, if a virtio-console socket client closes the connection or
shuts down the read side, the next guest write to the socket
raises SIGPIPE and kills the VM.

Set SO_NOSIGPIPE on this socket to prevent that.

Reviewed by:    markj
Fixes:          13ee8dde0409 ("Add virtio-console support to bhyve.")
MFC after:      3 days
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D62216

(cherry picked from commit 293dac30b9955d64cff74f3d31138950cc6bfafe)
DeltaFile
+6-0usr.sbin/bhyve/pci_virtio_console.c
+6-01 files

FreeBSD/src c8a8b38 — lib/libc/sys modstat.2 kldstat.2, sys/kern kern_linker.c

kern_linker: Fix struct version mismatch

The kldstat(2) syscall supports two different structures, identified by
their size, which the application stores in the version field before the
call.  Since one is a prefix of the other, instead of calling different
functions to fill each one in like modstat(2) does, we fill in the
larger of the two and simply don't copy out the extra fields if the
smaller one was requested.  As a side effect, we failed to fill out the
version field in either case.  This causes application code that sets
the version field once and calls kldstat(2) repeatedly to fail since the
version field is now incorrect for subsequent calls, whereas the same
pattern works fine for modstat(2) because it copies the same version
value back out.  Fix this by setting the version field immediately
before copying the struct out.

While here, amend the manual pages for both kldstat(2) and modstat(2) to
clarify that the version field is unchanged on return and remove bad
advice about rebuilding world if either syscall returns EINVAL.


    [5 lines not shown]
DeltaFile
+3-12lib/libc/sys/modstat.2
+3-12lib/libc/sys/kldstat.2
+3-1sys/kern/kern_linker.c
+9-253 files

FreeBSD/src 7f5c523 — sys/conf kern.post.mk

kern.post.mk: Fix unprivileged ports module build

When building ports modules along with the kernel, we run the build
target during buildkernel, and the install target during installkernel.
This was fine back in the day when we installed ports straight from the
working directory, but these days we stage them first, then build a
package, and install the package.  This staging and packaging should be
seen as part of the build process, not the installation process, so we
should use the package target, rather than the build target, during
buildkernel.

This fixes an issue where doing buildkernel as an unprivileged user,
then installkernel as root, left a root-owned staging directory in the
kernel object tree which the next unprivileged buildkernel would be
unable to remove or replace.

MFC after:      1 week
Reviewed by:    imp
Differential Revision:  https://reviews.freebsd.org/D62195

    [20 lines not shown]
DeltaFile
+2-2sys/conf/kern.post.mk
+2-21 files

FreeBSD/src 9bb80b6 — sys/compat/linuxkpi/common/src linux_compat.c

linuxkpi: Make list_sort stable

Linux's list_sort() is intended to be stable, but linuxkpi implemented
it as a wrapper around qsort(), which is not.  This used to work because
our qsort() had a bug that effectively turned it into insertion sort,
but this is no longer the case.  Replace the qsort() call with an inline
implementation of insertion sort.

MFC after:      1 week
Reviewed by:    bz, markj
Differential Revision:  https://reviews.freebsd.org/D62194

(cherry picked from commit e79b273db1a92542c4efb90ed80b92643e6ea2a6)
DeltaFile
+27-26sys/compat/linuxkpi/common/src/linux_compat.c
+27-261 files

FreeBSD/src 0bb45ab — sys/conf kern.post.mk

kern.post.mk: Fix unprivileged ports module build

When building ports modules along with the kernel, we run the build
target during buildkernel, and the install target during installkernel.
This was fine back in the day when we installed ports straight from the
working directory, but these days we stage them first, then build a
package, and install the package.  This staging and packaging should be
seen as part of the build process, not the installation process, so we
should use the package target, rather than the build target, during
buildkernel.

This fixes an issue where doing buildkernel as an unprivileged user,
then installkernel as root, left a root-owned staging directory in the
kernel object tree which the next unprivileged buildkernel would be
unable to remove or replace.

MFC after:      1 week
Reviewed by:    imp
Differential Revision:  https://reviews.freebsd.org/D62195

    [20 lines not shown]
DeltaFile
+2-2sys/conf/kern.post.mk
+2-21 files

FreeBSD/src f9dab72 — lib/libsys modstat.2 kldstat.2, sys/kern kern_linker.c

kern_linker: Fix struct version mismatch

The kldstat(2) syscall supports two different structures, identified by
their size, which the application stores in the version field before the
call.  Since one is a prefix of the other, instead of calling different
functions to fill each one in like modstat(2) does, we fill in the
larger of the two and simply don't copy out the extra fields if the
smaller one was requested.  As a side effect, we failed to fill out the
version field in either case.  This causes application code that sets
the version field once and calls kldstat(2) repeatedly to fail since the
version field is now incorrect for subsequent calls, whereas the same
pattern works fine for modstat(2) because it copies the same version
value back out.  Fix this by setting the version field immediately
before copying the struct out.

While here, amend the manual pages for both kldstat(2) and modstat(2) to
clarify that the version field is unchanged on return and remove bad
advice about rebuilding world if either syscall returns EINVAL.


    [5 lines not shown]
DeltaFile
+3-12lib/libsys/modstat.2
+3-12lib/libsys/kldstat.2
+3-1sys/kern/kern_linker.c
+9-253 files

FreeBSD/src aa8de86 — sys/compat/linuxkpi/common/src linux_compat.c

linuxkpi: Make list_sort stable

Linux's list_sort() is intended to be stable, but linuxkpi implemented
it as a wrapper around qsort(), which is not.  This used to work because
our qsort() had a bug that effectively turned it into insertion sort,
but this is no longer the case.  Replace the qsort() call with an inline
implementation of insertion sort.

MFC after:      1 week
Reviewed by:    bz, markj
Differential Revision:  https://reviews.freebsd.org/D62194

(cherry picked from commit e79b273db1a92542c4efb90ed80b92643e6ea2a6)
DeltaFile
+27-26sys/compat/linuxkpi/common/src/linux_compat.c
+27-261 files

FreeBSD/src 1ff1ba5 — sys/cddl/dev/dtrace/powerpc dtrace_isa.c

dtrace/powerpc: leave the stack walker's own frame out

dtrace_getpcstack() and dtrace_getstackdepth() started with their own
frame. They call nothing, so no return address is ever saved in it and
the first thing the walk read was whatever the stack had there. When
that didn't look like an address the walk ended at once, and stackdepth
and caller were 0. When it did, everything was off by one frame: stack()
had one of DTrace's own functions on top, profile probes showed the
interrupted function twice and caller pointed into the provider.

Start with the caller's frame.

Reviewed by:    jhibbits
MFC after:      1 week
Differential Revision:  https://reviews.freebsd.org/D62453
DeltaFile
+10-2sys/cddl/dev/dtrace/powerpc/dtrace_isa.c
+10-21 files

FreeBSD/src 56e4c92 — sys/cddl/dev/sdt sdt.c

sdt: skip one more frame on powerpc64

sdt_dtrace_probe() ends with the call to dtrace_probe(), which is a
tail call elsewhere. On powerpc64 a call into another module can't be
one, so there is one more frame between the probe and dtrace_probe().
stack() began with sdt_probe() and caller was in sdt_probe(), which is
also what lockstat(1) printed as the caller of every lock.

Reviewed by:    jhibbits
MFC after:      1 week
Differential Revision:  https://reviews.freebsd.org/D62455
DeltaFile
+7-0sys/cddl/dev/sdt/sdt.c
+7-01 files

FreeBSD/src cbe0777 — sys/powerpc/powernv opal_async.c

powerpc/powernv: keep OPAL async messages within one page

opal_wait_completion() gives firmware the physical address of the
caller's buffer, and firmware copies the whole message there. The
callers keep the buffer on the stack, and the pages of a kernel stack
aren't physically contiguous, so a message that crosses a page boundary
ends up partly in some unrelated page.

Use a local buffer that can't cross a page and copy it to the caller.

Reported by:    llm-postcr
Approved by:    jhibbits (blanket)
MFC after:      1 week
DeltaFile
+11-1sys/powerpc/powernv/opal_async.c
+11-11 files

FreeBSD/src b50c2ed — sys/kern kern_rmlock.c

rmlock: remove unused pcpu pointer load in rm_runlock

Reviewed by:    kib, markj
Differential Revision:  https://reviews.freebsd.org/D61837
DeltaFile
+3-5sys/kern/kern_rmlock.c
+3-51 files

FreeBSD/src 1875480 — sys/kern kern_rmlock.c

rmlock: Micro-optimize read locking

Reapply c84bb8cd771c.  markj's original commit log:
    rmlock: Micro-optimize read locking

    Use get_pcpu() instead of an open-coded pcpu_find(td->td_oncpu).  This
    eliminates some memory accesses and results in a shorter instruction
    sequence.  Note that get_pcpu() didn't exist when rmlocks were added.

    Reviewed by:    jah, mjg
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34377

That optimization was subsequently reverted by
    afb44cb01018 ("rmlock: Temporarily revert commit c84bb8cd771c")
due to triggering panics on arm64.  The issue was diagnosed as arm64's
get_pcpu() using a register asm variable, allowing the compiler to
reorder accesses that were intended to be constrained by the pseudo

    [9 lines not shown]
DeltaFile
+2-2sys/kern/kern_rmlock.c
+2-21 files

FreeBSD/src b9b0cab — sys/fs/msdosfs msdosfs_conv.c

msdosfs: avoid buffer overflow in win2unixfn()

On UTF-8 mounts, since f983cb362de7, a high surrogate in the last
character of a long name slot is joined with the low surrogate kept
from the logically following slot and converted into a 4-byte UTF-8
sequence.  If the other 12 characters convert to 3 bytes each, the slot
fills all 40 bytes of name[], and the terminating NUL is written past
its end.

Size name[] for 4 bytes per character, the most win2unixchr() returns.

Reported by:    llm-postcr
Fixes:  f983cb362de7 ("fs/msdosfs: add support for file namws with surrogate pairs")
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
DeltaFile
+1-1sys/fs/msdosfs/msdosfs_conv.c
+1-11 files

FreeBSD/src 15f3cd9 — sys/kern subr_terminal.c, sys/sys terminal.h

kern: Enable respond to terminal

Shells like fish starts to query Device Capability from the kernel
terminal emulator. We already have the reply infras for each
protocols. The remaining part for this is to enable actual write.

Previously, we have lock issue from the respond side as
ttydisc_rint_done calls wakeup and takes the lock again.

The respond function now acts like queueing the response only, allo
of the output is handled in outwakeup. wakeup now handle queueing
after locking, which makes respond gets rid of locking from the parent.

After this, fish is able to run in the tty.

Reviewed by:    dumbbell
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D62192
DeltaFile
+31-15sys/kern/subr_terminal.c
+6-0sys/sys/terminal.h
+37-152 files

FreeBSD/src 694f3ac — sys/dev/ixgbe if_ix.c

ixgbe: Rearm the assigned MSI-X vector for each TX queue

iflib passes a TX queue index to ifdi_tx_queue_intr_enable. With
more TX queues than RX queues, using that index in the RX queue
array can read past the allocation.

Use the vector saved in the TX queue at interrupt assignment. This
is the same vector ixgbe_configure_ivars() programs for that ring.

MFC after:      1 week
Sponsored by:   BBOX.io
DeltaFile
+11-1sys/dev/ixgbe/if_ix.c
+11-11 files

FreeBSD/src 9e1a4f5 — sys/netinet6 nd6.c

nd6: fix function name in a comment

Fixes:  0d469d23715d690b863787ebfa51529e1f6a9092
DeltaFile
+1-1sys/netinet6/nd6.c
+1-11 files

FreeBSD/src 2960982 — sys/compat/linuxkpi/common/include/linux delay.h, sys/compat/linuxkpi/common/src linux_schedule.c

linuxkpi: sleep at least the requested time

msleep(), usleep_range() and msleep_interruptible() passed C_HARDCLOCK
to pause_sbt(), which measures the timeout from the last hardclock
tick, so they could return up to a tick early.  Linux guarantees the
minimum.

Approved by: adrian
Differential Revision:  https://reviews.freebsd.org/D62181
DeltaFile
+2-2sys/compat/linuxkpi/common/include/linux/delay.h
+1-1sys/compat/linuxkpi/common/src/linux_schedule.c
+3-32 files

FreeBSD/src 489139b — sys/dev/usb/serial uplcom.c

uplcom: write the baud rate directly on PL2303HXN

uplcom encodes a divisor for any rate that is not in its table.  The
PL2303HXN (G series) does not take divisors, so output stalled at such
rates.  Linux writes the rate directly for these chips.

Differential Revision:  https://reviews.freebsd.org/D62460
DeltaFile
+2-1sys/dev/usb/serial/uplcom.c
+2-11 files

FreeBSD/src b0c8b66 — libexec/bootpd README getether.h, libexec/bootpd/tools/bootptest Makefile bootptest.c

bootptest: use getifaddrs(3) to find an interface

The getif() restored in 6c3c05c5f131 is not really functional.  Put it
back into history and implement [supposedly] desired functionality with
getifaddrs(3).  Put getether() into history as well.

Reported by:    llm-postcr
Fixes:          6c3c05c5f131637b95574faead1bf3219978ad1d
DeltaFile
+0-385libexec/bootpd/getether.c
+42-85libexec/bootpd/tools/bootptest/bootptest.c
+0-53libexec/bootpd/trygetea.c
+0-3libexec/bootpd/getether.h
+0-2libexec/bootpd/README
+1-1libexec/bootpd/tools/bootptest/Makefile
+43-5296 files

FreeBSD/src 4e4ae3c — libexec/bootpd/bootpgw bootpgw.c

bootpgw: use getifaddrs(3) to find interface closest to 'your' address

The daemon is supposed to relay BOOTP packets between interfaces, and
of course routing replies back to original interface was incorrect.
Bring back a fresh implementation of getif() into handle_reply() that
uses a more modern API, but makes selection using the old logic.

Reported by:    llm-postcr
Fixes:          d4452259e75f3891b77302270e6f69057e2d9f2e
DeltaFile
+28-2libexec/bootpd/bootpgw/bootpgw.c
+28-21 files

FreeBSD/src fa19542 — sys/cddl/contrib/opensolaris/uts/powerpc/dtrace fasttrap_isa.c

dtrace/powerpc: continue after a conditional branch that isn't taken

When the pid provider emulated a bc, bclr or bcctr that wasn't taken,
it left the new pc at 0. The traced process jumped to address 0 and
died with SIGSEGV.

Go on with the next instruction instead.

Reported by:    llm-postcr
Reviewed by:    jhibbits
MFC after:      1 week
Differential Revision:  https://reviews.freebsd.org/D62431
DeltaFile
+6-2sys/cddl/contrib/opensolaris/uts/powerpc/dtrace/fasttrap_isa.c
+6-21 files

FreeBSD/src 267071f — sys/cddl/contrib/opensolaris/uts/powerpc/dtrace fasttrap_isa.c, sys/cddl/contrib/opensolaris/uts/powerpc/sys fasttrap_isa.h

dtrace/powerpc: emulate the xor of USDT is-enabled sites

dtrace -G turns the call at an is-enabled site into xor r3,r3,r3. In
a 32-bit process the tracepoint for that site ends up on the xor
itself, and the pid provider doesn't know that instruction, so since
22aad251ed64 it refuses the tracepoint and the probe can't be enabled.
dtrace doesn't say so. 64-bit processes aren't affected, their
tracepoint is on the nop after the xor.

Emulate xor rA,rS,rS.

Reported by:    llm-postcr
Reviewed by:    adrian
Fixes:          22aad251ed64 ("dtrace/powerpc: refuse pid tracepoints that would need a single step")
MFC with:       22aad251ed64
Differential Revision:  https://reviews.freebsd.org/D62448
DeltaFile
+8-0sys/cddl/contrib/opensolaris/uts/powerpc/dtrace/fasttrap_isa.c
+1-0sys/cddl/contrib/opensolaris/uts/powerpc/sys/fasttrap_isa.h
+9-02 files

FreeBSD/src 29abde9 — sys/powerpc/linux linux_sysvec.c

linuxulator/powerpc: look AT_PLATFORM up by PVR

The feature bits don't tell the CPUs apart well enough. e5500 and e6500
are ISA 2.06 as well, so they got power7, and Linux programs that check
for it may then use VSX, which neither core has.

Use a table keyed by the PVR instead, with the names Linux uses. This
also sorts out ppc970, POWER5, POWER7+, POWER11 and Cell.

Reported by:    llm-postcr
Suggested by:   jhibbits
Approved by:    jhibbits (blanket)
Fixes:          79d5c5beab28 ("linuxulator/powerpc: report the CPU family in AT_PLATFORM")
DeltaFile
+33-16sys/powerpc/linux/linux_sysvec.c
+33-161 files

FreeBSD/src b82b4c2 — sys/net if_bridge.c, tests/sys/net Makefile if_bridge_test.sh

if_bridge: Fix a NULL dereference on frames injected by netmap

A frame that a netmap application writes to a bridge's host ring
enters bridge_input() with the bridge itself as the receiving
interface.  bridge_input() looks up the member that owns the source
address and continues with that member as ifp, but since 85967694b459
it takes bif from ifp->if_bridge before the lookup, so bif stays NULL.
The first injected frame with a known source address panics in
bridge_vfilter_in(), so any netmap application on a bridge, such as
Suricata in inline mode, panics the kernel as soon as it passes traffic.

Take the member from the address table entry instead, and add a test
that passes traffic through a bridge in netmap mode.

Reviewed by:            kp
MFC after:              1 week
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D62445
DeltaFile
+61-0tests/sys/net/if_bridge_test.sh
+7-3sys/net/if_bridge.c
+1-1tests/sys/net/Makefile
+69-43 files

FreeBSD/src ba02122 — contrib/llvm-project/llvm/include/llvm/CodeGen RDFGraph.h RDFRegisters.h, contrib/llvm-project/llvm/lib/CodeGen RDFLiveness.cpp

Merge commit a558d6560437 from llvm-project (by A. Jiang):

  [CodeGen] Get rid of incorrect `std` template specializations (#160804)

  This patch renames comparators
  - from `std::equal_to<llvm::rdf::RegisterRef>` to
  `llvm::rdf::RegisterRefEqualTo`, and
  - from `std::less<llvm::rdf::RegisterRef>` to
  `llvm::rdf::RegisterRefLess`.

  The original specializations don't satisfy the requirements for the
  original `std` templates by being stateful and
  non-default-constructible, so they make the program have UB due to C++17
  [namespace.std]/2, C++20/23 [namespace.std]/5.

  > A program may explicitly instantiate a class template defined in the
  standard library only if the declaration
  > - depends on the name of at least one program-defined type, and
  > - the instantiation meets the standard library requirements for the

    [7 lines not shown]
DeltaFile
+28-26contrib/llvm-project/llvm/include/llvm/CodeGen/RDFRegisters.h
+5-4contrib/llvm-project/llvm/lib/CodeGen/RDFLiveness.cpp
+4-4contrib/llvm-project/llvm/lib/Target/Hexagon/RDFCopy.h
+1-1contrib/llvm-project/llvm/lib/Target/Hexagon/RDFCopy.cpp
+1-1contrib/llvm-project/llvm/include/llvm/CodeGen/RDFGraph.h
+39-365 files

FreeBSD/src e5d1bcf — libexec/bootpd bootpd.c

bootpd: preserve request flags in reply

RFC 1542 §5.4: "the server MUST preserve the state of the BROADCAST flag
so that the relay agent can correctly act upon it."

Reported by:    llm-postcr
Fixes:          7d8b5bd3f15ba99343e2d93c53ac73cc4bc550f0
DeltaFile
+0-2libexec/bootpd/bootpd.c
+0-21 files

FreeBSD/src 6c3c05c — libexec/bootpd/tools/bootptest Makefile bootptest.c

bootptest: fix build

This tool needs getif(), that had been removed in 7d8b5bd3f15b.

Fixes:  7d8b5bd3f15ba99343e2d93c53ac73cc4bc550f0
DeltaFile
+76-3libexec/bootpd/tools/bootptest/bootptest.c
+1-1libexec/bootpd/tools/bootptest/Makefile
+77-42 files

FreeBSD/src 1a95125 — libexec/bootpd bootpd.c

bootpd: better handle getifaddrs() results

Pick up the first matching address, not the last.  Check if getifaddrs()
failed.

Reported by:    llm-postcr
Fixes:          7d8b5bd3f15ba99343e2d93c53ac73cc4bc550f0
DeltaFile
+5-1libexec/bootpd/bootpd.c
+5-11 files