FreeBSD/src f25b4d9sys/arm/broadcom/bcm2835 bcm2838_pci.c

pci: bcm2838: cleanup on attach failure to fix devmatch panic

Specifically on the RPi CM4, we currently don't set the controller up
right and it never moves into the ready state (we don't observe the link
active bit).  Failure to cleanup here actually results in a panic not
long after, due to a use-after-free in the rman bits.  Further down in
pci_host_generic, we have some rman stashed in the softc that are
initialized and placed onto the rman tailq, then the softc is later
freed without an rman_fini() to pull them off of the tailq properly.

Note that PCIe on this board won't come up at boot without something
plugged in, so it currently can't be booted with an empty slot with the
intent to hotplug a supported card.  Some issues with controller startup
have been observed with Broadcom NICs in the wild, but no problems have
been observed with other NICs and a variety of different PCIe cards.

Shout-out to Vince <git at darkain.com> for the extensive debugging and
analysis to arrive at this conclusion.


    [3 lines not shown]
DeltaFile
+9-4sys/arm/broadcom/bcm2835/bcm2838_pci.c
+9-41 files

FreeBSD/src bddfcbdstand/lua core.lua cli.lua, stand/man loader.8

lualoader: add be-list and be-switch commands

This is useful for driving BE changes from the loader command prompt,
rather than having to use the menu.  Note that the active carousel in
the boot environment carousel doesn't currently reflect a switch in
boot environments done this way- I'm considering this only a minor bug,
as you probably can't or won't go back to the menu if you're using these
commands.

Reviewed by:    imp (previous version)

(cherry picked from commit c7ff706b31c22f10c2403869c46b443448da3e08)
DeltaFile
+43-0stand/lua/core.lua
+23-0stand/lua/cli.lua
+16-1stand/lua/core.lua.8
+14-1stand/man/loader.8
+1-6stand/lua/menu.lua
+97-85 files

FreeBSD/src 1f73372sys/dev/pci pci_host_generic_fdt.c pci_host_generic.c

pci: pci_host_generic: provide cleanup methods outside of detach

If device_attach() fails, we're expected to actually cleanup after
ourselves because device_detach() will not be called.  Factor out the
cleanup bits that don't rely on attach having actually succeeded so
that we can cleanup properly in bcm2838_pci.

Reviewed by:    andrew, imp

(cherry picked from commit 31a94ec32b53ebf6227bc868ce4f7aa07650680d)
DeltaFile
+19-0sys/dev/pci/pci_host_generic_fdt.c
+11-4sys/dev/pci/pci_host_generic.c
+1-0sys/dev/pci/pci_host_generic.h
+1-0sys/dev/pci/pci_host_generic_fdt.h
+32-44 files

FreeBSD/src 800c403sys/dev/ofw ofw_bus_subr.c ofw_bus_subr.h

kern: ofw: provide ofw_bus_destroy_iinfo to teardown interrupt-map

For symmetry with ofw_bus_setup_iinfo, the next commits will use it to
properly cleanup on failure in bcm2838_pci.

Reviewed by:    andrew

(cherry picked from commit b230a7b9a52c0fc948f4f1dcd1225a94674073f6)
DeltaFile
+12-0sys/dev/ofw/ofw_bus_subr.c
+1-0sys/dev/ofw/ofw_bus_subr.h
+13-02 files

FreeBSD/src 2db75e8sys/compat/linuxkpi/common/include/asm set_memory.h, sys/compat/linuxkpi/common/include/linux page.h

linuxkpi: work with numpages > 1 in the set_pages_*() KPIs

These calls are used for buddy pages at least in drm's ttm_pool, which
leads to a panic when we invoke lowmem handlers and drm tries to shrink
the pool.

Cope with numpages > 1 by traversing the contiguous pages and executing
the adjustment there, as well, as suggested by markj@.  Previous
versions have tried to use the corresponding `set_memory_*()` functions,
but it is believed that not updating `md.pat_mode` breaks subsequent
userspace mappings in ways that may result in things like screen tearing
or other artifacts when running i915kms.

This stabilized my amdgpu laptop running two VMs, chromium and a
concurrent buildworld.

Reviewed by:    bz, markj

(cherry picked from commit 67f7f2781daa9bd398b424ffe2bd0be67f37f03d)
(cherry picked from commit 8dad29555a5807bf21941807752e1589e20312de)
DeltaFile
+21-0sys/compat/linuxkpi/common/src/linux_page.c
+3-12sys/compat/linuxkpi/common/include/asm/set_memory.h
+2-0sys/compat/linuxkpi/common/include/linux/page.h
+26-123 files

FreeBSD/src 87224fasbin/devd devd.cc

devd: Use PF_LOCAL instead of PF_INET

Avoid dependency on INET (IPv4) by using PF_LOCAL,
allowing media check to work on systems without INET support.

PR:             295045
Reviewed by:    kevans

(cherry picked from commit b2e4da0b53ad082768b8f6f83766e030fd00d02a)
DeltaFile
+1-1sbin/devd/devd.cc
+1-11 files

FreeBSD/src ee07da0usr.sbin/jail config.c

jail: open the fstab files with fopen("re")

This protects against accidentally leaking them past fork()+exec()
in future refactorings.

PR:             295052
Reviewed by:    kevans

(cherry picked from commit 58811b0ae096c134af372bcf475aea1d8d0e3c08)
DeltaFile
+1-1usr.sbin/jail/config.c
+1-11 files

FreeBSD/src 0de1f3alib/libc/sys execve.2

fexecve(2): call out a scenario where you want !O_EXEC

We note a reason why you might need it, but there's an equally important
reason you may need to omit it: interpreted programs.  Add a note
accordingly, along with the workaround configuration if there's reason
you can't help it.

PR:             294780
Reviewed by:    Jan Bramkamp <crest_freebsd_rlwinm.de>, kib

(cherry picked from commit 9c18d55a768a3e60ecaba1325e9a3e00a25dee26)
DeltaFile
+12-1lib/libc/sys/execve.2
+12-11 files

FreeBSD/src 10b44bfusr.sbin/cron/cron cron.8 database.c

cron: log when a crontab path is too long

Log via syslog when snprintf truncates the crontab path, instead of
silently skipping the entry.

Signed-off-by:  Christos Longros <chris.longros at gmail.com>
Reviewed by:    bcr, kevans

(cherry picked from commit 91bfba010bcda665cc24a76af631cc85fcb0c688)
DeltaFile
+9-2usr.sbin/cron/cron/cron.8
+4-2usr.sbin/cron/cron/database.c
+13-42 files

FreeBSD/src 3129eceusr.sbin/ctld ctld.cc kernel.cc

ctld: kernel-sourced portal groups are not dummies

The current and historical versions of ctld would flag our initial set
of kernel ports as dummies, because their portal groups were empty since
portals come from the configuration on-disk.

As a result, we would never try to remove a kernel port at startup that
didn't exist in the configuration (possibly a feature if you wanted
concurrent ctld(8)), and we would always try to port->kernel_add() on
ports in the configuration (even if they actually did have an existing
kernel port).

Flag these portal groups as kernel groups so that we avoid trying to add
ports that already exist.  It may be the case that the kernel_remove()
loop in conf::apply() needs to do something other than the current
`oldport->is_dummy()` to avoid removing ports that it isn't supposed to
be managing, but that wuld also seem to apply to LUNs that would be
removed today.


    [3 lines not shown]
DeltaFile
+9-0usr.sbin/ctld/ctld.cc
+2-0usr.sbin/ctld/kernel.cc
+1-0usr.sbin/ctld/ctld.hh
+12-03 files

FreeBSD/src f77062fstand/lua core.lua cli.lua, stand/man loader.8

lualoader: add be-list and be-switch commands

This is useful for driving BE changes from the loader command prompt,
rather than having to use the menu.  Note that the active carousel in
the boot environment carousel doesn't currently reflect a switch in
boot environments done this way- I'm considering this only a minor bug,
as you probably can't or won't go back to the menu if you're using these
commands.

Reviewed by:    imp (previous version)

(cherry picked from commit c7ff706b31c22f10c2403869c46b443448da3e08)
DeltaFile
+43-0stand/lua/core.lua
+23-0stand/lua/cli.lua
+16-1stand/lua/core.lua.8
+14-1stand/man/loader.8
+1-6stand/lua/menu.lua
+97-85 files

FreeBSD/src 76720b0sys/arm/broadcom/bcm2835 bcm2838_pci.c

pci: bcm2838: cleanup on attach failure to fix devmatch panic

Specifically on the RPi CM4, we currently don't set the controller up
right and it never moves into the ready state (we don't observe the link
active bit).  Failure to cleanup here actually results in a panic not
long after, due to a use-after-free in the rman bits.  Further down in
pci_host_generic, we have some rman stashed in the softc that are
initialized and placed onto the rman tailq, then the softc is later
freed without an rman_fini() to pull them off of the tailq properly.

Note that PCIe on this board won't come up at boot without something
plugged in, so it currently can't be booted with an empty slot with the
intent to hotplug a supported card.  Some issues with controller startup
have been observed with Broadcom NICs in the wild, but no problems have
been observed with other NICs and a variety of different PCIe cards.

Shout-out to Vince <git at darkain.com> for the extensive debugging and
analysis to arrive at this conclusion.


    [3 lines not shown]
DeltaFile
+9-4sys/arm/broadcom/bcm2835/bcm2838_pci.c
+9-41 files

FreeBSD/src dc7494fsys/dev/pci pci_host_generic_fdt.c pci_host_generic.c

pci: pci_host_generic: provide cleanup methods outside of detach

If device_attach() fails, we're expected to actually cleanup after
ourselves because device_detach() will not be called.  Factor out the
cleanup bits that don't rely on attach having actually succeeded so
that we can cleanup properly in bcm2838_pci.

Reviewed by:    andrew, imp

(cherry picked from commit 31a94ec32b53ebf6227bc868ce4f7aa07650680d)
DeltaFile
+19-0sys/dev/pci/pci_host_generic_fdt.c
+11-4sys/dev/pci/pci_host_generic.c
+1-0sys/dev/pci/pci_host_generic.h
+1-0sys/dev/pci/pci_host_generic_fdt.h
+32-44 files

FreeBSD/src 92a2764sys/compat/linuxkpi/common/include/asm set_memory.h, sys/compat/linuxkpi/common/include/linux page.h

linuxkpi: work with numpages > 1 in the set_pages_*() KPIs

These calls are used for buddy pages at least in drm's ttm_pool, which
leads to a panic when we invoke lowmem handlers and drm tries to shrink
the pool.

Cope with numpages > 1 by traversing the contiguous pages and executing
the adjustment there, as well, as suggested by markj@.  Previous
versions have tried to use the corresponding `set_memory_*()` functions,
but it is believed that not updating `md.pat_mode` breaks subsequent
userspace mappings in ways that may result in things like screen tearing
or other artifacts when running i915kms.

This stabilized my amdgpu laptop running two VMs, chromium and a
concurrent buildworld.

Reviewed by:    bz, markj

(cherry picked from commit 67f7f2781daa9bd398b424ffe2bd0be67f37f03d)
(cherry picked from commit 8dad29555a5807bf21941807752e1589e20312de)
DeltaFile
+21-0sys/compat/linuxkpi/common/src/linux_page.c
+3-12sys/compat/linuxkpi/common/include/asm/set_memory.h
+2-0sys/compat/linuxkpi/common/include/linux/page.h
+26-123 files

FreeBSD/src a53d4b5sys/dev/ofw ofw_bus_subr.c ofw_bus_subr.h

kern: ofw: provide ofw_bus_destroy_iinfo to teardown interrupt-map

For symmetry with ofw_bus_setup_iinfo, the next commits will use it to
properly cleanup on failure in bcm2838_pci.

Reviewed by:    andrew

(cherry picked from commit b230a7b9a52c0fc948f4f1dcd1225a94674073f6)
DeltaFile
+12-0sys/dev/ofw/ofw_bus_subr.c
+1-0sys/dev/ofw/ofw_bus_subr.h
+13-02 files

FreeBSD/src b575dacsbin/devd devd.cc

devd: Use PF_LOCAL instead of PF_INET

Avoid dependency on INET (IPv4) by using PF_LOCAL,
allowing media check to work on systems without INET support.

PR:             295045
Reviewed by:    kevans

(cherry picked from commit b2e4da0b53ad082768b8f6f83766e030fd00d02a)
DeltaFile
+1-1sbin/devd/devd.cc
+1-11 files

FreeBSD/src dc0cc22lib/libsys execve.2

fexecve(2): call out a scenario where you want !O_EXEC

We note a reason why you might need it, but there's an equally important
reason you may need to omit it: interpreted programs.  Add a note
accordingly, along with the workaround configuration if there's reason
you can't help it.

PR:             294780
Reviewed by:    Jan Bramkamp <crest_freebsd_rlwinm.de>, kib

(cherry picked from commit 9c18d55a768a3e60ecaba1325e9a3e00a25dee26)
DeltaFile
+12-1lib/libsys/execve.2
+12-11 files

FreeBSD/src a03b45dusr.sbin/jail config.c

jail: open the fstab files with fopen("re")

This protects against accidentally leaking them past fork()+exec()
in future refactorings.

PR:             295052
Reviewed by:    kevans

(cherry picked from commit 58811b0ae096c134af372bcf475aea1d8d0e3c08)
DeltaFile
+1-1usr.sbin/jail/config.c
+1-11 files

FreeBSD/src 4a56809usr.sbin/ctld ctld.cc kernel.cc

ctld: kernel-sourced portal groups are not dummies

The current and historical versions of ctld would flag our initial set
of kernel ports as dummies, because their portal groups were empty since
portals come from the configuration on-disk.

As a result, we would never try to remove a kernel port at startup that
didn't exist in the configuration (possibly a feature if you wanted
concurrent ctld(8)), and we would always try to port->kernel_add() on
ports in the configuration (even if they actually did have an existing
kernel port).

Flag these portal groups as kernel groups so that we avoid trying to add
ports that already exist.  It may be the case that the kernel_remove()
loop in conf::apply() needs to do something other than the current
`oldport->is_dummy()` to avoid removing ports that it isn't supposed to
be managing, but that wuld also seem to apply to LUNs that would be
removed today.


    [3 lines not shown]
DeltaFile
+15-0usr.sbin/ctld/ctld.cc
+4-0usr.sbin/ctld/kernel.cc
+2-0usr.sbin/ctld/ctld.hh
+21-03 files

FreeBSD/src 52e2e6binclude/ssp stdio.h

ssp: fix our gets_s implementation under _FORTIFY_SOURCE

Annex K specifies an interface for handling constraint violations from
gets_s, but we previously broke this for some classes of get_s misuse.

Provide a more nuanced version that tries to dodge errors that would
trigger a constraint handler while still providing value.  Notably, we
don't want to trigger a failure unless the passed-in length reasonably
fits within an RSIZE_MAX, because gets_s will immediately call larger
lengths bogus and fail.

PR:             294881
Reviewed by:    markj

(cherry picked from commit d98f4f0698ef0c5178882c544b4c38542d4780f0)
DeltaFile
+29-1include/ssp/stdio.h
+29-11 files

FreeBSD/src 2edb8d4usr.sbin/cron/cron cron.8 database.c

cron: log when a crontab path is too long

Log via syslog when snprintf truncates the crontab path, instead of
silently skipping the entry.

Signed-off-by:  Christos Longros <chris.longros at gmail.com>
Reviewed by:    bcr, kevans

(cherry picked from commit 91bfba010bcda665cc24a76af631cc85fcb0c688)
DeltaFile
+9-2usr.sbin/cron/cron/cron.8
+4-2usr.sbin/cron/cron/database.c
+13-42 files

FreeBSD/src 89fa97fsys/compat/freebsd32 freebsd32_misc.c

compat32 wait4/6(2): only copy out when there is a pid to report

PR:     295965
Reported and tested by: mandree
Reviewed by:    markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D57513
DeltaFile
+4-8sys/compat/freebsd32/freebsd32_misc.c
+4-81 files

FreeBSD/src c85542brelease Makefile.gce

GCE: Apply public-image label on GCE images

Update the GCE image creation process to automatically apply the
'public-image=true' label when publishing new images. This aligns
with standard labeling expectations for images hosted in public
projects.

MFC after:      3 days
DeltaFile
+1-0release/Makefile.gce
+1-01 files

FreeBSD/src 925ca9bsys/compat/linux linux_socket.h linux_socket.c

linux: Add TCP_INFO support

Implement the getsockopt for TCP_INFO by mapping FreeBSD's version to
what Linux expects.

MFC after:      1 month
Relnotes:       yes
Reviewed by:    kib
Differential Revision:  https://reviews.freebsd.org/D55882
DeltaFile
+92-0sys/compat/linux/linux_socket.h
+44-3sys/compat/linux/linux_socket.c
+136-32 files

FreeBSD/src 1c85c5estand/efi/loader main.c

loader.efi: Search boot device before foreign ZFS pools

When `boot_policy` is `RELAXED`, `find_currdev()` tried ZFS pools on every
disk before searching the boot ESP and sibling partitions. Booting install
media from USB could therefore select an installed ZFS root on internal
storage instead of the intended memstick UFS image.

Extract the boot-device partition walk into `try_boot_device_partitions()`
and run it before relaxed foreign-pool probing. The ZFS search order is
preserved; pools on the boot device are tried first, followed by pools on
other devices when `boot_policy` is `RELAXED` and the boot device yields
no bootable root.

Signed-off-by: Faraz Vahedi <kfv at kfv.io>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/2239
DeltaFile
+72-53stand/efi/loader/main.c
+72-531 files

FreeBSD/src b52dc20sys/kern kern_jail.c

jail: Don't double-free the current prison in kern_jail_set/get

Reported by:    Yuxiang Yang, et al <yangyx22 at mails.tsinghua.edu.cn>
Discussed with: markj
MFC after:      3 days
DeltaFile
+10-4sys/kern/kern_jail.c
+10-41 files

FreeBSD/src a64877blib/libufs inode.c, sbin/fsck_ffs inode.c

Avoid incorrect UFS1 timestamp corrections when system clock fails at boot.

Git 1111a44301da - main - Defer the January 19, 2038 date limit in
UFS1 file systems to February 7, 2106 - did so by changing the UFS1
32-bit signed timestamps to unsigned. With this change, time stamps
from before January 1, 1970 went from being negative numbers to
large positive numbers implying times in the future. When such a
time stamp is encountered when an inode is read into memory or when
it is encountered by fsck, its timestamp is replaced with the
kernel's current time.

Andre Albsmeier reported that he had a machine reboot after a power
failure and the battery that maintained its real-time clock had
died. The result was that the system booted with the time set to
five years earlier (absent a real-time clock value, the boot ROM
used the time that the boot ROM had last been updated). The net
result was that fsck reset the time stamps of all files newer than
five years old to the five year old time.


    [31 lines not shown]
DeltaFile
+9-8lib/libufs/inode.c
+4-3sys/ufs/ffs/ffs_vfsops.c
+2-1sbin/fsck_ffs/inode.c
+15-123 files

FreeBSD/src 4497024sys/kern kern_procctl.c

reap_kill_subtree_once: when proctree_lock is dropped, reaper might change

Recalculate it to iterate over the right set of processes.

Prevent reaper' struct proc reuse by holding the tree ref on it.
Since our reference is taken under the proctree lock and we know that
the process is reaper, it cannot go away.  The process hold count
(p_lock) cannot be used there because p_lock intent is prevent exit, but
reaper owns its reap-children until reaped itself, i.e. even a zombie
reaper is still on duty.

Reviewed by:    markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D57492
DeltaFile
+29-14sys/kern/kern_procctl.c
+29-141 files

FreeBSD/src 85a65e3sys/kern kern_fork.c kern_exit.c, sys/sys proc.h

proc: add tree ref count

Owning the reference prevents reuse of the struct proc.

Reviewed by:    markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D57492
DeltaFile
+7-0sys/sys/proc.h
+2-1sys/kern/kern_fork.c
+1-1sys/kern/kern_exit.c
+1-0sys/kern/kern_proc.c
+11-24 files

FreeBSD/src a248c55sys/kern uipc_usrreq.c

connectat(2): do not enable EMPTYPATH for AT_FDCWD

This restores existing error code for connect(2) over unix domain socket
when the empty string is specified as socket address.

Reported by:    eduardo
Reviewed by:    markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D57509
DeltaFile
+3-2sys/kern/uipc_usrreq.c
+3-21 files