proc: Make the COW generation counter a saturating counter
A sleeping thread can hold on to a COW counter value indefinitely while
a sibling thread forces the process generation counter to wrap around.
This can cause us to free a limit set while it's still in use. This can
be exploited to obtain root privileges.
Fix this by making p_cowgen a saturating counter: once it reaches
UINT_MAX, the value is fixed, and we always take the slow path through
thread_cow_update(). The per-process counter is reset at fork time, and
I suspect it's quite unlikely that a process will hit the limit
organically.
Simplify the optimization in setrlimit which proactively syncs the
thread's limit structure: now that the counter is saturating, we cannot
infer from PROC_COW_CHANGECOUNT(td, p) == 1 that the thread and proc are
in sync.
Approved by: so
[6 lines not shown]
ptrace: Fix interactions between remote requests and signal handling
The debugger may have invoked execve in the debugee via PT_SC_REMOTE, in
which case the sigacts structure may have been replaced and freed.
Then, sigprocess() can operate on the freed structure. This can be
exploited to obtain privileges. Further, we could have nested
ptracestop() calls if the debugger requests a blocking syscall while a
signal is pending. It is very hard to reason about the correctness of
such calls.
Make sigprocess() reload the process signal handler state after handing
control to the debugger, this might change due to execve().
Set TDB_BOUNDARY in ptracestop() rather than in the AST handler and
syscallret(). Plumb a flag through to achieve this. This also ensures
that nested ptracestop() calls do not try to handle remote requests.
Add a TDB_INREMOTEREQ flag, use it to ensure that we don't pause or
consume signals while executing a remote request. Factor out the
[11 lines not shown]
socket: Disallow listen on SS_ISDISCONNECTED sockets
tcp_usr_shutdown() can race with listen(): it calls tcp_output after
marking the socket disconnected. This can lead to corruption of the
socket union.
Simply disallow listen() on disconnected data sockets. This is not a
portable feature and it seems unlikely that anything relies on it.
Remove a recently added regression test which documents the old
behaviour.
Approved by: so
Security: FreeBSD-SA-26:102.socket
Security: CVE-2026-127762
Reported by: Laam Alif at Ibteda Digital Library
Reviewed by: emaste
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D62220
proc: assert td belongs to p in PROC_COW_CHANGECOUNT
PROC_COW_CHANGECOUNT(td, p) evaluates p->p_cowgen - td->td_cowgen, which
is only meaningful when td is a thread of p. Otherwise it subtracts two
unrelated copy-on-write generations, as the kern.proc.rlimit remote
update path did before it was fixed. Assert td->td_proc == p to catch
such a caller on INVARIANTS kernels.
Approved by: so
Security: FreeBSD-SA-26:101.setrlimit
Suggested by: mjg
MFC after: 2 weeks
Assisted-by: Claude Opus 4.8
Reviewed by: olce, mjg
Differential Revision: https://reviews.freebsd.org/D62162
kern_proc_setrlimit: take the fast path only for curproc
When a thread changes its own process' resource limits,
kern_proc_setrlimit() syncs the thread to the new plimit and releases
two references on the old one, the process' and the thread's, rather
than letting the thread sync itself on its next kernel entry. It
takes this path whenever the target process' copy-on-write generation
is one ahead of the current thread's, but never checks that the
target is the thread's own process.
Another process' limits can be set through the kern.proc.rlimit
sysctl (used by limits -P), Linux prlimit64(2) and the Linux fork
path. On such a remote update the generations can still line up;
lim_cowsync() then syncs and releases the calling thread's reference,
yet both references are dropped from the target's old plimit. A
thread of the target still points at that plimit through td_limit, so
it is freed while live -- a use-after-free.
Guard the fast path with the target being the calling thread's own
[12 lines not shown]
unix: fix use-after-free in SCM_RIGHTS GC after MSG_PEEK
uipc_soreceive_dgram() removes a datagram from the receive queue with
STAILQ_REMOVE_HEAD() before pinning it in so_rcv.uxdg_peeked for a
MSG_PEEK receive. STAILQ_REMOVE_HEAD() does not clear the removed
element's link field, and m_stailqpkt is a union with m_nextpkt, so the
pinned datagram keeps pointing at the datagram that used to follow it in
the queue. That datagram is no longer referenced from here and can be
freed independently, for example by unp_disconnect() when the sending
peer closes.
unp_scan_socket() passes so_rcv.uxdg_peeked to unp_scan(), which walks a
record list through m_nextpkt while collecting SCM_RIGHTS garbage. It
therefore followed the stale link into the freed datagram. On an
INVARIANTS or KASAN kernel this is a panic in unp_remove_dead_ref(); on
a release kernel it double-counts the rights in that record and lets the
collector reclaim a socket that is still reachable.
Clear m_nextpkt when the datagram is pinned so the scan stops at the
[17 lines not shown]
linux: Release futexes and clear tids earlier during execve
During execve, other threads in the process are terminated. As a part
of this, they invoke the sv_thread_detach handler, which modifies user
memory. This handler is invoked only after the new process image has
been loaded, in which case they can modify memory in a setuid or setgid
image process.
Fix this by implementing sv_onexec_old, which explicitly runs before the
new image is loaded. This is how native executables release robust
mutexes.
Approved by: so
Security: FreeBSD-SA-26:99.linux
Security: CVE-2026-127757
Reported by: mmacy, kbowling
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D62207
bsnmp: drop messages with an unsupported SNMP version
snmp_pdu_decode_header() returned SNMP_CODE_BADENC for an unknown
version. snmp_input_start() treats BADENC as a bad value in a SET and
carries on, so its version check, which runs only for SNMP_CODE_OK, was
skipped. The message then reached snmp_pdu_auth_access(), which with
snmp_vacm loaded switched on pdu->version and called abort() for
SNMP_Verr. A single unauthenticated packet could stop bsnmpd.
Return SNMP_CODE_BADVERS instead, as bsnmplib(3) documents, so the
message is counted in snmpInBadVersions and dropped. Remove the
mapping in snmp_pdu_decode() that tried to do this but was never
reached, and have snmp_pdu_auth_access() deny an unknown version
rather than abort.
Approved by: so
Security: FreeBSD-SA-26:98.bsnmp
Security: CVE-2026-127756
Reported by: Hila Cohen, Apiiro (hillalee on github)
[5 lines not shown]
pam_xdg: Do not follow symbolic links when removing the runtime directory
When the last session of a user ends, the runtime directory is removed by
root. The user owns the directory and can still have processes (always
without the linger option), so its content can change while it is removed.
remove_dir() took the type of each entry from readdir() and opened the
directories with openat(fd, name, 0). An entry replaced by a symbolic link
between the two was followed and the content of its target was removed
as root.
Open every entry relative to its parent with O_DIRECTORY | O_NOFOLLOW and
unlink what is not a directory at that moment, never what it points to.
Also stay on the filesystem of the runtime directory, do not enter a
directory that belongs to neither the user nor root, and limit the depth
of the recursion. remove_dir() now always consumes the descriptor it is
given, the callers closed it a second time.
Looking for the last session file also opened a user-controlled entry
[16 lines not shown]
krb5: Import MIT 1.22.3
Major changes in 1.22.3 (2026-11-09)
====================================
This is a bug fix release, with a focus on security issues discovered
with the aid of large language models. See
https://web.mit.edu/kerberos/advisories/MITKRB5-SA-2026-001.txt for
information on the risks of continuing to use unpatched releases.
* Fix a logic error when checking PAC server checksums
[CVE-2026-111423].
* Check for unkeyed checksums when validating CAMMAC verifiers
[CVE-2026-71199].
* Fix a loophole in the KDC's client authdata filtering which could
allow clients to include fake PAC and CAMMAC authdata values when
requesting service tickets. These fake values would be rejected by
[53 lines not shown]
krb5: Fix reachable assert when importing krb5 names
If a name token contains trailing garbage, error out from
krb5_gss_import_name() instead of crashing the process with an
assertion failure.
Commit message details obtained from upstream commit.
Approved by: so
Security: FreeBSD-SA-26:96.krb5
Obtained from: upstream commit 07818f1fd
Reported by: Aisle Research (Ze Sheng, Dmitrijs Trizna,
Luigino Camastra, Guido Vranken) to krb5-bugs
MFC after: 3 days
(cherry picked from commit fce16f60de9718be6b789f00e86141a84cd920d3)
(cherry picked from commit 27691b8b9303c6fec89a6dcb9c56f8c8f0f5e69c)
arm64: Apply boundary checking to ranges in the ARM64_GUARD_PAGE handler
Otherwise pmap_bti_set() may end up partially operating on a largepage
mapping. In the case of a L2 block mapping, it'll demote the mapping.
Then, a subsequent fault will cause pmap_enter_largepage() to remap the
whole large page, but without a break-before-make sequence, so we could
end up with 4KB TLB entries pointing into the large page. If the
largepage object is subsequently destroyed, those TLB entries won't be
invalidated, and would allow userspace to access freed memory.
Fix this using the vm_map_check_boundary() helper. Don't bother
checking for non-canonical addresses, as pmap_bti_set() handles that.
Approved by: so
Security: FreeBSD-SA-26:95.arm64
Security: CVE-2026-127755
Reviewed by: alc, kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61956
tcp bbr: improve handling of retransmissions in LAST-ACK
When performing a timer based retransmission, clear the
BBR_RWND_COLLAPSED flag. If it sticks, t_rxtshift is never incremented
resulting in unlimited retransmissions in the LAST-ACK state.
Approved by: so
Security: FreeBSD-EN-26:33.tcp
Reported by: Illia Vynohradov
Reviewed by: Peter Lei
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D61586
(cherry picked from commit 3c6fd437b1824caeddb5f0d4570d43cf0c999c14)
(cherry picked from commit cbd17b66e64e9bdf025200c4993b8aeae6a0ebe9)
tcp bbr: improve retransmit timout calculation
The retransmission timeout should the srtt + 4 * rttvar.
The srtt is using 5 bits of fractions and rttvar is using 4 bits of
fractions, some specific shifting is required.
Approved by: so
Security: FreeBSD-EN-26:33.tcp
Reviewed by: Peter Lei
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D61581
(cherry picked from commit 2f98793a13fe3e69cf6b698fa469550b4ba0fea1)
(cherry picked from commit ccf8e3762c3948446263ae3ef0dd98391ef9f97e)
tcp bbr: improve invalidating rtt
Invalidate the rtt based on t_rxtshift instead of resetting t_srtt to 0,
because using the latter also affects the retransmission timeout.
Approved by: so
Security: FreeBSD-EN-26:33.tcp
Reviewed by: Peter Lei
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D61585
(cherry picked from commit 8018d75601dfe804a8d70f4f08bdb0e4e3a8c5c9)
(cherry picked from commit 158dcb8e415d84caf6ebc30841ed4bfc3148bc32)
[orc-rt] Fix UB in IntervalMap::erase before first range. (#248813)
If KS preceded every range in a non-empty map then upper_bound returned
begin(), and erase called std::prev on it. Bail out in that case
instead. This check subsumes the existing empty-map check, which is
removed.
The new unit test detects the original bug when built with
AddressSanitizer (stack-buffer-overflow).
VPN: OpenVPN: Client Export - let a read-only user download when the presets are unchanged (#11392)
(cherry picked from commit 7682aafb0b7cd4146e4ee20cf4da8eb17575b973)