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
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
ptrace: Call ptrace_check_allowed() from the compat32 layer
Otherwise the checks there aren't applied to freebsd32 ptrace calls.
Fixes: 7006cb7bd22d ("pdptrace(2): allow debugging in capability mode")
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61597
(cherry picked from commit 44ae34814f689bf640c03b7f26f4f540a5f92d54)
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)
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]
bsnmp: reject an oversized vacmViewTreeFamilyMask
The SET handler for vacmViewTreeFamilyMask compared the value length
against the 16-byte view->mask, but the check had no statement of its
own: it guarded the following malloc() instead of rejecting the
request. A value longer than 16 bytes was therefore copied into
view->mask with memcpy(), overflowing struct vacm_view. Add the
missing return so an over-long value is refused with wrongValue.
Approved by: so
Security: FreeBSD-SA-26:89.bsnmp
Security: CVE-2026-127743
Reviewed by: harti
Fixes: 135f7de5ddb6
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]
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
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
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]
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]
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
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
sound: Improve interlocking in chn_resizebuf()
chn_resizebuf() fails if the channel's software buffer is mapped, but
does not take into account the fact that channel I/O drops the channel
lock when copying from or to user memory. During the window where the
lock is dropped, a resize may free the old buffer, causing userspace to
access freed kernel memory. This can be exploited to escalate
privileges.
Fix this by disallowing resizing when I/O is in progress.
Approved by: so
Security: FreeBSD-SA-26:88.sound
Security: CVE-2026-127741
Reviewed by: christos, kib
Reported by: OpenAI Security Research Team
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61446
bsnmp: mask reserved SNMPv3 msgFlags bits on input
snmp_pdu_decode_header() reads the msgFlags octet straight into
pdu->flags and never sanitises it. Only bits 0..2 are defined on the
wire (authFlag, privFlag, reportableFlag). Bit 7 (0x80) is bsnmp's
internal SNMP_MSG_AUTODISCOVER marker: it shares the same field and is
tested later as "this is discovery, skip USM and VACM".
Because the byte is taken verbatim from an unauthenticated peer, a
client that sets bit 7 of msgFlags has (pdu->flags &
SNMP_MSG_AUTODISCOVER) read true straight after header decode, forging
the discovery state. A noAuthNoPriv user -- which has no digest to
verify -- can thus mark an ordinary request as discovery and have it
bypass the VACM access check, operating outside its configured views.
Keep only the three defined wire bits when decoding msgFlags, so the
internal marker can never be set from the network.
Approved by: so
[3 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
tcp: Handle read-only mbufs in tcp_pulloutofband()
tcp_pulloutofband() is used to implement the urgent flag: it pulls a
byte out of the data stream, to be returned to the recevier when MSG_OOB
is specified. That function extracts the byte assuming that the mbuf is
safe to modify, which may not be the case, e.g., when transmitting file
data with sendfile(). This flaw can be exploited by a local user to
obtain root privileges.
Generalize this subroutine so that it handles read-only mbufs as well.
Add some regression tests.
Approved by: so
Security: FreeBSD-SA-26:93.tcp
Security: CVE-2026-127748
Reported by: OpenAI Security Research Team
Reviewed by: tuexen
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61411
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