100 Commits
Author SHA1 Message Date
Brooks Davis 4ca9291004 kenv(2): add kern_kenv
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2284
2026-11-07 12:10:46 +00:00
Brooks Davis 230d581d4e fstat(2): add user_fstat
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2284
2026-11-07 12:10:46 +00:00
Brooks Davis 3369af6f98 cpuset(2): add kern_cpuset
Effort:		CHERI upstreaming
Sponsored by:	 Innovate UK
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2284
2026-11-07 12:10:46 +00:00
Brooks Davis d7c0ab90cd acct(2): add kern_acct
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2284
2026-11-07 12:10:45 +00:00
Brooks Davis 7b18863d59 mac syscalls: add kern_ implementations
Where the kern_ interfaces map trivially to the syscall interface, follow
the syscall name even if awkward (e.g., sys___mac* -> kern___mac*).
Otherwise use shorter names.

Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2284
2026-11-07 12:10:45 +00:00
Brooks Davis 675739153b sys/security/audit: add kern_ implementations
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
PR:		https://github.com/freebsd/freebsd-src/pull/2284
2026-11-06 13:58:14 +00:00
Brooks Davis deadb35bec updateuio_t: improve comment and style
Reported by:	netchild
Effort:		CHERI upstreaming
Fixes:		afe41f1ab9 ("sys/uio: add updateiov()")
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D60169
2026-10-13 15:01:30 +01:00
Brooks Davis 2127135a22 jail_{get,set}: user_ implementations
This will enable compat implementations in the future.

Reviewed by:	jamie, jhb
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D60026
2026-09-29 19:14:07 +01:00
Brooks Davis afe41f1ab9 sys/uio: add updateiov()
This function take a struct uio previously created by copyinuio and and
updates the lengths of the user-space iovec to match those in the uio.

To reduce the risks of pointer leakage and cross-ABI pointer confusion,
lengths are updated individually.

Reviewed by:	jamie, jhb
Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL, Innovate UK
Differential Revision:	https://reviews.freebsd.org/D60025
2026-09-29 19:14:06 +01:00
Brooks Davis 53fe018630 amd64: gate WRMSRNS immediate form on compiler support
This support was introduced in LLVM 20 and we still support releases
with LLVM 19 so it's too early to require LLVM 20.  Decay to the
non-immediate form when the compiler it too old.  This makes the ifunc
pointless, but limits the need for other ifdefs.

Reviewed by:	kib
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D60023
2026-09-26 12:43:34 +01:00
Brooks Davis 2a717d519e uio: make *copyinuio take a void *
This aligns with copyinuio_t and avoids some hypothetical undefined
behavor around calling functions with mismatched types.

Reviewed by:	kib
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D60024
2026-09-26 12:05:43 +01:00
Brooks Davis e376d28ce8 LINT: enable KLD_DEBUG
Without this, no kernel config contained this option so it was easy to
break.

Sponsored by:	Innovate UK
2026-09-21 10:54:12 +01:00
Brooks Davis 0a3d54a47e kern_linker: use __func__ correctly in diagnostics
__func__ is a variable not a string literal so pass it to printf.  This
only manifest when KLD_DEBUG was defined so wasn't tested by an kernel
including LINT.

Reported by:	Mark Millard <[email protected]>
Sponsored by:	Innovate UK
2026-09-21 10:53:45 +01:00
Brooks Davis c1e7332587 sendfile(2): rework compat implementation
Rename the sendfile() function to kern_sendfile(), expand the arguments
previously passed in struct sendfile_args, and extend with two function
pointer arguments to copy in the header/trailer structure and the
create uio's for the header and trailer as required.  Use this to allow
the removal of freebsd32_do_sendfile() which was a nearly identical
duplicate of sendfile() with attendant maintenance cost.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D59034
2026-09-13 09:41:59 +01:00
Brooks Davis 2ff0ca5272 uexterror(3): install the right manpage
Reported by:	Herbert J. Skuhra
2026-08-20 14:31:07 +01:00
Brooks Davis 94f86eff72 uexterror_gettext: add tests for invalid formats
Verify that unsupported, unterminated, and overly long formats output
expected messages.

Reviewed by:	kib
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58413
2026-08-20 11:40:41 +01:00
Brooks Davis ddf6065122 exterr(9): add a few tests of new message formats
This is enough to show that the idea works (and to exercise
uexterr_set()), but isn't complete by any means.

Reviewed by:	kib
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58060
2026-08-20 11:40:31 +01:00
Brooks Davis 95e33099c7 runtime: add the ability to set exterrors in userspace
The UEXTERROR(3) macro is a partial analog to EXTERROR(9) that sets
the current user exterror state and errno.  The main difference is
that it returns no value and sets errno directly since that's the
typical pattern in libraries.

While here move the storage and constructor for single-threaded
program's uexterr to its own file.

Reviewed by:	kib
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58059
2026-08-20 11:39:00 +01:00
Brooks Davis 2f024a7cfd exterr: relax format restrictions
Rather than passing the format string to printf and forcing the
arguments to be (u)intmax_t, partially parse format strings and cast
p1 and p2 to the correct type before running the individual format
though printf.  This restructure has a couple motivatations:
 - We can skip formats that make no sense (floating point, %n, etc.).
 - It is possible to special case the printing of pointers in the
   CHERI case.

The first case is motivated by a suggestion from the audiance at
one of Kirk's BSDCan talks on exterr to allow userspace to set exterr
status.  Allowing arbitrary format strings including %n creates a
write-what-where gadget so we need to not do that.

The second case is motivated by our experinces with CHERI and debugging
mmap issues using a different textual error reporting framework.  With
CHERI, pointers are more than integer addresses and it's useful to
include more details.  Doing so will follow in a future commit.

When the new code encounters an inappropriate format it includes
a diagnostic and in most cases prints the format untouched.

Reviewed by:	kib
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58058
2026-08-20 11:38:19 +01:00
Brooks Davis 7516130eb9 kdump(1): minimally adapt to exterror category sources
Add some minimal handling of category sources other than static kernel
sources.  We don't actually look up dynamic sources yet (that would
require extended trace records to add the file names to the trace file
since we can't assume the trace file is running on a kernel with the
same numbers.)

Make the decision to append a "src/" prefix to each file name
dependent on the category source.

Reviewed by:	kib
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58412
2026-08-03 22:43:23 +01:00
Brooks Davis 5dff273d68 uexterr_gettext(3): support dynamic kernel categories
Add an uncached sysctl based implementation which retrieves individual
categories.  A cache would be an obvious extension should this optional
feature that can only be enabled by an environmental varible have a
noticable performance impact in a case that matters.

Reviewed by:	kib
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58238
2026-08-03 22:43:23 +01:00
Brooks Davis 295f102309 exterror(9): dynamic kernel categories
Make it possible to define categories without compiling their
paths into libc (important for third-party modules).  The
EXTERR_CATEGORY_DYNAMIC macro can be defined to a string describing the
compilation unit (generally the path relative to src/sys) which takes
the place of EXTERR_CATEGORY.

These strings are assembled in linker sets with category numbers
assigned at system startup or module load time.  The strings can be
retrieved from the kern.exterr.categories.<category> sysctl.

Reviewed by:	kib
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58237
2026-08-03 22:43:23 +01:00
Brooks Davis bbf95a9b84 exterror(9): split category into multiple sources
The static, global index into an array of strings is simple, cheap,
and works for the base kernel, but is unworkable for (potentially
third-party) kernel modules or for arbitrary userspace code.  Swipe a
few of the top bits of category to indicate a source with all-zeros
being the current model (EXTERR_CAT_SRC_KERN_STATIC).  Add two
additional sources EXTERR_CAT_SRC_KERN_DYNAMIC and EXTERR_CAT_SRC_USER
with stub implementations.

Reviewed by:	kib
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58236
2026-08-03 22:43:22 +01:00
Brooks Davis 6880edbfd5 rtld: fix indentation of multiline conditional
Fixes:		7e2f38311e ("rtld-elf/rtld.c: apply clang-format")
Sponsored by:	Innovate UK
2026-08-03 17:47:32 +01:00
Brooks Davis b3b4763bc1 sys/exterrvar.h: forward declare struct thread
Remove dependency on sys/proc.h.

Reviewed by:	imp
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58235
2026-07-15 10:32:16 +01:00
Brooks Davis 844009378d exterr: allow exterr to fit pointers on CHERI targets
Switch to uint64ptr_t which is a uint64_t on traditional architectures
and a uintptr_t on CHERI architectures.  This has no ABI impact on
non-CHERI kernels.

Fix truncation of 64-bit values on 32-bit kernels.

Reviewed by:	kib
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D58056
2026-07-15 10:32:16 +01:00
Brooks Davis db3eca2be2 exterrctl(2): add kern_exterrctl
Reviewed by:	kib
Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D58055
2026-07-15 10:32:16 +01:00
Brooks Davis 524fb0444f fetch.9: fix a typo
Fixes:		a1c52e05f5 ("CHERI: declare fueptr and suptr")
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
2026-07-01 15:09:15 +01:00
Brooks Davis 17602eb3ea CHERI: make mem{cpy,move}(9) CHERI compatible
- Use intptr_t in place of long as the word type in the core copying
  loop where aligned words a copied.  This preserved the provenance of
  any copied pointers.
- When working with the address of src or dst use ptraddr_t rather than
  uintptr_t.  This avoid ambigious provenance in expressions involving
  multiple addresses.

As a minor tweak, rename the function to memmove since that is the
interface it implements (overlapping src and dst are permitted) and make
memcpy the alias rather than the other way around.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57965
2026-07-01 12:49:10 +01:00
Brooks Davis f14bdfefa4 CHERI: add sooptcopyinptr to preserve pointer provenance
Most socket options don't involve pointers so make the default
sooptcopyin discard provenance and add a sooptcopyinptr that preserves.

Reviewed by:	markj, emaste
Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL, Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57665
2026-07-01 12:48:10 +01:00
Brooks Davis 7f55dbe6ae CHERI: declare mem{cpy,move}_data
Declare kernel-only, provenance-discarding memcpy_data, and memmove_data
APIs intended to copy raw data which does not contain pointers (e.g.,
buffers on their way to or from network or storage devices).  On CHERI
architectures, they will explicitly remove tags from capabilities,
removing any provenance.  This reduces the risk of accidental spread of
pointers on CHERI systems.

Document that bcopy preserves pointer provenance.

Reviewed by:	ziaee, kib, adrian, markj
Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL, Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57662
2026-07-01 12:46:11 +01:00
Brooks Davis a1c52e05f5 CHERI: declare fueptr and suptr
These should replace fueword and suword when manipulating pointers in
memory.  On CHERI targets they will be implemented using capability
aware instructions and otherwise they are defined to fueword and suword.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57664
2026-06-29 13:59:44 +01:00
Brooks Davis b517edb8de CHERI: declare copy{in,out}ptr{,_nofault}
These provenance-preserving functions are to be used when copying
objects that are expected to contain pointers.  Data buffers which do
not contain pointers should be copied by the traditional copyin/copyout
functions which *do not* preserve pointer provenance (on CHERI they
clear validity tags).

NOTE: Going forward, this requires changes when adding new syscalls or
ioctl that take pointers to objects containing pointers.  Fortunately,
the vast majority (>90%) of copyin and copyout statements do not copy
pointers and require no change.  Failure to make the chance will have no
effect on non-CHERI architectures.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL, Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57663
2026-06-29 13:59:29 +01:00
Brooks Davis b207b1562a sys/systm.h: use __nodiscard consistently and correctly
__nodiscard is closer to (and sometimes expands to) [[nodiscard]] from
C23 and C++17 so prefer it to the homegrown __result_use_check and put
it in the right place so it is correct when expanded to [[nodiscard]].

Reviewed by:	markj, emaste
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D57882
2026-06-26 17:42:06 +01:00
Brooks Davis 2515e3f677 cdefs(9): encourage __nodiscard over __result_use_check
__nodiscard is closer to (and sometimes expands to) [[nodiscard]] from
C23 and C++17 so prefer it to the homegrown __result_use_check.

When __nodiscard does expand to [[nodiscard]] it must appear entierly
before the function declaration (or between the function name
and argument list) so relocate as appropriate.  This differs from
__attribute__((__warn_unused_result__)) used by __result_use_check which
is more flexible.

Reviewed by:	imp, markj, emaste
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D57881
2026-06-26 17:41:40 +01:00
Brooks Davis 1366a87c9c memory_model(7): create and document pointer provenance
Add a skeleton manpage intended to describe the FreeBSD memory model.

To start out, add documentation of pointer provenance and a cross link
to atomic(9).

Provide some advice on preserving provenance in CHERI and reference
more detailed discussions elsewere.

Effort:		CHERI upstreaming
Reviewed by:	kib, adrian, markj, emaste
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57812
2026-06-26 12:26:11 +01:00
Brooks Davis 00b0ea95df arch.7: used title case for .Ss headings
Do capitalize "size".  Don't gratutiously capitalize "char" any more
than we do "make" further down.

Reviewed by:	emaste
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D57820
2026-06-25 11:05:28 +01:00
Brooks Davis b94f438906 Add kernel manpages for bcopy, memcpy, and memmove
We will add variants of memcpy and memmove to support CHERI so
bootstrap the manpages from section 3.

Mark bcopy as deprecated.

Reviewed by:	imp, kib, emaste
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57661
2026-06-25 11:05:02 +01:00
Brooks Davis 015b890e28 mem*.3: stop refering to strings
POSIX and the C standard now refer to objects and sequences rather
than confusingly revering to strings.

Also update bcopy(3) and bzero(3).

Reviewed by:	emaste
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57680
2026-06-21 17:48:49 +01:00
Brooks Davis 8b47939b95 uipc_socket: prefer memcpy to bcopy
Reviewed by:	kib, emaste
Suggested by:	emaste
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57689
2026-06-21 17:13:31 +01:00
Brooks Davis fc9b28879e uiomove_*: centralize the copy function selection
Add a uiomove_step() for the central set of switch statements which
choose between userspace and kernel and if data is going to or from the
iovec.

Refactor uiomove_fromphys loops to unconditionally free per-iteration
resources and drop gotos.

While here, switch from bcopy to memcpy.

Reviewed by:	kib
Suggested by:	emaste
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57688
2026-06-21 17:13:27 +01:00
Brooks Davis 2ee2ef607f pmap: prefer memcpy over bcopy
Alter pmap_copy_page(s) to use memcpy rather than the deprecated bcopy.
We'll be adding non-provenance preserving versions for CHERI support and
would like to avoid introducing variants of deprecated APIs just to
maintain symmetry.

Reviewed by:	kib
Suggested by:	emaste
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D57687
2026-06-21 17:08:12 +01:00
Brooks Davis a7e07d0d57 libgcc_s: export __extendhftf2
We've compiled it since the LLVM 13 import in 2021, but for some reason
never exported it.  A user of CheriBSD recently caused Morello LLVM to
emit a reference to it so finish the job and export it.

Reviewed by:	dim, emaste
Fixes:		6e75b2fbf9 ("Merge llvm-project release/13.x llvmorg-13.0.0-rc1-97-g23ba3732246a")
MFC after:	1 week
Sponsored by:	DARPA, AFRL
See also:	https://github.com/CTSRD-CHERI/cheribsd/issues/2614
Differential Revision:	https://reviews.freebsd.org/D56310
2026-04-08 16:31:55 +01:00
Brooks Davis 4dd517acb6 libc/armv7: remove default version for alloca
The alloca() interface has been a macro expanding to __builtin_alloca()
since 2003 (commit 79806b4cdc, included in FreeBSD 5.2).  Even before
that virtually every compiler version I was able to test replaced
alloca() with compiler generated code when targeting C.

Hide it to prevent future (mis)use.

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D51858
2026-03-05 10:34:47 +00:00
Brooks Davis db1ecd5854 getnetconfig: make nc_error a thread local variable
Remove a bunch of complexity at the cost of 4 bytes of storage per
thread.

Reviewed by:	jhb
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D55310
2026-03-05 10:30:30 +00:00
Brooks Davis ea9bc84658 cirrus-ci: move package_check after test
Liveness is often more important than minor packaging glitches (which
might well be the fault of a prior commit.)

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D55481
2026-03-05 10:23:51 +00:00
Brooks Davis 0076f6d1ad sys/_offsetof.h: pacify GCC 12's macro redefinition check
GCC 12 has a strict definition of identity (all characters including
whitespace must be identical) when comparing "redefined" macros. Make
our definition exactly match the stddef.h that comes with GCC to fix
test-includes of netlink/netlink_snl.h.  (Note: later versions of GCC
are a bit more flexible and don't have this problem.)

Reported by:	des
Sponsored by:	DARPA, AFRL
Fixes:		2adc3f0db1 ("stddef.h: centralize definition of offsetof()")
2026-02-23 10:05:06 +00:00
Brooks Davis dcbd1fccdc types.h: use central definition of offsetof()
Previously this broke if included after (sys/)stddef.h.

Reported by:	des
Fixes:		2adc3f0db1 ("stddef.h: centralize definition of offsetof()")
2026-02-19 16:25:26 +00:00
Brooks Davis a31127e6df sys/syscallsubr.h: assorted tidying
- gc unused struct kevent
- sort kern_frmdirat, kern_funlinkat, kern_kexec_load, and kern_kqueue
- put user_ functions in their own section

Effort:		CHERI upstreaming
Reviewed by:	kib
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D55309
2026-02-19 15:10:33 +00:00
Brooks Davis 89c3ae5fc9 build: add stddef.h to define ptraddr_t as required
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Reviewed by:	kib
Co-authored-by:	Alfredo Mazzinghi <[email protected]>
Co-authored-by:	Alex Richardson <[email protected]>
Differential Revision:	https://reviews.freebsd.org/D55308
2026-02-19 15:10:32 +00:00
Brooks Davis 2adc3f0db1 stddef.h: centralize definition of offsetof()
Move to sys/_offsetof.h and use __builtin_offsetof() instead of
__offsetof to avoid reintroducing sys/cdefs.h polution in stddef.h.

This has the side effect of allowing sys/stddef.h to be included after
stddef.h which can happen in compatability headers.

Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL
Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D55307
2026-02-19 15:10:32 +00:00
Brooks Davis cb59eec9eb stddef.h: add ptraddr_t
I'd missed that stddef.h is standalone and isn't a copy of sys/stddef.h
in my initial merge.

Effort:		CHERI upstreaming
Reviewed by:	kib
Sponsored by:	Innovate UK
Fixes:		dca634d154 ("new type: ptraddr_t")
Differential Revision:	https://reviews.freebsd.org/D55305
2026-02-19 15:10:32 +00:00
Brooks Davis 1e18927957 .github: support all stable branches
If this eventually poses a problem for unsupported branches we can fix
them directly.

Sponsored by:	Innovate UK

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D53838
2026-02-19 15:10:32 +00:00
Brooks Davis c4130a8a84 OpenSSL: install EVP_CIPHER_CTX_get_app_data.3 once
A separate EVP_CIPHER_CTX_get_app_data.3 was added in the OpenSSL 3.5.5
import, but the link to EVP_EncryptInit.3 was still being installed
which stomped on the file and created inconsistent entries in the METALOG.

Reviewed by:	emaste
Found by:	package_check script in Cirrus-CI
Fixes:		1731fc70f7 ("OpenSSL: update vendor sources to match 3.5.5 content")
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D55332
2026-02-17 18:24:29 +00:00
Brooks Davis 18d47c1856 rpc: correct resultproc_t's type
It takes exactly three arguments of known type.

Tweak the types of various resultproc_t functions to match the type (mostly
added const to struct pointers) allowing us to drop casts.

Effort:		CHERI upstreaming
Reviewed by:	vangyzen, glebius
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54941
2026-02-02 21:20:16 +00:00
Brooks Davis e236502a99 clnt_broadcast(3): fix eachresult argument type
The `eachresult` argument is documented to take a function pointer of
type:

	bool_t (*)(caddr_t, struct sockaddr_in *)

It was declared to take a resultproc_t which has historically been
declared to be:

	bool_t (*resultproc_t)(caddr_t, ...);

This overlapped well enough for currently supported ABIs where variadic
arguments are passed in registers, but this declaration is misaligned
with the documentation (resultproc_t takes three arguments) and will be
fixed in a followup commit.

Fix the type to be non-variadic, matching callbacks, and define a
convenience type of as most callbacks take something other than a char *
as their first argument and need to be cast.

Effort:		CHERI upstreaming
Reviewed by:	ngie, glebius, jhb
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54940
2026-02-02 21:20:10 +00:00
Brooks Davis 47413f23e5 clnt_broadcast(3): don't free function pointers
Replace use of thr_getspecific/thr_setspecific to stash the function
pointer we're smuggling between clnt_broadcast and rpc_wrap_bcast with a
simple thread local variable.  Clear it after use so the reference
doesn't linger.

In the relatively unlikely event clnt_broadcast was called from threads
that exited prior to program termination, the previous code called free
on a function pointer, which is undefined and might corrupted allocator
state.

Effort:		CHERI upstreaming
Reviewed by:	glebius, jhb
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54939
2026-02-02 21:20:01 +00:00
Brooks Davis e17d7ab869 xdr_string: don't leak strings with xdr_free
Historically (and in a small amount of older software such as OpenAFS),
developers would attempt to free XDR strings with

	xdr_free((xdrproc_t)xdr_string, &string)

This resulted in xdr_free calling xdr_string with only two intentional
arguments and whatever was left in the third argument register.  If the
register held a sufficently small number, xdr_string would return FALSE
and not free the string (no one checks the return values).

Software should instead free strings with:

	xdr_free((xdrproc_t)xdr_wrapstring, &string)

Because buggy software exists in the wild, act as though xdr_wrapstring
was used in the XDR_FREE case and plug these leaks.

Reviewed by:	kib
MFC after:	3 days
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D54825
2026-01-23 10:35:55 +00:00
Brooks Davis ac5a19ec69 rpc/xdr.h: make xdrproc_t always take two arguments
The type of xdrproc_t is clearly defined in the comments as a function
with two arguments, an XDR * and a void * (sometimes spelled caddr_t).
It was initialy defined as:

	typedef bool_t (*xdrproc_t)();

At some point people started giving it a non-empty argument list.
Unfortunatly, there has been widespread disagreement about how arguments
are passed.  There seems to have been a widespread view that it should
be allowed to pass three argument function pointer to xdrproc_t.  Most
notable is xdr_string which takes a maximum length parameter. This lead
to all sorts of prototypes (all of which have been present in the
FreeBSD source tree):

FreeBSD userspace (nominally from tirpc, but seemingly local):
	typedef bool_t (*xdrproc_t)(XDR *, ...);
FreeBSD kernel, glibc:
	typedef bool_t (*xdrproc_t)(XDR *, void *, ...);
rcp/xdr.h with _KERNEL defined (not used?):
	typedef bool_t (*xdrproc_t)(XDR *, void *, u_int);
gssrpc (in krb5) and Linux kernel:
	typedef bool_t (*xdrproc_t)(XDR *, void *);

For two argument functions on current ABIs, these all equivalent as
these arguments are passed in registers regardless of decleration and
definition, but we end up with two problems:

   - xdr_free((xdrproc_t)xdr_string, ...) calls xdr_string with no third
     argument and (at least on FreeBSD) may fail to free memory if the
     string is shorter than the value lying around in the third argument
     register.  There are no instance of this in tree, but I found some
     with Debian code search, in particular in OpenAFS.

   - Under CheriABI, variadic arguments are passed in a separate,
     bounded array so theses prototypes aren't equilvalent to the
     non-variadic calling convention of the functions.

The reality is that that xdr_string should not be cast to xdrproc_t and
xdr_wrapstring should be used instead so we do not need to support this
case.  Instances of the former behavior are now extremely rare.

With this change we bring FreeBSD in line with gssrpc and the Linux
Kernel.  Warnings about casts should now be correct and should be fixed.

Bump __FreeBSD_version as some software required adaptation if it is
declaring functions to cast to xdrproc_t.  Update OpenZFS's workaround
of this historic mess accordingly.

Effort:		CHERI upstreaming
Sponsored by:	Innovate UK

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D54824
2026-01-23 10:35:32 +00:00
Brooks Davis a01a4c0730 CODEOWNERS: register interest in some infrastructure 2026-01-16 09:43:12 +00:00
Brooks Davis d78291b0e9 lib/virtual_oss: don't (over)link to libsamplerate
These plugins require samplerate.h due to virtual_oss's int.h including
it, but don't use any symbols directly so don't link to the library.

Centralize adding the include path.

Reviewed by:	christos
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54705
2026-01-16 09:34:18 +00:00
Brooks Davis 373c72ad50 virtual_oss: build system tidying
general:
 - find libsamplerate's headers in the temporary sysroot instead of
   digging in the source tree.
 - use LIBADD where possible

lib/virtual_oss:
 - centralize SHLIBDIR define
 - centralize include path for internal headers
 - don't try to find libsamplerate directly in .OBJDIR

No functional changes.

Reviewed by:	christos
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54704
2026-01-16 09:33:56 +00:00
Brooks Davis adab1dd6a7 virtual_oss: build commands/libs in parallel
Reviewed by:	christos
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54703
2026-01-16 09:33:50 +00:00
Brooks Davis 497a13601f virtual_oss: remove needless .include in intermediate Makefile
It doesn't define anything we use.

Reviewed by:	christos
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54702
2026-01-16 09:33:22 +00:00
Brooks Davis 0a64d16cef sys/_types.h: avoid use of __has_feature()
Only fairly recent GCC versions support and sys/_types.h must work with
quite old compilers and without sys/cdef.h being included.  The prior
workaround works fine, but we can have the same effect with compiler
macro definitions.  In this specific case, compilers that define the
__intcap_t builtin type will define __SIZEOF_INTCAP__.

This reverts commit 029a09f180
This reverts commit 19728f31ae

Reviewed by:	imp, des, kib, emaste
Effort:		CHERI upstreaming
Fixes:		85ab981a8e ("sys/_types.h: define fallback __(u)intcap_t")
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D54009
2026-01-09 14:42:00 +00:00
Brooks Davis 31e7dc6b9a iflib: remove convoluted custom zeroing code
Replace a collection of aliasing violations and ifdefs with memset
(which now expands to __builtin_memset and should be quite reliably
inlined.)  The old code is hard to maintain as evidenced by the most
recent change to if_pkt_info_t updating the defines, but not the zeroing
code.

Reviewed by:	gallatin, erj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Fixes:		43d7ee540e ("iflib: support for transmit side nic KTLS offload")
Differential Revision:	https://reviews.freebsd.org/D54605
2026-01-09 14:19:49 +00:00
Brooks Davis 1b425afa8d cache: avoid hardcoded CACHE_PATH_CUTOFF
Compute the cutoff at compile time instead which will avoid the need
for a CHERI case.

Correct the comment about CACHE_PATH_CUTOFF.  It dates to 5.2.0 not 4.4
BSD.  Historic values are:

32 - introduced (c2935410f6)
35 - NUL terminated and bumped (5d5c174869)
39 - sized to alignment (bb48255cf5)
45 - bumped to improve efficency on 64-bit (3862838921)

No functional change.

Reviewed by:	markj
Suggested by:	jhb
Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54554
2026-01-09 14:15:43 +00:00
Brooks Davis 258ad80092 cache: avoid hardcoded cache padding
Replace CACHE_LARGE_PAD with rounding up to the alignment of struct
namecache_ts.

No functional change.

Reviewed by:	olce, markj
Suggested by:	jhb
Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54553
2026-01-09 14:15:35 +00:00
Brooks Davis fb0bdbea2e cache: avoid hardcoded zone alignment
Previously, this was underaligned on CHERI system where pointers are
larger than time_t.

Use the alignment of struct namecache_ts which picks up time_t via strut
timespec and pointers via struct namecache.  This arguably overaligns
cache_zone_small and cache_zone_large on i386 kernels, but I suspect the
actual microarchitectures most i386 binaries are run on do better with
64-bit alignment.

Reviewed by:	olce, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Fixes:		cf8ac0de81 ("cache: reduce zone alignment to 8 bytes")
Differential Revision:	https://reviews.freebsd.org/D54376
2026-01-09 14:15:22 +00:00
Brooks Davis a79e2278c5 ipf: copy{in,out}ptr -> ipf_copy{in,out}_indirect
These functions take the source or destintation address indirectly from
a potentially missaligned buffer.  Rename them to refect this and to
free up the copy{in,out}ptr names.

Some of the code in question is dead code and doesn't or won't compile,
but I've changed it all for consistency.

NB: If the pointers are actually stored under aligned then this code is
broken with CHERI.

Reviewed by:	cy
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D54232
2025-12-19 15:59:08 +00:00
Brooks Davis b9b1262a8e src.conf.5: regen documenting WITH_IPFILTER_IPFS 2025-12-15 13:52:34 +00:00
Brooks Davis c112ad7560 options: describe WITH_IPFILTER_IPFS
Add a description for WITH_IPFILTER_IPFS.

Fixes:		0ff0c19e7f ("ipfilter: Disable ipfs(8) by default")
2025-12-15 13:50:56 +00:00
Brooks Davis 80203a27e9 Add sys/_align.h replacing machine/_align.h
Define _ALIGNBYTES using sizeof(void *) (no functional change on any
existing architecture) which will allow it to work with CHERI were we
must align things up to capability alignment.

In _ALIGN, replace integer manipulation which does not preserve pointer
provenance with a type and provenance preserving builtin.  This requires
modest changes in code which assumes _ALIGN returns an integer, but
those are relatively rare.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53947
2025-12-10 10:57:50 +00:00
Brooks Davis cfae62eac0 libcasper: fix warnings when _ALIGN preserves types
Without the void * casts, the compiler complains about an alignment
requirement increase.

Reviewed by:	kib, markj
Obtained from:	CheriBSD
Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D53946
2025-12-10 10:57:45 +00:00
Brooks Davis ac79e2e025 get*ent: be consistant about _ALIGN(p) - p
Add an nscache specific inline function to calculate the misalignment
rather than adding and subtracting _ALIGN(p) and p which can take the
buffer far out of bound (undefined behavior in C and unsupported on
CHERI).

Reviewed by:	kib
Effort:		CHERI upstreaming
Obtained from:	CheriBSD
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D53945
2025-12-10 10:57:34 +00:00
Brooks Davis 4e22cd3bf0 add types: (u)int64ptr_t
This type represents an integer value of at least 64 bits which is
capable of being cast to and from pointer types.  It is intended to
replace various spellings of (u)int64_t there the value is expected to
hold a pointer.  This is common in Linux code to allow 32-bit and 64-bit
structures to be the same and used other places including OpenZFS.  With
the introduction of CHERI this no longer works, but we need to preserve
the ABI for integer pointer targets.  Rather than adding ifdefs in every
case, we introduce a new type.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53823
2025-11-27 14:54:56 +00:00
Brooks Davis 6ebbfe723b sys/_types.h: add __intptr_t to __mbstate_t
Extend __mbstate_t to include an intptr_t to ensure it can hold a
pointer if required.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53822
2025-11-27 14:54:56 +00:00
Brooks Davis 528e70a12c sys/_types.h: add void * to __max_align_t
Add a pointer member to __max_align_t as pointers may have different
alignment requirements than long long or long double.

Reviewed by:	kib
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53821
2025-11-27 14:54:56 +00:00
Brooks Davis 85ab981a8e sys/_types.h: define fallback __(u)intcap_t
__intcap_t and __uintcap_t are new primative types in CHERI-aware ABIs
that are used to define (u)intptr_t.  To allow coexistance of integer
pointers and hybrid code, define them to __(u)intptr_t when they are
not otherwise available.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53820
2025-11-27 14:54:56 +00:00
Brooks Davis 96e05e2d1d sys/_types.h: define __(u)int(f)ptr_t for CHERI
On pure-capability ABIs, uintptr_t and variants are capabilities and
defined to the new primative type __uintcap_t and variants.  This is
required to allow pointers (capabilities) to round trip through
uintptr_t as required by the C standard.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53819
2025-11-27 14:54:56 +00:00
Brooks Davis 6aaba75383 sys/_types.h: centralize __vm_offset_t and __vm_size_t definitions
Use __ptraddr_t to define __vm_offset_t and __size_t for __vm_size_t
rather than per-pointer-size definitions.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53818
2025-11-27 14:54:56 +00:00
Brooks Davis dca634d154 new type: ptraddr_t
ptraddr_t is an unsigned integer type that can hold the address of any
pointer.  It differes from uintptr_t in that it does not carry
provenance which is useful for CHERI in that it can disambigurate the
provenance of uintptr_t expressions.  It differes from size_t in that
some segmented architecture (not supported by FreeBSD) may have a size_t
that does not hold an address.

ptraddr_t is not yet standardized, but is currently proposed for
inclusion in C++2Y.

Prefer the compiler defined __PTRADDR_TYPE__ defintion where available
as this a new type and we don't need to worry about historical values.
Fall back to __size_t where unavailable.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53817
2025-11-27 14:54:55 +00:00
Brooks Davis 747e8427e9 sys/syscallsubr.h: fix some whitespace
Sponsored by:	DARPA, AFRL
2025-11-21 12:13:00 +00:00
Brooks Davis 5b3368322b sys/extaddr.h: don't declare struct iovec
The code never uses it so there's no need to forward declare it.

Sponsored by:	Innovate UK
2025-11-21 12:13:00 +00:00
Brooks Davis 9e7eb261e6 arch.7: deprecate __ILP32__ and __LP64__ macros
With CHERI there now more options than __ILP32__ and __LP64__ so lack of
one does not imply the other.  Encourage the use of __SIZEOF_*__ macro
tests in their place.

Effort:		CHERI upstreaming
Reviewed by:	kib, markj, emaste
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D52820
2025-10-08 10:33:40 +01:00
Brooks Davis f7b6ea699b arch.7: correct claim about ILP32 alignment
Only i386 lays out structures with weak (4-byte) alightment.  It may be
that access works when weakly aligned, but from an ABI perspective, it's
all about struct layout.

Reviewed by:	kib, emaste
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D52818
2025-10-02 10:28:35 +01:00
Brooks Davis 0a551f8a7d arch.7: Remove mention of PDP11_ENDIAN
AFACT, this was never accurate.  When there was support (such as it was)
for PDP endian it seems to have been spelled PDP_ENDIAN.

Reviewed by:	imp, kib, emaste
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D52817
2025-10-02 10:28:35 +01:00
Brooks Davis 90d2aedbb9 bsd.cpu.mk: Fix whitespace appending to MACHINE_ABI
No functional change.

Effort:		CHERI upstreaming
Reviewed by:	imp
Fixes:		426fc376af ("bsd.cpu.mk: Introduce MACHINE_ABI")
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D52833
2025-10-02 10:28:35 +01:00
Brooks Davis 4b8eebe975 tcpdump: don't create unused version.c
The version now comes from the PACKAGE_VERSION macro.

Fixes:		0a7e5f1f02 ("tcpdump: Update to 4.99.5")
Reviewed by:	jrm, emaste
Differential Revision:	https://reviews.freebsd.org/D52334
2025-09-03 13:12:33 +01:00
Brooks Davis 9f67000141 tcpdump: drop no-op LBL_ALIGN macro
This macro was replaced by a collection of architecture ifdefs in
tcpdump 4.99.4 so defining it does nothing.

Fixes:		51a183021f ("Import tcpdump 4.99.4")
Reviewed by:	jrm, emaste
Differential Revision:	https://reviews.freebsd.org/D52333
2025-09-03 13:12:19 +01:00
Brooks Davis d376524a5d tcpdump: get BINDIR from usr.sbin/Makefile.inc [NFC]
Reviewed by:	jrm, emaste
Differential Revision:	https://reviews.freebsd.org/D52332
2025-09-03 13:12:10 +01:00
Brooks Davis 0f434b2b50 rtld: require MAP_GUARD support
MAP_GUARD was added prior to 12.0.  We don't support such old kernels in
userspace so drop the support.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D50731
2025-08-11 12:18:51 +01:00
Brooks Davis 8d26a9da0c amd64: assume the kernel supports RDFSBASE and RDGSBASE
There is no need to support pre-12.0 (and thus pre-ino64) kernels in a
15.x libc.

Continue to check if the CPU supports these features before using them
and fall back as required.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D50732
2025-08-08 18:15:21 +01:00
Brooks Davis 7988e7e167 sysent: regen to mark _exit _Noreturn 2025-08-08 10:30:17 +01:00
Brooks Davis 2a2556879b syscalls.master: mark _exit as not returning
Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D51674
2025-08-08 10:30:17 +01:00
Brooks Davis 202ac0975e sysent: add a new NORETURN type flag
System calls of type NORETURN don't return and their stubs are declare
not to.

Reviewed by:	kevans, kib
Differential Revision:	https://reviews.freebsd.org/D51673
2025-08-08 10:30:17 +01:00
Brooks Davis 8433f8cd06 sysent: regen for _exit(2) normalization 2025-08-08 10:30:16 +01:00
Brooks Davis e7e964cb2e syscalls: normalize _exit(2) declerations
exit(3) is implemented by the runtime and performs a number of shutdown
actions before ultimately calling _exit(2) to terminate the program.  We
historically named the syscall table entry `exit` rather than `_exit`,
but this requires special handling in libc/libsys to cause the `_exit`
symbol to exist while implementing `exit` in libc.

Declare the syscall as `_exit` and flow that through the system.

Because syscall(SYS_exit, code) is fairly widely used, allow a
configured extra line in syscall.h to define SYS_exit to SYS__exit.

I've found no external uses of __sys_exit() so I've not bothered to
create a compatability version of this private symbol.

Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D51672
2025-08-08 10:30:16 +01:00
Brooks Davis fd4cdc438b rtld: fix dependencies for rtld-libc
Previously we (appropriately, but incorrectly) attempted to depend on
LIBC_NOSSP_PIC and LIBSYS_PIC for rtld_libc.a.  Unfortunately,
variables in dependency lists are expanded at parse time and those
variables are defined in bsd.libnames.mk which *must* be included by
bsd.{lib,prog}.mk.  As such, they were undefined and thus expanded to
the empty string resulting in no dependency with predictable and highly
confusing results.

Move the declaration of these dependencies to after the include of
bsd.prog.mk and add comments on both side in hopes of keeping any future
dependencies in sync.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D51790
2025-08-08 10:30:16 +01:00
Brooks Davis 401d39e389 libsys: add a dependency for syscall stubs
Make syscall stubs generated by lib/libsys/Makefile.sys depend on it.
This will have some false positives, but generating and assembling them
is fast.  Also add slightly dubious dependencies on compat.h and SYS.h.

While here, fix the comment documenting the assembly origin.

Reviewed by:	kib, emaste
Differential Revision:	https://reviews.freebsd.org/D51671
2025-08-06 12:31:24 +01:00