Commit Graph
100 Commits
Author SHA1 Message Date
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
Konstantin Belousov cba481a7bf PF_KEY socket: limit the length of copied socket address
for SADB_UPDATE op SADB_X_EXT_NEW_ADDRESS_SRC/DST extensions, by
checking the sa_len matching the address family requirements before
doing the copy.

Also convert KEY_SETSECASIDX() and KEY_SETSECSPIDX() to functions and
apply the sa_len clamping there.

See https://github.com/0xdeadbeefnetwork/pfkey-sadb-overflow

PR:	297264
Tested by:	Wafa Hamzah <[email protected]> (previous version)
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
Konstantin Belousov fbe9aa7ebf netipsec/key.c::key_checksockaddrs(): constify src/dst address buffer pointers
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
Konstantin Belousov 6747bf7e22 linuxkpi: stop inlining accesses to curthread->td_lkpi_task
This should provide much higher resistence against struct thread layout
changes for out-of-tree modules depending on linuxkpi.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58733
2026-08-13 18:29:14 +03:00
Konstantin Belousov e2cfbd498a tty: do not recurse on ttydev_close()
When the terminal cdev is closed due to revoke, ttydev_close() destroys
t_inpoll and t_outpoll selinfos.  Since corresponding knotes reference
files pointing to the same tty cdev, it fdrop()s them.  But then the
VOP_CLOSE() call would recurse into the ttydev_close() for the same tty.
More, because the devfs vnode is already doomed, each close call gets
the FREVOKE flag set.

As result, the kernel is recursing as deep into the ttydev_close() as
there are opened files referencing the same tty, which have the knotes
installed.  Basically, the recursion level is controlled by userspace.

Prevent it by marking the tty that is handled by ttydev_close(), with
the TF_INDEVCLOSE flag.  Do nothing in ttydev_close() when the flag is
already set, avoiding recursion.

Fixes:	acd5638e26 ("tty: delete knotes when TTY is revoked")
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58706
2026-08-13 18:29:14 +03:00
Konstantin Belousov 6a8558cf9f vm/vm_phys.c: allow PHYS_TO_VM_PAGE(0) for registered fictitious page @0
PR:	296348
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58785
2026-08-11 16:26:35 +03:00
Konstantin Belousov 9f5c4ef328 dounmount(9): temporarily enable recursion for the covered vnode lock
For some complex nullfs mount configurations, it is possible to get the
covered vnode lock for the mount shared with some inside-mount vnode
lock.  Then at unmount time, vflush() would recurse on the covered vnode
lock when reclaiming the vnode.

Work around it, by temprorarily allowing recursion on the covered vnode
lock.  Disable recursion after the unmount if it was not enabled before.

PR:	297174
Reviewed by:	jah
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58567
2026-08-07 12:09:50 +03:00
Konstantin Belousov 1d97ad676d lockmgr(9): add lockcanrecurse(9)
Also add vnode locking wrappers for lockcanrecurse(9) and
lockdisablerecurse(9).

Reviewed by:	jah
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58567
2026-08-07 12:09:50 +03:00
Konstantin Belousov b0a85cb9df ptrace_test: require debug.ptrace_transparent_attach enabled for its test
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2026-08-07 02:11:10 +03:00
Konstantin Belousov d3c3a705b5 autofs: try to avoid waiting for timeouts of in-flight requests for forced unmounts
Do the advisory aborts of the in-flight requests before flushing the
vnodes.  It should mostly eliminate the waits due to requests busying
the mp.

Reported and reviewed by:	rew
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58637
2026-08-06 11:54:47 +03:00
Konstantin Belousov dfdd8af5a8 pddupfd.2: fix errno value returned for non-procdesc argument
Noted  and reviewed by:	lwhsu
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58666
2026-08-05 21:16:08 +03:00
Konstantin Belousov e8b9b6b9f3 pdkill(2), pdgetpid(2): return EBADF if the file type is not procdesc
For pdwait(2) and pddupfd(2), the returned error is kept EINVAL.

PR:	297293
Reviewed by:	lwhsu, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58666
2026-08-05 21:15:54 +03:00
Konstantin Belousov b95a859483 autofs_lookup(): busy the mount point around autofs_trigger()
Since autofs_lookup() calls into autofs_trigger_vn() to perform
automounting, and autofs_trigger_vn() unlocks the vnode, it is possible
for the unmount to start meantime.  Then autofs_trigger() accesses freed
memory.

At this point, busy can be only done unblocking, and the transient
failure must abort the trigger operation.  This would cause spurious
automounter errors, but at least should prevent accesses to the freed
memory.

PR:	294361
Reviewed by:	markj, rew
Tested by:	rew
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58626
2026-08-05 01:36:13 +03:00
Konstantin Belousov 4c58eef12d stat.2: enhance the description of st_blocks
Reviewed by:	emaste, mckusick
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential revision:	https://reviews.freebsd.org/D58592
2026-08-03 01:17:28 +03:00
Konstantin Belousov 77d6c45afd tests/sys/capsicum: adjust tests for the new reaping behavior
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58569
2026-08-01 13:42:04 +03:00
Konstantin Belousov a96f285b59 tests/sys/kern: adjust tests for the new reaping behavior
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58530
2026-08-01 13:42:01 +03:00
Konstantin Belousov c49198534a pdwait(2), wait(2): document interaction between pdopenpid() and waitpid()
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58264
2026-08-01 13:41:54 +03:00
Konstantin Belousov bcdb6ba94d processes: add zombie references, each of them prevents reap
Add the p_zombieref bitmask into struct proc, which enumerates all
legitimate waiters on the process exit status. Among them are parent
for PZOMBIEREF_PARENT, and the holder of the process descriptor for
PZOMBIEREF_PROCDESC, if the process was created by pdfork().

Require all zombie refs to be cleared to reap zombie. This prevents
stealing the exit status from the parent by pdwait()ing on a procdesc
obtained by pdopenpid(), or by waitpid() by debugger from the real
parent.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58264
2026-08-01 13:41:45 +03:00
Konstantin Belousov 7da4edd300 pdwait(2): change handling of the exited processes
Instead of accessing the struct proc and gathering data from it,
memoize the data needed for pdwait() on exited process in struct
procdesc, at the time of process termination.

This allows unlimited number of calls to pdwait(2) on procdesc for
terminated process.

Change the locking requirements for pd_flags to proctree_lock. This does
not modify the pre-patch locking regime, but the change requires it.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58407
2026-08-01 13:41:35 +03:00
Konstantin Belousov a24674ecab kern/kern_exit.c: make wait_fill_siginfo/wrusage global
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58407
2026-08-01 13:41:28 +03:00
Konstantin Belousov 833bdae6c5 proc_realparent(): do not mark the child as orphan when reparenting to p_opptr pid
Reported and reviewed by:	markj
Fixes:	8cef3c9b76 ("proc_realparent(): assert that an orphaned child has real parent != parent")
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58566
2026-07-31 18:57:31 +03:00
Konstantin Belousov 72952bf6a3 amd64: try to fix the build with old clang that does not know about FRED
Reported by:	jhb
Reviewed by:	jhb, jrtc27
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58550
2026-07-30 20:08:24 +03:00
Konstantin Belousov cef05c5a62 amd64: do not allow to set reserved bits in MXCSR for ptrace(PT_SETFPREGS)
Also do not mask bits in the mxcsr_mask.  It is ignored by FRSTOR/XRSTOR.

Reported by:	markj
Reviewed by:	jhb, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58548
2026-07-30 20:08:24 +03:00
Konstantin Belousov 930f2e4da9 kern_execve(): avoid storing non-VDIR into p_textdvp
Reported by:	Nick Price
Tested by:	pho
Reviewed by:	jah, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58506
2026-07-30 05:56:30 +03:00
Konstantin Belousov b72f9bfc45 statfs(2): allow to interrupt busying
There are probably more places which could benefit from allowing to
interrupt vfs_busy() calls at syscalls top level.

Requested by:	Peter Eriksson <[email protected]>
Reviewed by:	jah, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58477
2026-07-29 08:20:12 +03:00
Konstantin Belousov fb4d7bd4b7 vfs_busy(): add MBF_PCATCH flag to allow interrupting the sleep
Reviewed by:	jah, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58477
2026-07-29 08:20:07 +03:00
Konstantin Belousov 2e259c209f kern_pdwait(): print the process pointer through pd
to avoid using uninitialized value in the KASSERT() statement on the first
iteration.

Also, do the assert under the proctree_lock, which is not critical but
satisfies the invariants.

Noted and reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58505
2026-07-28 22:45:52 +03:00
Konstantin Belousov 8cef3c9b76 proc_realparent(): assert that an orphaned child has real parent != parent
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58504
2026-07-28 22:45:47 +03:00
Konstantin Belousov a3b5937da6 mknod.2: properly document root requirements
Submitted by:	Martijn Dekker <[email protected]>
PR:	297082
Fixes:	4090d103b0 ("mknod.2: update the man page")
MFC after:	3 days
2026-07-28 04:01:52 +03:00
Konstantin Belousov 34ca5a9e73 geom_zero(4): reset the uio vector on each uiomove()
PR:	297062
Tested by:	Jordan Gordeev <[email protected]>
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58472
2026-07-27 21:46:32 +03:00
Konstantin Belousov 10ea2300bf tests/libpthread: add pthread_cond_clockwait(3) tests
Reviewed by:	markj, ngie
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58458
2026-07-27 19:17:29 +03:00
Konstantin Belousov e7015a3834 pthread_cond_timedwait.3: document pthread_cond_clockwait(3)
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58463
2026-07-27 19:17:29 +03:00
Konstantin Belousov 6d3db07a2e pthread_cond_timedwait.3: use .Fo/.Fc for long arguments list
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58463
2026-07-27 19:17:29 +03:00
Konstantin Belousov e1136fbcab libthr: implement pthread_cond_clockwait(3)
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D58463
2026-07-27 19:17:28 +03:00