tests/ssl_sendfile: fix flakyness under load
When loopback TCP delivery is faster than our sending thread it may take
several writes to full buffer reliably.
PR: 299447
syslogd/tests: wait for tcpdump before sending the message
The forwarded and relayed format tests could send the message before tcpdump
attached to lo0, so "tcpdump -c 1" never saw it and the test hung until the
300s timeout. Also make syslogd_stop_on_ports stop every port it is given.
Reviewed by: markj
Approved by: markj
Sponsored by: Netflix
Differential Revision: https://ron-dev.freebsd.org/FreeBSD/src/pulls/108
axgbe: return positive errno values from the sysctl handlers
Return positive errno values from the FreeBSD sysctl handlers so that
userland reports the proper error instead of "Unknown error: -22".
Convert the negative phy_config_aneg() result at the sysctl boundary,
matching axgbe_if_media_change(), and retain the PHY code's internal
error convention.
Differential Revision: https://reviews.freebsd.org/D61400
(cherry picked from commit c89613ded9237811d35a42788e9728fe0404e26b)
axgbe: bound the sysctl parser writes in get_val()
Reject tokens and option counts that exceed the fixed parser buffers,
and fix the terminating NUL offset. Have the sysctl handlers propagate
parser errors before applying settings.
Handle SYSL_U32 options and reject failed numeric conversions instead of
using an uninitialized value. Fix the duplex case falling through to an
error, and initialize the link-setting strings for unexpected speeds.
Differential Revision: https://reviews.freebsd.org/D61339
(cherry picked from commit 5523a8ba6f618fa5c853450dd551d8a5f06715ca)
modstat: check errno before calling feature_present
feature_present will overwrite errno if COMPAT_FREEBSD13 is not present.
Approved by: re (cperciva)
Reported by: llm-postcr
Fixes: ef726c645300 ("modstat: allow compat support to fail in tests")
(cherry picked from commit acd270c8c6542b45e404078b28e1a732106aa76c)
(cherry picked from commit ed8dc5e715fff0a0c9f60416362924315bb49381)
modstat: allow compat support to fail in tests
v1 and v2 versions of stuct module_stat are now gated by COMPAT_ ifdefs
so allow the otherwise valid query to fail with EINVAL.
Approved by: re (cperciva)
Effort: CHERI upstreaming
Reviewed by: markj
Reported by: llm-postcr
Sponsored by: Innovate UK
Fixes: 1ebf46ecb627 ("modstat: don't copyout while holding a lock")
Differential Revision: https://reviews.freebsd.org/D61460
(cherry picked from commit ef726c645300870b6bdf3573079b1f89f3b45c74)
(cherry picked from commit 4a9770b9256c7119da287b15a6e7900298e6d514)
modstat: don't copyout while holding a lock
If a user arranges for a page fault to never be filled (e.g., via a
FUSE file system), this can hold the shared lock forever.
To make this all work, refactor kern_modstat and freebsd32_modstat to
malloc a temporary buffer and fill it before copying it out rather
than doing a bunch of copies.
Add COMPAT_* ifdefs around compat code. The module_stat_v1 code is
really for a.out binaries in practice and thus a bit questionable.
Approved by: re (cperciva)
Reviewed by: markj
Reported by: llm-postcr
Sponsored by: Innovate UK
Fixes: 7f8c2056db1e ("modstat: avoid copying from freed memory")
Differential Revision: https://reviews.freebsd.org/D61432
[2 lines not shown]
modstat: avoid copying from freed memory
If a module is unloaded after the module is looked up in kern_modstat,
but before one of the copyout's occurs, then the memory being copied
might be freed and reused leading to an information disclosure.
The LLM was particularly concerned about a TOCTOU issue in the length
of the name, but it seems likely that there are issues with all the
copyout's. As such, hold the shared lock throughout.
Approved by: re (cperciva)
Reviewed by: markj
Reported by: llm-postcr
MFC after: 3 days
Sponsored by: Innovate UK
Fixes: 9b3851e9e3b1 ("- Lock down the ``module'' structure...")
Differential Revision: https://reviews.freebsd.org/D61398
(cherry picked from commit 7f8c2056db1e39e44c3eda15aa4e53f7fc971cd8)
(cherry picked from commit 80fed5b6b5bdf712603b90a236796e35ed7e604c)
powerpc/pmap: Use dcbz to zero pages in the radix pmap
pagezero() was a plain store loop (bzero), which under the kernel build
flags (-mno-vsx -msoft-float) compiles to byte stores. dcbz
establishes a zeroed cache line directly in the cache without a
read-for-ownership fetch from memory, roughly halving the memory
transactions of page zeroing.
Measured on POWER9 (Raptor Blackbird, DD2.3, bare metal), zeroing a
cold 256 MB buffer with 128-byte scalar loops:
byte stores (current libkern memset) 8.6 GB/s
doubleword (std) stores 26.8 GB/s
dcbz 34.6 GB/s
dcbz raises an alignment interrupt on caching-inhibited mappings, and
the kernel does not emulate it, so mmu_radix_zero_page() falls back to
bzero() for any page whose memattr is not the write-back default. The
internal pagezero() callers only touch freshly allocated page-table
[13 lines not shown]
linux: do not truncate the listxattr() size
listxattr() sized its buffer with min(), which truncates the 64-bit
size to 32 bits, so a size of 2^32 + k allocated k bytes while the
copy-out guard used the full size. The walk then read record lengths
past the buffer and copied kernel heap out to the caller, and could
panic the kernel. Any user can reach it through a user.* attribute on
a file it owns.
Use MIN(), and fail with EIO if a record runs past the data returned.
Approved by: re (cperciva)
Reviewed by: adrian, markj
Approved by: adrian (mentor)
Differential Revision: https://reviews.freebsd.org/D61006
Signed-off-by: Nick Price <nprice at FreeBSD.org>
(cherry picked from commit fbe4835e6b1eec36103a5ce97efbab11b3b5fc72)
(cherry picked from commit a46d6ae4c0b6f6e8eb74b13da6f607d2ead74be7)
ktls: Check the record type message holds its byte
sosend_generic() read the TLS record type past a TLS_SET_RECORD_TYPE
control message holding only a cmsghdr, and sent that stale byte.
Approved by: re (cperciva)
Approved by: markj
Fixes: b2e60773c6b0 ("Add kernel-side support for in-kernel TLS.")
Sponsored by: Netflix
(cherry picked from commit bd4975e5fb051c2b2e8d5218940b7e8ef87b5bdf)
(cherry picked from commit 42e7802e24fefd1cef6913ab162cda2c7bdc477f)
tcp: improve consistency
Use an inline function tcp_adapt_iss_check() to perform the check
consistently instead of replicating the code multiple times. These
checks already became inconsistent.
A fix for PR 298560 requires more calls to tcp_adapt_iss_check().
Reviewed by: Peter Lei
Fixes: fa2ad70a4511 ("tcp: make ghost ACK handling more conformant")
MFC after: 3 days
MFC to: stable/14
MFC to: stable/15
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D61685
bhyve: Do not abort when the VM is destroyed during an exit
When a VM is destroyed (bhyvectl --destroy) while a vCPU thread is
handling an exit in bhyve, every call on the VM fails. vm_loop()
handles that for vm_run() and ends bhyve with BHYVE_EXIT_ERROR, but a
vCPU in the middle of an exit hits one of the assert(error == 0) after
a register update or an exception injection (emulate_inout(),
vmexit_rdmsr(), vm_inject_fault()), or reports "Failed to emulate
instruction" and returns VMEXIT_ABORT: bhyve dies of SIGABRT and
leaves a core. With a guest doing a lot of port I/O or MSR accesses
that bhyve emulates, a forced stop hits this regularly.
Add vm_check_destroyed(), which exits with BHYVE_EXIT_ERROR, as
vm_loop() does, if the VM is gone. Call it before those asserts and
on the instruction emulation failure paths on amd64, arm64 and
riscv. A failure on a VM that still exists asserts or aborts as
before.
Signed-off-by: Wanpeng Qian <wanpengqian at gmail.com>
[4 lines not shown]
amd64/pt.c: Clear ToPa PMI status for stray interrupts
An inactive tracing session might encounter stray ToPA PMI
interrupts, in which case the interrupt handler skips processing
the interrupt but fails to reset the ToPA status bit.
amd64/pt.c: Plug a 'pt_backend_alloc_thread' error path memory leak
The thread-mode allocation method failed to release the previously
allocate `pt_ctx` structure on error.
Fixes: 310162ea218a
amd64/pt.c: Align ToPA table to page size
The Intel SDM states that the ToPA table must by 4k-aligned, and any
alignment issues will cause an operational error and disable tracing.
The default buffer size prevented this from happening, but a smaller
buffer size could hit this issue. Fix this by explicitly allocating
the ToPA table with malloc_aligned.
Fixes: 310162ea218a
unix: Do not copy out internalized SCM_RIGHTS on MSG_PEEK
recvmsg(2) with MSG_PEEK on a queued SCM_RIGHTS message copied the
control data out in its internalized form, an in-kernel struct file
pointer per descriptor, instead of as file descriptors. The
stream/seqpacket receive method noted this in an XXXGL comment; the
datagram peek path behaved the same way.
On a peek, return the SCM_RIGHTS message with -1 in place of each
descriptor. A descriptor is a non-negative integer, so -1 tells the
caller that descriptors are queued without installing any; they are
delivered by the next non-peek receive. Other control messages (e.g.
SCM_CREDS) are still returned. Document this in unix(4).
Reviewed by: glebius, markj
Suggested by: glebius
Pull Request: https://github.com/freebsd/freebsd-src/pull/2469
Signed-off-by: Patrick Crandol <patrick at crandol.com>
tests: unix: Check that MSG_PEEK returns -1 for SCM_RIGHTS
Add a regression test that a MSG_PEEK receive of a queued SCM_RIGHTS
message returns -1 in place of the descriptor, while other control
messages, here SCM_CREDS, are still returned, and that the following
receive still delivers the descriptor.
Signed-off-by: Patrick Crandol <patrick at crandol.com>
ipsec: Reject an AH IPv4 option that runs past the header
ah_massage_headers() zeroed each mutable IPv4 option before checking its
length fit the header, so an option length byte could write up to 255 zero
bytes past the IP header (and the mbuf) when ip_dooptions() had not
validated the options (process_options=0).
With the check done up front, the post-switch off > skip test is dead;
remove it.
Reviewed by: markj, rcm
Approved by: markj, rcm
Sponsored by: Netflix
Fixes: b12a7532e390 ("Merge revision 1.35 from NetBSD: fix pointer/offset mistakes in handling of IPv4 options")
Differential Revision: https://ron-dev.freebsd.org/FreeBSD/src/pulls/94
linux: Handle OOB accesses in bsd_to_linux_errno()
Such accesses can be triggered via ptrace(PT_SET_SC_RET).
Approved by: re (cperciva)
Reported by: Dennys Kaluzny Pereira <dennyskaluzny at gmail.com>
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 8f024e97cabf7497dc047538db9c6be9067752a1)
(cherry picked from commit c48a331e54794310fe05dddcb0719cdba1f5b1c3)
fget_remote(9): recheck remote process fdp after holding the file
kern_pddupfd() grants access to the process named by a process
descriptor with p_candebug(), then calls fget_remote() to duplicate a
descriptor from that process's current filedesc. The check remains
stable against an execve() by that one process, but the implementation
does not keep the held filedesc semantically bound to that process.
If the authorized process P shares its descriptor table with another
process Q, P can detach from the table with rfork(RFCFDG) after
fget_remote() has held the old table but before it acquires the table
lock. After P detaches, Q is the sole process-reference owner of the
old table; fget_remote() retains only a separate lifetime hold. When
Q executes a setuid program, the normal fdunshare() call observes
fd_refcnt == 1 and does not copy the table. Privileged descriptors are
therefore installed in the held old table. The waiting pddupfd() call
accepts that table because its process reference count is nonzero and
can return a descriptor opened by Q even though the security check was
performed against P.
[11 lines not shown]
sglist: use u_int instead of u_short to store sizes
sglist_alloc accepts an int argument to specify the number of segments
in the sglist. The sglist struct however stores this value in a u_short,
which may wrap in the case of larger sglists. This happens when the
NVIDIA driver performs large allocations, as reported by a user.
This changes updates the use of u_short to a u_int to match the arg
passed into sglist_alloc. The sglist init and save locations are also
updated to no longer use shorts to represent nseg.
Approved by: khng (mentor)
PR: 299611
Sponsored by: NVIDIA
Differential Revision: https://reviews.freebsd.org/D61197
fget_remote(9): recheck remote process fdp after holding the file
kern_pddupfd() grants access to the process named by a process
descriptor with p_candebug(), then calls fget_remote() to duplicate a
descriptor from that process's current filedesc. The check remains
stable against an execve() by that one process, but the implementation
does not keep the held filedesc semantically bound to that process.
If the authorized process P shares its descriptor table with another
process Q, P can detach from the table with rfork(RFCFDG) after
fget_remote() has held the old table but before it acquires the table
lock. After P detaches, Q is the sole process-reference owner of the
old table; fget_remote() retains only a separate lifetime hold. When
Q executes a setuid program, the normal fdunshare() call observes
fd_refcnt == 1 and does not copy the table. Privileged descriptors are
therefore installed in the held old table. The waiting pddupfd() call
accepts that table because its process reference count is nonzero and
can return a descriptor opened by Q even though the security check was
performed against P.
[9 lines not shown]