[libc][regex] Add ERE {m,n} interval quantifiers (#236569)
POSIX Extended Regular Expressions support bounded and lower-bounded
interval quantifiers ({m}, {m,}, and {m,n}) with repetition counts up to
RE_DUP_MAX (255); although POSIX leaves an unescaped '{' not followed by
an ASCII digit undefined, real-world patterns rely on it matching a
literal '{'. Unrolling counted repetitions at parse time duplicates
subexpressions up to 255 times per quantifier, while unanchored
derivative stepping across high-count intervals builds quadratic
alternation chains as active repetition states accumulate at each input
byte.
We represent interval quantifiers directly in Expr by moving ch into the
8-byte payload union alongside named Binary and RepeatBounds structs,
freeing two bytes to cache a has_repeat bit and a saturating 16-bit
rep_expansion factor within the 16-byte node size, and packing hash_expr
into a single 16-byte HashKey struct round. During Repeat derivative
evaluation, next_min collapses to zero whenever the body is nullable at
the pre-byte anchor context so leading copies can match empty at the
[13 lines not shown]
[CIR] Convert CIR to LLVM in one shot (#243162)
Convert CIR to LLVM with pattern rollback disabled, so rewrites
materialize immediately. This is the last of the three conversions to
flip (the earlier passes already run without rollback).
Measured on the compile-time investigations branch (3-run serial
medians, five slow translation units), flipping only this conversion cut
the CIR-vs-plain gap from 81.4s to 73.3s (-10%, all top-5 combined);
conversion time on SemaExpr fell from 3.28s to 2.66s (-19%).
In landing order, this were all the separate bits necessary to get here:
- #232510: switch.flat successor operands
- #235196: NFC preparation for one-shot conversion
- #238691: CXXABI and target lowering without rollback
- #238698: global types visible across replacements
- #241645: fold constant int/bool casts
- #242111: AMDGPU printf constant-string annotation
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]
[DA] Fix for missed anti-dependence due to iteration-local alias scopes (#223299)
DependenceAnalysis misreports cross-iteration dependences as `none`
when `!alias.scope` / `!noalias` metadata is iteration-local.
noalias.scope.decl inside a loop only holds for that iteration.
Strip those scopes before the cross-iteration AA query, same as LAA.
Fixes #223173
assisted-by: meta.ai
[CIR] Fix cleanup ordering of coroutines (#230574)
* Capture promise and parameter-copy cleanups for the destroy region
* Clean up the GRO expression with any temporaries before
`initial_suspend`
* Add a cleanup scope for the coroutine body
* Destroy the promise and parameter copies in the destroy region
---------
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[MemProf] Find missing tail call frames through aliases of the profiled callee (#243293)
The ThinLTO search for frames missing from profiled contexts due to tail
calls compared each tail call edge's callee against the profiled
callee's ValueInfo. Only the aliasee's function summary gets a context
node, so a tail call through an alias of the profiled callee never
matched, and the search instead recursed into the aliasee's own calls.
The IR version of the search already resolves aliases.
Treat a tail call to an alias of the profiled callee as reaching it.
The synthesized callsite record is still keyed by the alias, which is
what the ThinLTO backend looks up for the tail call.
Assisted-by: Gemini
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]
linux: Handle OOB accesses in bsd_to_linux_errno()
Such accesses can be triggered via ptrace(PT_SET_SC_RET).
Reported by: Dennys Kaluzny Pereira <dennyskaluzny at gmail.com>
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 8f024e97cabf7497dc047538db9c6be9067752a1)
[CodeGen] Declare command line options of ten passes in TableGen (#243179)
Port the options of EarlyIfConversion, FixupStatepointCallerSaved,
HardwareLoops, IfConversion, MachineOutliner, MachineSink,
PeepholeOptimizer, RegisterCoalescer, SelectOptimize and TailDuplicator.
* Rename the -disable-ifcvt-*, -disable-peephole, -disable-adv-copy-opt,
-disable-non-allocatable-phys-copy-opt, -disable-loop-level-heuristics
and -disable-global-outlining spellings to positive ones
(-disable-loop-level-heuristics becomes
-select-opti-loop-level-heuristics). The old spellings remain aliases,
which reject a value, so adv-copy-opt.ll switches to the new spelling.
* -machine-sink-bfi and -aggressive-ext-opt stay cl::opt:
getAnalysisUsage reads them.
* Move toOptional(BoolOrDefault) from CommandFlags.cpp to
BoolOrDefault.h for HardwareLoops.
LLM-aided
[mlir][gpu][sparse] Fix crash when gpu-triple is set without gpu-chip (#242020)
The sparsifier forwards an unset `gpu-chip` as an empty string, which
overwrites the nvvm-attach-target default of `sm_75` and `#nvvm.target`
rejects it. The pass builds the attribute with `getAttr`, so it asserts
instead of reporting the error.
Only set the chip when the user passed one, and use `getChecked` in the
pass so a bad option gives a diagnostic. `ROCDLAttachTarget` and
`XeVMAttachTarget` have the same pattern, left for a follow-up.
Fixes #239436
vfs: Check access for O_CREAT directory opens
O_CREAT with O_DIRECTORY takes LOOKUP without creating a vnode.
Clear O_CREAT there so vn_open_vnode checks read or search access.
Add an unprivileged regression test for denied and permitted opens.
Approved by: so
Security: FreeBSD-SA-26:92.vfs
Security: CVE-2026-127746
Reviewed by: kib
Fixes: 9e18c9eb27cd
bsnmp: do not act on an SNMPv3 discovery message that carries bindings
An SNMPv3 message with an empty engine id and empty user name is handled
as snmpEngineID discovery: snmp_pdu_auth_user() sets SNMP_MSG_AUTODISCOVER
and returns without a USM user, and snmp_pdu_auth_access() then grants the
message access. A genuine discovery request carries no variable bindings
and only elicits a Report, but a discovery PDU that did carry bindings was
executed anyway -- so a GET or SET ran with no authentication and without
the VACM access check.
This affects two cases. With an empty user name the message is wholly
unauthenticated, so anyone able to reach the agent could issue a SET. It
also affects a configured noAuthNoPriv user: such a user has no digest to
verify, so it too can set the AUTODISCOVER flag (an authenticated request
before time synchronisation) and have a bindings-carrying PDU bypass VACM
and operate outside its views.
Refuse any AUTODISCOVER message that arrives with variable bindings
instead of acting on it. Empty-binding discovery, the authenticated
[23 lines not shown]
fdescfs: add VOP_ACCESS() implementation
kern_truncate() checks VWRITE only through VOP_ACCESS() on the fdescfs
vnode, which always succeeded until now. So a file opened read-only
could be truncated, even if the caller has no write permission for it.
Note that reopen on mounts without nodup already performs the permission
checks in dupfdopen(). For nodup mounts, the VOP_ACCESS() implementation
of the real filesystem is used.
Approved by: so
Security: FreeBSD-SA-26:91.fdescfs
Security: CVE-2026-127745
Reported by: Kevin Day <kevin at your.org>
Sponsored by: The FreeBSD Foundation
kqueue: Fix a race between kqueue_fork_copy_list() and kqueue_expand()
While kqueue_fork_copy_list() is iterating over the knote lists, the
backing array may change while the kqueue lock is dropped. Since each
list is a singly-linked list, kqueue_fork_copy_list() must start
iterating from the list head in order to remove the marker, but that
list head pointer is invalid after kqueue_expand() runs.
Add a bit of indirection to re-compute the correct list head each time
the kqueue lock is dropped.
Avoid changing the layout of struct knote since I want to backport this
to releng branches.
Approved by: so
Security: FreeBSD-SA-26:85.kqueue
Security: CVE-2026-127750
Reported by: Dennys Kaluzny Pereira <dennyskaluzny at gmail.com>
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D61608
bsnmp: let an SNMPv3 discovery message elicit only a Report
An SNMPv3 message with no variable bindings is treated as RFC 3414
engineID (or time-window) discovery: snmp_input_start() appends a
single usmStats counter to the request, and snmp_pdu_auth_access()
skips the VACM check because the AUTODISCOVER flag is set. The
request's verb was then still dispatched by type. A genuine discovery
is a GET and simply reads that counter back -- the intended Report --
but a zero-binding GETNEXT or GETBULK instead walks forward from the
appended OID, and with VACM skipped it returns the next registered
object(s): an unauthenticated read of the agent's USM and VACM
configuration (objects at or after 1.3.6.1.6.3.15).
Force the verb of a discovery message to GET, so the appended counter
is read as-is and no walk (or SET) can run under the skipped-VACM
state. Genuine discovery, which already uses GET, is unaffected.
This complements the earlier change that rejects an AUTODISCOVER
message carrying its own bindings; that guard is never reached on this
[7 lines not shown]
tmpfs: Clear setgid on creation by nonmembers
New tmpfs nodes inherit their parent directory group. Clear S_ISGID when
the creator is not a member of that group and lacks PRIV_VFS_SETGID,
matching UFS and tmpfs chmod behavior.
Approved by: so
Security: FreeBSD-SA-26:94.tmpfs
Security: CVE-2026-127749
Reviewed by: kib
freebsd32: Avoid modifying a shared control message
freebsd32_copy_msg_out() copies out received control messages. The
cmsg ABI differs between the 32-bit and native ABIs in that the 32-bit
ABI requires only 4-byte alignment for message bodies, see CMSG_ALIGN.
When the control message is read from the socket buffer with MSG_PEEK,
short messages which fit into an mbuf are copied into private storage,
but larger messages are returned by acquiring a counted reference on the
underlying mbuf cluster still attached to the socket buffer.
When the underlying storage is shared, the non-atomic, temporary
modification of the control message header in freebsd32_copy_msg_out()
can be abused to corrupt the message queue; this can be leveraged to
escalate privileges.
Approved by: so
Security: FreeBSD-SA-26:86.freebsd32
Security: CVE-2026-101321
[4 lines not shown]
so_splice: Serialize teardowns of splices
A socket splice can be configured with a timeout; once the timeout
expires, the splice is automatically undone. The implementation of an
unsplice operation detaches each socket from the splice structure, and
then drains the timeout task. The timeout task takes the splice
structure as an argument, and passes the source socket to so_unsplice().
It is possible for two threads to race with the task thread: one removes
the source socket from the splice associated with currently running
task, and the other thread splices that socket again, creating a new
splice structure. The timeout thread may then unsplice the source
socket even though it doesn't own that socket's current splice. The
resulting use-after-free can be exploited by a local user to escalate
privileges.
Fix the problem by serializing teardowns of splices: make so_unsplice()
callers specify the cause of the teardown, and ensure that threads can't
race to destroy a splice after an error occurs.
[8 lines not shown]
tests: Add test for fdescfs truncation bug
Add a test case that verifies that it is not possible to truncate a
file opened read-only through fdescfs in default mode, and another that
verifies that it is possible when fdescfs was mounted in nodup mode.
Approved by: so
Security: FreeBSD-SA-26:91.fdescfs
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D61236
vm_map: Fix handling of largepage mappings
vm_map_pmap_enter() is not aware of largepage objects and enters their
constituent 4KB pages into the pmap. This permits mapping a constituent
page after the corresponding largepage object is freed, which can be
abused to escalate privileges. Simply don't pass largepage mappings to
it.
Modify vm_fault_copy_entry() to handle largepage mappings for the case
where mprotect() needs to eagerly upgrade protections on a wired
largepage mapping.
Approved by: so
Security: FreeBSD-SA-26:90.vm
Security: CVE-2026-127744
Reviewed by: alc, kib
Reported by: OpenAI Security Research Team
Reported by: Albert at Vexera AI
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61363