100 Commits
Author SHA1 Message Date
Konstantin Belousov 4ab9e73994 libthr/thr_mutex.c: make mutex asserts more useful
Print the file and line number of the caller where the assert fired.
Use _thread_exitf() directly for this.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-28 02:56:06 +02:00
Konstantin Belousov 73b3fb41e6 amd64: Make the SYSENTER and INTn action same as for IDT case.
Fixes:	6e93f5e4d6 ("amd64: FRED support")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-27 13:59:41 +02:00
Konstantin Belousov 8671e823b7 amd64: do not pass SYSENTER frame to FRED fast syscall handler
With FRED, SYSCALL is delivered as event type syscall (7) and vector 1.
SYSENTER is syscall with vector 2.  Handle SYSENTER in slow path,
otherwise 32bit code is able to execute 64bit syscalls.

Also check that SYSCALL comes from the 64bit mode. Intel already
specifies that SYSCALL causes #UD in compatibility mode, but there is no
AMD specification for SYSCALL under FRED yet, and SYSCALL is allowed
in compatibility mode on AMD with IDT event delivery.

Fixes:	6e93f5e4d6 ("amd64: FRED support")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-27 13:59:41 +02:00
Konstantin Belousov 473cd1bba9 amd64: fixes for register handling of syscall entry for FRED
- Save %r10 into tf_rcx.  This is the location for the 4th arg.
  libsys stubs do 'movq %rcx, %r10' so the fast syscall path works
  as is.  But Go binaries directly put arg 4 into %r10.
  Also save %r11 into tf_r11 for the duration of syscall handler.
- Somewhat improve binary compatibility with IDT SYSCALL fast return,
  by copying userspace return %rip into %rcx, and %rflags into %r11,
  emulating SYSCALL IDT delivery.

Fixes:	6e93f5e4d6 ("amd64: FRED support")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-27 13:58:48 +02:00
Konstantin Belousov 5bc997b6f5 amd64: do not allow to set IOPL to 3 when FRED is used
SDM requires that IOPL is zero when returning to usermode with ERETU.

Do not set rflags.iopl for FreeBSD io(4) open.
This might be changed to disallow io(4) open for FRED at all with a
knob, if there is a real need.

Return ENOSYS from linux iopl(2), apparently Linux kernel can be
configured without iopl(2) support, so linux programs should be prepared
for this error.

Return EINVAL from vt(4)/syscons(4) ioctl(KDENABIO).

Fixes:	6e93f5e4d6 ("amd64: FRED support")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-27 13:58:48 +02:00
Konstantin Belousov e86a612d77 trap_fred_handle_k_exc(): handle #AC in kernel
Fixes:	c6d7235ac1 ("amd64: handle #AC in kernel mode")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-27 13:58:48 +02:00
Konstantin Belousov 787e2e411d amd64_cpu_init_fred(): set stack level for NMI and not #NM
Fixes:	6e93f5e4d6 ("amd64: FRED support")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-27 13:58:48 +02:00
Konstantin Belousov 175595ba6c dl_iterate_phdr(3): do not return garbage for objects not using TLS
For objects without a TLS segment, tlsindex is zero. tls_get_addr_slow()
then reads dtv_slots[-1], which is dtv_size, and returns it as the TLS
address. Set dlpi_tls_data to NULL for such objects instead.

Fixes:	d36d681615 ("rtld dl_iterate_phdr(): dlpi_tls_data is wrong")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-25 19:33:46 +02:00
Konstantin Belousov e2979f4cbb rtld: some cosmetics in donelist_init()
Add a missing word in the comment.
Make each assignment a separate statement.
Fix formatting.

Fixes:	1e370f0387 ("rtld: stop using unbound alloca()")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-25 19:33:46 +02:00
Konstantin Belousov 91d8163803 rtld: fix leak in get_program_var_addr() on the error path
Fixes:	1e370f0387 ("rtld: stop using unbound alloca()")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-25 19:33:46 +02:00
Konstantin Belousov dc1514eda5 x86: make machine/sysarch.h usable from assembler
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-25 05:39:25 +02:00
Konstantin Belousov cf63e3f3cd pdfork.2: improve markup
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2026-10-23 21:17:45 +03:00
Konstantin Belousov 8dfa23d81f sys: centralize SV_* flags definitions for ELF Linux ABIs
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-20 23:55:16 +03:00
Konstantin Belousov f69d974bf6 sys: centralize SV_* flags definitions for several FreeBSD ABIs
The omitted ABI is compat32 on arm64, which lacks SV_ASLR.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-20 23:55:16 +03:00
Konstantin Belousov dca0b0ad8b sys/sysent.h: align SV_* flags values, provide full 32bit
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-20 23:55:16 +03:00
Konstantin Belousov 40582412d3 x86/mp_x86.c: unbreak COUNT_IPIS
Fixes:	3a0e2ca3ee ("x86: ipi_bitmap_handler(): Account for IPIs correctly on COUNT_IPIS")
2026-10-20 23:55:16 +03:00
Konstantin Belousov bdcfeac3e1 sysarch.x86.2: manual page for the sysarch(2) functions on x86
Reviewed by:	ziaee
Discussed with:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D60047
2026-10-17 02:15:34 +03:00
Konstantin Belousov 43c79c64af machine/floatingpoing.h: harmonize all arches
Reported by:	fluffy
Reviewed by:	jhibbits (previous version)
Discussed with:	imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D60255
2026-10-16 19:27:39 +03:00
Konstantin Belousov af08f29e5f tests/sys/fs/ufs/sync_test.c: hide the alignment warning
Reported and tested by:	dhw
Fixes:	afe1dec742 ("tests: add UFS synchronous write durability tests")
Sponsored by:	The FreeBSD Foundation
2026-10-13 16:48:52 +03:00
Konstantin Belousov ef758b59a4 rtld: release rtld_bind_lock around calls to .preinit_array initializers
We unlock the bind lock around .init calls anyway.  Also, the main
object cannot be unloaded.

Reported and reviewed by:	dim
PR:	298943
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D60588
2026-10-10 20:03:01 +03:00
Konstantin Belousov 46399049f8 rtld: fix indent
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2026-10-10 18:10:18 +03:00
Konstantin Belousov c2b7fe4a9e .gitignore: add tgrep index directory
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2026-10-08 12:25:02 +03:00
Konstantin Belousov bea382f25b kern/coredump_vnode.c: avoid dumping to the mount point we suspended
PR:	299095
Reported by:	Rick Richard <[email protected]>
Reviewed by:	markj
Tested by:	Rick Richard <[email protected]> (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D60283
2026-10-07 20:00:53 +03:00
Konstantin Belousov ccd44c5e48 vn_open_cred(): rename VN_OPEN_NAMECACHE flag to VN_OPEN_COREDUMP
The flag only use is for special handling of core dump vnodes.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D60283
2026-10-07 20:00:53 +03:00
Konstantin Belousov 274236ed08 rtld.c: avoid double-free on dso load failure in do_load_object()
The obj->path is assigned directly from the path argument, and
load_object() frees the path on do_load_object() failure.  Do not free
it in obj_free() on the error path.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D60402
2026-10-06 20:33:27 +03:00
Konstantin Belousov ea23918b02 rtld-elf/i386: remove no longer true __unused args annotations
Fixes:	d45d7aea61 ("i386 rtld: implement support for TLSDESC relocation")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-10-06 10:56:59 +03:00
Konstantin Belousov 1e595e959f devfs_open: do not access dsw after dev_relthread()
Noted and reviewed by:	markj
Fixes:	850d456292 ("cdevsw: add D_NONPASSABLE flag")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D60393
2026-10-06 03:30:49 +03:00
Konstantin Belousov 499901dd7a ufssuspend(4): mark non-passable
This fixes long-standing issue where ufssuspend file descriptor could
leak over fork or be passed over unix domain socket, and then closing it
in the opener would not unsuspend the file system.

It should not affect the well-behaving growfs(8) utility, but makes the
userspace API safer on principle.

Reviewed by:	markj
Tested by:	pho (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D60285
2026-10-06 00:56:53 +03:00
Konstantin Belousov 850d456292 cdevsw: add D_NONPASSABLE flag
to make the opened device files non-passable.

Reviewed by:	markj
Tested by:	pho (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D60285
2026-10-06 00:56:53 +03:00
Konstantin Belousov dec68aeff8 libc/stdlib/getenv.c: always allocate new environment
in particular, if the old environment is NULL.

Among making it less surprising for userspace to observe NULL environ,
the change also prevents NULL deref in __rebuild_environ() when
terminating the empty as NULL environment with the NULL pointer.

Reported by:	 Leo Bicknell <[email protected]>
PR:	298747
Reviewed by:	emaste, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59996
2026-10-02 22:48:42 +03:00
Konstantin Belousov 1e8708d9b5 stat.2: document SFBSD_MNTROOT
Reviewed by:	sobomax, markj, olce
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59910
2026-10-01 00:36:04 +03:00
Konstantin Belousov 0d5d887293 stat(2): report mount points using st_bsdflags SFBSD_MNTPOINT flag
Reviewed by:	jah, sobomax, markj, olce
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59910
2026-10-01 00:36:03 +03:00
Konstantin Belousov 233b6efe5f pdfork.2: downgrade sections inside description to subsections
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2026-09-29 23:04:37 +03:00
Konstantin Belousov cc467e4513 amd64/mp_machdep.c: remove double 'for' in comment
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2026-09-29 23:04:37 +03:00
Konstantin Belousov c2f66b6616 libthr.3: document LIBPTHREAD_PSHARED_LOCK_DESTROY_IMMEDIATE_GC
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-09-28 01:30:00 +03:00
Konstantin Belousov 4472a048cf libthr: GC pshared locks not more than each 25msecs by default
Provide a tunable env variable to request immediate GC on destroy
to allow to return to the previous behavior.

Based on the report and patch by Atle Solbakken <[email protected]>.
PR:	268532
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-09-28 01:30:00 +03:00
Konstantin Belousov e40c72c823 VFS: style
Wrap long lines, related to the nullfs mounts over regular files and
sockets type checks.  Also fix indent.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-09-24 21:38:33 +03:00
Konstantin Belousov 30ad8440b4 VFS: require locked vnode for fsync()
Stop exempting devfs nodes.

Reviewed by:	markj
Tested by:      pho
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:	https://reviews.freebsd.org/D59932
2026-09-24 21:38:33 +03:00
Konstantin Belousov 53edaad235 filesystems: use g_vfs_close_unlocked(9)
As result, we lock the devvp vnode around calls to VOP_FSYNC() on
unmount. For instance, the vn_fsync_buf() implementation of fsync()
needs exclusive lock on the vnode to guarantee that all dirty buffers
are indeed synced.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59932
2026-09-24 21:38:33 +03:00
Konstantin Belousov 87962e08fa g_vfs_close_unlocked(9): wrapper around g_vfs_close(9)
that locks both bo vnode and topology.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59932
2026-09-24 21:38:32 +03:00
Konstantin Belousov 20c09e6fec amd64: use WRMSRNS immediate form to update splitlock control, when available
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:41 +03:00
Konstantin Belousov 74d325fee2 amd64: cache MSR_MEMORY_CTL in pcpu
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:41 +03:00
Konstantin Belousov 51cea5416a amd64: add userspace control for disabling splitlocks
Thread can control it with sysarch(I386_SET_SPLITLOCK). The global
default is set with hw.splitlock_force.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:41 +03:00
Konstantin Belousov e318f24c0f amd64: support for tracking per-thread 'disable splitlocks' state
If hw supports it, on atomic operation that requires exclusive ownership
of more than one cache line, #AC is generated.
The state is maintained as the arch-private TDF_MD_SPLITLOCK_AC flag.

The state is inherited on thread creation from the thread spawning the
new one.  It is cleared on exec.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:40 +03:00
Konstantin Belousov d8c1abb0e3 amd64: calculate if hardware supports disabling splitlocks
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:40 +03:00
Konstantin Belousov c6d7235ac1 amd64: handle #AC in kernel mode
Recover from it if PCB_ONFAULT handler is provided.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:40 +03:00
Konstantin Belousov dc97561221 amd64: add md thread flags word
Use a hole in struct mdthread.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:40 +03:00
Konstantin Belousov 4a8acccc2e amd64 cpufunc.h: add WRMSRNS helpers
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:40 +03:00
Konstantin Belousov 71f08bfa02 x86: add cpu_stdext_feature5
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:40 +03:00
Konstantin Belousov 9aa031eb92 x86: add definitions for the CORE_CAP and MEMORY_CTL MSRs
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59815
2026-09-22 18:40:40 +03:00
Konstantin Belousov 64a73d1b6d amd64/*sigtramp.S: re-enable some cfi annotations for special registers
Also explicitly specify .cfi_sections to emit the cfi bytecode into the
loadable .eh_frame section.

Reviewed by:	mchoo
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59838
2026-09-21 21:25:38 +03:00
Konstantin Belousov 151a8512bd truss(1): capsicumize
The new ptrace(2) features allow to change truss(1) to systematically
operate on the process descriptors instead of pids.

Allocate the global kqueue that tracks all noted children
by pdopenpid()-ing them and adding to the kqueue with
EVFILT_PROCDESC/NOTE_PDSIGCHLD. The activated knote triggers the
pdwait() call to return the child tracing info. This replaces the
waitid(P_ALL) call in the non-capsicumized truss(1) eventloop.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58094
2026-09-16 18:33:40 +03:00
Konstantin Belousov fa848d4d0c rtld: more caution when parsing in digest_notes()
Incorrect ELF might have PT_NOTE slightly larger than the needed to
contain all notes, and the PT_NOTE size could be larger than one page.
Then rtld mmaps just the notes bytes to parse.  After the last note,
we iterate past the mapped region trying to read the Elf_Note header.
This was found in wild.

Require full elf note to fit into the [start_note, end_note) region to
continue the parsing.  Check it in stages, first verifying the Elf_Note
header structure fits, to be able to read the name and data length.
After that, check the whole note against limit.

Reported and tested by:	makc
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59635
2026-09-15 00:55:01 +03:00
Konstantin Belousov 2ef97312d5 rtld.c: fix indent
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2026-09-15 00:55:01 +03:00
Konstantin Belousov 18a5549bcb lib/msun amd64: use AVX FMA instructions for fma(3) and fmaf(3) when available
Utilize the ARCHLEVEL framework from libc/amd64/string to provide the
way for runtime selection of the implementation, if wanted.

Reviewed by:	fuz, kfv
Discussed with:	kargl
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59462
2026-09-08 15:13:29 +03:00
Konstantin Belousov b45fd24a3c lib/msun: move the calculation of LIBC_SRCTOP earlier
which makes the variable available for machine/Makefile.inc usage.

Reviewed by:	fuz, kfv
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59462
2026-09-08 15:13:29 +03:00
Konstantin Belousov 661d1135e4 pdfork.2: document kern.pdfork_implicit_nowaitpid
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59349
2026-09-07 19:04:00 +03:00
Konstantin Belousov 24d3cbaaf5 kern_fork.c: add kern.pdfork_implicit_nowaitpid sysctl
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59349
2026-09-07 19:03:51 +03:00
Konstantin Belousov c63c77b3a5 vp_crossmp: weaken the assert and make it more precise
Since the vp_crossmp vnode can leak into vn_vptocnp() calls due to
nullfs file mounting, not all lock requests are non-sleeping. The
requirement for the crossmp locking is that all lock requests should be
shared. Then, it does not matter if the requests allow sleeping, since
all locks are shared.

Also, check the lock type by correctly masking it with LK_TYPE_MASK.

Reported and tested by:	pho
Reviewed by:	jah, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59468
2026-09-07 18:46:03 +03:00
Konstantin Belousov 76f5fccc5f amd64 rtld: implement support for TLSDESC relocation
Discussed with:	jrtc27
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59269
2026-09-06 01:00:10 +03:00
Konstantin Belousov d45d7aea61 i386 rtld: implement support for TLSDESC relocation
Discussed with:	jrtc27
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59269
2026-09-06 01:00:10 +03:00
Konstantin Belousov fb63a60d6e rtld i386: use macro for the 'GNU ABI' calling convention of TLS resolver
Discussed with:	jrtc27
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59269
2026-09-06 01:00:09 +03:00
Konstantin Belousov 5d9e5f4964 rtld: explain the use of rtld_bind_lock in rtld_get_addr_slow()
Discussed with:	jrtc27
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59269
2026-09-06 01:00:09 +03:00
Konstantin Belousov 6a69d28ee0 rtld: allow arches to initialize/finalize objects
Discussed with:	jrtc27
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59269
2026-09-06 01:00:09 +03:00
Konstantin Belousov c0c7b56d30 ntsync(4): do not double-free the alert event when a dup was detected for WAIT_ALL
Reported by:	Andrew Griffiths <[email protected]>
Reported by:	Chris Jarrett-Davies <[email protected]>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-09-04 17:44:07 +03:00
Konstantin Belousov 1a296762b3 libcasper: reap zombies without requiring waitpid(2)
Reported and tested by:	bapt
Reviewed by:	bapt, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59348
2026-09-04 05:27:09 +03:00
Konstantin Belousov c8f8d00c24 ptrace(2): allow ptrace(PT_TRACE_ME) in cap mode
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59317
2026-09-02 04:00:50 +03:00
Konstantin Belousov b3734c1386 tests/sys/kern/procdesc.c: mark grandchild var in pdopenpid_capmode() as volatile
The variable is written in the child process which shares the address
space with the parent.  The data flow must not be optimized by a compiler.

Reviewed by:	markj
Fixes:	ddf62c83fc ("sys/tests/kern/pdopenpid: pdopenpid(2) is allowed in cap mode")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59282
2026-09-01 16:56:34 +03:00
Konstantin Belousov 326ab530dc pdopenpid(2): in cap mode, translate all errors from pdopenpid1() to ECAPMODE
to not leak information about unused pids or system processes' pids.

Reviewed by:	markj
Fixes:	73c92a978c ("pdopenpid(2): allow in capability mode with restrictions")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59252
2026-09-01 16:56:34 +03:00
Konstantin Belousov 420428718d tty: gracefully handle proctree_lock locking
Instead of relocking tty to get the proctree_lock and experiencing the
race due to the relock, take the proctree_lock in advance for ioctl
commands that need it.  The affected commands, TIOCNOTTY, TIOCSCTTY,
and TIOCSPGRP, must not be overridden by the specific tty drivers,
so the common handling is cleaner.

Reviewed by:	kevans (previous version), markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59132
2026-08-29 12:43:07 +03:00
Konstantin Belousov 824f934bf9 tty: make tty_wait_background() aware of proctree_lock ownership
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59132
2026-08-29 12:43:00 +03:00
Konstantin Belousov 9bd3fe5712 tty: add tty_wait_proctree(9)
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59132
2026-08-29 12:42:52 +03:00
Konstantin Belousov a15c71254a condvar.9: document cv_wait_sig_unblock(9)
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59132
2026-08-29 12:42:47 +03:00
Konstantin Belousov 0cc6c44296 condvars(9): add cv_wait_sig_unlock()
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59132
2026-08-29 12:42:40 +03:00
Konstantin Belousov ddf62c83fc sys/tests/kern/pdopenpid: pdopenpid(2) is allowed in cap mode
Adjust test to check for ECAPMODE using grandchild instead of child.
Childrens can be opened even in cap mode.  Add test for the later.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58989
2026-08-28 14:55:11 +03:00
Konstantin Belousov 1ac08a43cf pdfork.2: document cap mode, namely pdopenpid(2) and pdptrace(2) errors
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58989
2026-08-28 14:55:11 +03:00
Konstantin Belousov 1d20ebb7bf Regen 2026-08-28 14:55:11 +03:00
Konstantin Belousov 73c92a978c pdopenpid(2): allow in capability mode with restrictions
The pdopenpid() syscall is allowed to open processes which are either
direct children of the caller, or are debuggees already attached to the
calling process. This is reasonable because we could have controlled the
child on fork anyway.

The procdesc-less debuggee can legitimately appear due to ptrace
FOLLOW-FORK mode.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58989
2026-08-28 14:55:11 +03:00
Konstantin Belousov 7006cb7bd2 pdptrace(2): allow debugging in capability mode
The pdopenpid(2) syscall is allowed in capability mode. Add the chicken
switch security.bsd.ptrace_in_cap_mode, which disables it without
reboot, if needed.

The descriptor passed to pdptrace(2) must have the CAP_PTRACE
capability enabled. This capability is not enabled by default by
pdfork()/pdopenpid(), and the calls do not return a procdesc suitable
for debugging. The opening code must prepare for debugging in advance by
passing the PD_PTRACE_CAP flag to pdfork()/pdopenpid().

For ptrace(2), allow PT_CLEARSTEP and PT_GET_CHILDREN for the current
thread and process in cap mode as well.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58989
2026-08-28 14:55:11 +03:00
Konstantin Belousov 68d4b31127 kern: add p_canopen()
The function defines the policy for allowing to open a pid.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58989
2026-08-28 14:55:10 +03:00
Konstantin Belousov 3dfd63b584 ptrace.2: document PT_GET_ABI_NAME
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59113
2026-08-28 14:53:01 +03:00
Konstantin Belousov 6b9ef5dfc9 ptrace(2): add PT_GET_ABI_NAME request
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59113
2026-08-28 14:53:01 +03:00
Konstantin Belousov 5f5910ba38 tests/sys/kern/pdwait: adjust test for the addition of CAP_PTRACE
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58586
2026-08-28 14:52:55 +03:00
Konstantin Belousov 45633600ac pdfork.2, rights.4: document pdptrace(2), CAP_PTRACE, and pdfork(PD_PTRACE_CAP)
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58586
2026-08-28 14:52:32 +03:00
Konstantin Belousov 16ff23d1a7 Regen 2026-08-28 14:52:32 +03:00
Konstantin Belousov 6d17a04fc6 lib/libsys: export pdptrace(2)
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58586
2026-08-28 14:52:32 +03:00
Konstantin Belousov f8c0616052 Add pdptrace(2)
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58586
2026-08-28 14:52:32 +03:00
Konstantin Belousov 9cea869940 ptrace: split sys_ptrace()/freebsd32_ptrace()
The code to handle copyin and copyout of the structured parameters is
moved into the helpers.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58586
2026-08-28 14:52:32 +03:00
Konstantin Belousov b2f300ee8f sys/bsm/audit_kevents.h: add AUE_PDPTRACE
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58586
2026-08-28 14:52:31 +03:00
Konstantin Belousov e8c3132048 pdfork(2): add PD_PTRACE_CAP flag
If the flag is not specified, the process descriptor returned by either
pdfork(2) or pdopenpid(2) has the CAP_PTRACE capability disabled.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58586
2026-08-28 14:52:31 +03:00
Konstantin Belousov 5f82dd8e91 capsicum: add CAP_PTRACE
The capability will allow the ptrace(2) on the procdesc.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58586
2026-08-28 14:52:31 +03:00
Konstantin Belousov 8c911d9a98 kern/kern_descrip.c: export filecaps_fill()
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58094
2026-08-28 14:52:31 +03:00
Konstantin Belousov a1aa26b7db tests/sys/posixshm/posixshm_test.c::accounting fix after st_size changes
st_blksize is defined by POSIX as the 'preferred I/O block size for this
object.' It is wrong to use st_blksize as the unit for st_blocks and
expect it to be equal to the object size regardless of the change of
st_blksize.

Fixes:	3a1bf59d19 ("shmfd: consistently return size in 512 byte blocks for fstat(2) st_blocks")
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D59014
2026-08-21 04:31:50 +03:00
Konstantin Belousov fdcb52d036 ofed/ipoib: convert to timer_setup linuxKPI
Reviewed by:	bz
Sponsored by:	NVidia networking
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58941
2026-08-20 02:16:53 +03:00
Konstantin Belousov 814cd91998 mlx5(4): convert to timer_setup() linuxKPI
Reviewed by:	bz
Sponsored by:	NVidia networking
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58941
2026-08-20 02:16:53 +03:00
Konstantin Belousov 3a1bf59d19 shmfd: consistently return size in 512 byte blocks for fstat(2) st_blocks
This is ABI-breaking change that could be considered as the bug fix.

Requested by:	David Timber <[email protected]>
Reviewed by:	emaste, markj
Sponsored by:	The FreeBSD Foundation
Relnotes:	yes
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58942
2026-08-19 17:46:34 +03:00
Konstantin Belousov 4b17776d9a compat/freebsd32: set uio_rw for trailer's uio in freebsd32_sendfile()
PR:	297516
Reported by:	asomers
Fixes:	dfad790c8c ("sendfile: stop abusing kern_writev()")
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2026-08-14 17:35:39 +03:00
Konstantin Belousov 1a71d24ecd kern/sys_process.c: make vmspace_rwmem() similar to io functions
In particular, if there were any bytes moved, and then vm_fault()
faulted, do not return an error, but report the short io instead.

PR:	297512
Reviewed by:	markj
Tested by:	Stéphane D'Alu <[email protected]>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58838
2026-08-14 17:35:38 +03:00
Konstantin Belousov f6000e9dd9 kern/kern_proc.c: do not throw out read data in get_ps_strings()
Since vmspace_iop()/proc_readmem() might return -1 on error from
vmspace_rwmem(), account for this and stop reading but return already
accumulated data if any, instead of returning an error.

PR:	297512
Reported and tested by:	Stéphane D'Alu <[email protected]>
Reviewed by:	markj
Fixes:	e1b0d051bb ("proc: Allow to make proc_rwmem() operate on a consistent address space")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58838
2026-08-14 17:35:38 +03:00
Konstantin Belousov 01d4e3c1d3 netipsec/xform_ipcomp.c: fix sockaddr type set in ipcomp6_nonexp_encapcheck()
Noted and reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58646
2026-08-14 17:35:38 +03:00