kern/kern_exit.c: fix decision to give back to real parent in proc_reap()
p_oppid records the reaper by pid only, and nothing updates p_oppid when
the reaper changes. When p_oppid no longer matches, proc_realparent()
falls back to p_reaper. In proc_reap(), the test p_oppid !=
p_pptr->p_pid is then still true, so proc_reap() "gives back" the child
to proc_realparent(). That resolves to the new reaper, which is already
p_pptr. proc_reparent() returns early, the reaper gets a spurious
SIGCHLD, and proc_reap() returns without reaping.
Another problem with p_oppid check is that a parked zombie is leaked
permanently under the new reaper if the reaper changes before the
debugger waits, because p_oppid keeps the old reaper's pid.
In proc_reap(), base the give-back decision on the resolved parent
instead of the pid comparison.
Reported by: llm-postcr
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
contrib/lutok: update generated headers/build glue
lutok and kyua have both been updated for the new tests and the adjusted
header layout.
MFC after: 1 week
MFC with: 5e4c3200cdc7 ("contrib/lutok: update to 0.7.1")
contrib/lutok: update to 0.7.1
This is a bugfix release. Users are encouraged to take this version.
MFC after: 1 week
Merge commit 'dac7d818e3cef52d724592c6b349dbd8ad9a049a'
contrib/lutok: compile/run tests from the project
This change adds the necessary glue to build and run the tests
distributed with each release, sans the examples tests. liblutok is
an "internal" library, so the headers and library aren't distributed
with installworld, et al, and thus the examples tests--which require the
headers/library to build tests on the fly--fail when the tests are run,
due to this difference with the upstream project.
MFC after: 1 week
iflib: remove the legacy interrupt before freeing the queues
iflib_device_deregister() and the iflib_device_register() failure path
freed the queue structures and ran IFDI_DETACH before tearing down an
INTx or MSI handler. A shared INTx line can run the driver filter and
iflib_fast_intr_rxtx() at any time, so another device's interrupt in
that window used freed queues and driver state. Tear the handler down
before anything is freed.
Reported by: llm-postcr
Reviewed by: gallatin
Differential Revision: https://reviews.freebsd.org/D62040
iflib: clear an interrupt after freeing it
em(4) and several other drivers free their MSI-X vectors when
IFDI_MSIX_INTR_ASSIGN fails, then free them again from IFDI_DETACH,
which iflib's attach failure path runs next. The second
iflib_irq_free() tears down a stale tag and releases a stale resource.
Clear both so it is a no-op.
Reviewed by: gallatin
Differential Revision: https://reviews.freebsd.org/D62039
lutok: import lutok-0.7.1
This change adds lutok lutok-0.7.1 from upstream [1].
The lutok-0.7.1 artifact was been verified by SHA256 checksum [2].
This is a bugfix release.
The core issues addressed in this release relate to memory handling in edge
cases and a handful of build-related bugfixes found when enabling ASAN in CI.
A huge shoutout goes to @holmuk for the findings and fixes made in the library.
Users are encouraged to upgrade to this release.
More information about the release (from a high level) can be found in
the release notes [3].
Updated with [4] like: `update_lutok.sh 0.7.1 lutok-0.7.1`.
[5 lines not shown]
linuxkpi: set M_AMPDU for NICs that require host reordering
Set the M_AMPDU flag on RX packets for NICs that require host
reordering.
The reporter (Denis) sees a traffic increase from ~ 100Mbit/sec
to ~365Mbit/sec and a decrease in dropped frames due to RX
sequence / RX CCMP PN reordering.
PR: 300862
Obtained from: Denis Lemire <denis at lemire.name>
MFC after: 1 month
ipfw: Destroy global state after the vnets on unload
A module's MOD_UNLOAD handler runs before any of its SYSUNINITs. Since
ipfw_destroy() moved into MOD_UNLOAD, vnet_ipfw_uninit() runs after it
and takes locks that ipfw_destroy() has already destroyed: the sockopt
handler lock, and vnet_mtx in a vnet that tracks interfaces. kldunload
ipfw panics with INVARIANTS:
panic: mtx_lock() of destroyed mutex @ sys/netpfil/ipfw/ip_fw_sockopt.c:3038
ipfw_del_sopt_handler() <- ipfw_destroy_tables() <- vnet_ipfw_uninit()
<- vnet_deregister_sysuninit() <- linker_file_sysuninit()
<- linker_file_unload()
Call ipfw_destroy() from a SYSUNINIT at SI_ORDER_FIRST instead, which
runs after the SI_ORDER_SECOND vnet teardown, as before 9bcc1e97dda8
and as pf does for pf_unload().
Reviewed by: glebius
Fixes: 9bcc1e97dda8 ("ipfw: cleanup SYSINIT(9)s")
[2 lines not shown]
ipfw: Run the vnet hooks of ipfw_nat, nat64 and nptv6 after ipfw's
9bcc1e97dda8 put the SYSINITs of ipfw_nat, ipfw_nat64 and ipfw_nptv6
at SI_ORDER_SECOND, the order of ipfw's own vnet hooks; before, they
ran after them.
In ipfw_nat, the module-wide hooks and the vnet hooks now share that
order too, which leaves their relative order to the sort. As built,
kldunload ipfw_nat runs ipfw_nat_destroy() first: it clears
ipfw_nat_ptr and lookup_nat_ptr while every vnet still has
V_ipfw_nat_ready set, and a packet that hits a nat rule in between
calls a NULL pointer:
(null)() at 0 <- ipfw_check_packet <- pfil_mbuf_in <- ip_input
Loading can open the same window the other way around.
The vnet hooks of all three modules also tie with ipfw's, and run after
them on vnet creation and before them on destruction only because ipfw
[10 lines not shown]
ipfw: Drain the state expiry task before taking the upper half lock
vnet_ipfw_uninit() takes the upper half lock and then drains the task
that expires dynamic states. Since 331333ba0186 that task, dyn_tick(),
takes the same lock, so when it fires while a vnet is being destroyed
the two wait for each other and jail -r hangs:
jail: taskqueue_drain_timeout <- vnet_ipfw_uninit <- vnet_destroy
swi6: _sx_xlock <- dyn_tick <- taskqueue_run_locked
Drain the task first. The pfil hooks and the sockopt handler are
detached by then, and dyn_tick() takes the lock itself.
Reviewed by: glebius
Fixes: 331333ba0186 ("ipfw: hold sleepable "upper half...")
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D62245
tests/sys/kern/procdesc: test the debugger's wait after the last close
Attach a debugger to a PD_NOWAITPID child, let the child exit, and let
the parent close the last process descriptor before the debugger waits.
Check that a debugger which is neither the parent nor the reaper can
still wait for the child, which then goes to the reaper, and that a
reaper which is the debugger can collect the child.
The child exits on its own: kill(2) does not kill a traced process, it
only stops it for the debugger.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
amd64, powerpc64: treat procctl(P_PID, 0) as request for current process
Discussed with: markj
Fixes: f833ab9dd187 ("procctl(2): add consistent shortcut P_ID:0 as curproc")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61919
tests/sys/kern/procdesc: test the reap by a close from a non-parent
The parent waits for its pdfork(2) child, and then another process,
which inherited the descriptor over fork(2), closes the last one and so
reaps the zombie. Check that the child's resource usage is accounted
to the parent and not to the closing process, and that the child's
SIGCHLD is no longer pending for the parent.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
proc_reap(): account the reaped child to its parent
When the last process descriptor of a zombie is closed by a process
other than its parent, proc_reap() added the child's resource usage to
the closing process instead of the parent. Add it to the parent, and do
it before dropping proctree_lock, which keeps the parent from being
reaped meanwhile.
Reported by: llm-postcr
Fixes: cfb5f7686588 ("Add experimental support for process descriptors")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
proc_reap(): dequeue the child's SIGCHLD under the parent's lock
p_ksi is only queued to the parent, but proc_reap() took it off the
queue with the caller locked. When the last process descriptor of a
zombie is closed by a process other than its parent, e.g. one which
inherited the descriptor over fork(2) or opened it with pdopenpid(2),
the parent's signal queue and p_pendingcnt were modified without the
parent's lock.
Since bcdb6ba94d08 this is easy to hit: a pdfork(2) child without
PD_NOWAITPID signals its parent with p_ksi on exit, and while the
descriptor is open, the parent's wait only drops PZOMBIEREF_PARENT and
leaves p_ksi queued if the parent blocks or catches SIGCHLD.
Lock the parent, as proc_reparent() does.
Reported by: llm-postcr
Fixes: cfb5f7686588 ("Add experimental support for process descriptors")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
procdesc_close(): leave a zombie parked at its debugger with it
A debugger which is not the parent of a PD_NOWAITPID child, and got the
child via PT_ATTACH, can wait for the child after it exited. If the
parent closed the last process descriptor before the debugger waited,
the close dropped the last zombie reference, and proc_reap() gave the
zombie back to the real parent. The real parent cannot wait for a
PD_NOWAITPID child, and the debugger got ECHILD, so the zombie stayed
until the real parent exited.
Handle a zombie parked at its debugger as procdesc_close() handles a
traced live process: keep it with the debugger, and make the reaper the
real parent. The debugger's wait then gives the zombie to the reaper,
which proc_reparent() lets wait for it. A debugger which is the reaper
gets PZOMBIEREF_PARENT right away.
Reported by: llm-postcr
Fixes: bcdb6ba94d08 ("processes: add zombie references, each of them prevents reap")
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
kern.post.mk: Further refine ports module build
A handful of kmod ports have NO_PACKAGE set, which disables the package
target, which means the previous commit made things worse for those
ports rather than better. Work around this by explicitly building the
stage target first.
Fixes: b393df657811 ("kern.post.mk: Fix unprivileged ports module build")
rtwn: (RTL8192FU) fix init, with_ucode build and tx power handling
- added noop for RTWN_WITHOUT_UCODE builds on sc_set_media_status
- fixed upper bound of power delta for MCS for HT20/HT40 in tx power
- moved reading per channel bb trim values after efuse and bb initialization
- use 256 bytes per TX pages as per vendor and linux rtl8xxxu
- added tab character instead of spaces in share/misc/usb_vendors after the device name
Tested on RTL8192FU
Sponsored by: Alchemilla Ventures Private Limited
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D62241
Reported by: llm-postcr
Fixes: 1f0e186e1832 ("rtwn: added support for Realtek RTL8192FU...")
rge(4): Fix build without INET
rge_tx_pad() calls in_delayed_cksum_o() and in_cksum_skip()
unconditionally. in_delayed_cksum_o() lives in netinet/ip_output.c
(optional inet) and in_cksum_skip() lives in netinet/in_cksum.c
(optional inet | inet6). So kernels with "device rge" and no
INET fail to link. This breaks LINT-NOINET and LINT-NOIP.
Include opt_inet.h, add it to the module's SRCS, and wrap the IPv4
software checksum block in #ifdef INET.
Fixes: e3ded948ad41 ("rge(4): Implement RTL8125 UDP hardware workaround")
Reported by: llm-postcr
Differential Revision: https://reviews.freebsd.org/D62240
libsys: Split out a new libsys_private.h from libc's libc_private.h
Downstream we have accidentally ended up referencing libc symbols from
within libsys, which went unnoticed because in practice libc is always
loaded whenever libsys is. Split out a new header to detect such cases
at build time, without relying solely on the test recently added in
493c84741c45 ("libsys: add test checking that -lsys alone is linkable").
Note we still add libc to the compiler's include path for compat.h and
(un-)namespace.h, but none of these provide declarations. Ideally that
would also be refactored, but that is a more invasive change.
Copyright header copied from those added by kib@ in 8495e8b1e9e1 ("Fix
known issues which blow up the process after dlopen("libthr.so") (or
loading a dso linked to libthr.so into process which was not linked
against threading library)."), the commit that introduced what is almost
all the code in this header; none of this code originates from jb@, to
whom libc_private.h is attributed.
[3 lines not shown]
libfetch: Fix buffer overruns in FTP code
* When parsing the reply to a CWD, PWD, or CDUP command, if we ran out
of space in the destination buffer, we would correctly terminate the
loop, but then incorrectly see the remaining length as non-zero,
causing us to write a terminating NUL one past the end of the buffer
and report success instead of a protocol error. Additionally, the
code would fail to notice an improperly terminated pathname, and was
hard to follow, so rewrite the entire loop.
* When comparing the current working directory to the intended working
directory to calculate the minimal operation to get from one to the
other, if the current working directory was an empty string, we would
improperly read one byte below the start of the intended working
directory.
MFC after: 1 week
Reported by: Laam Alif at Ibteda Digital Library
Differential Revision: https://reviews.freebsd.org/D61502
[2 lines not shown]
libfetch: Fix buffer overruns in FTP code
* When parsing the reply to a CWD, PWD, or CDUP command, if we ran out
of space in the destination buffer, we would correctly terminate the
loop, but then incorrectly see the remaining length as non-zero,
causing us to write a terminating NUL one past the end of the buffer
and report success instead of a protocol error. Additionally, the
code would fail to notice an improperly terminated pathname, and was
hard to follow, so rewrite the entire loop.
* When comparing the current working directory to the intended working
directory to calculate the minimal operation to get from one to the
other, if the current working directory was an empty string, we would
improperly read one byte below the start of the intended working
directory.
MFC after: 1 week
Reported by: Laam Alif at Ibteda Digital Library
Differential Revision: https://reviews.freebsd.org/D61502
[2 lines not shown]
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