Commit graph

24975 commits

Author SHA1 Message Date
Olivier Certner
618c97b87b
libprocstat: ZFS support: Makefile: Tidy up a bit
Regroup assignments tweaking preprocessor defines/undefs, and separately
those about include directories.

Re-order include directories a bit more logically, and remove redundant
ones.

Separate logical groups by blank lines.

Build artifacts have been verified to stay the same when produced with
an external LLVM 18 toolchain.

MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D48070
2024-12-19 23:36:06 +01:00
Olivier Certner
b6f4027ad9
setcred(2): Add manual page
Reviewed by:    Alexander Ziaee <concussious@runbox.com>
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D48063
2024-12-19 23:36:00 +01:00
Ruslan Bukin
a7bf553d17 riscv vmm: add SSTC extension check.
Check if RISC-V SSTC is available and advertise to the guest.

This is needed for Eswin EIC7700 that does not include SSTC.

As we don't have a mechanism for reporting extension presence
from the kernel to userspace, then use vm_cap_type for now.

Reviewed by: mhorne, markj
Differential Revision: https://reviews.freebsd.org/D48058
2024-12-17 10:35:44 +00:00
Kristof Provost
aa69fdf154 pfctl: change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@

Obtained from:	OpenBSD, claudio <claudio@openbsd.org>, 0cde32ce3f
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47790
2024-12-17 11:07:13 +01:00
Kristof Provost
ebe11b4698 pf: fix state export in the face of NAT64
Now that we can NAT64 we can have states where the wire and stack address
families (and protocol) are different.  Update the state export code to account
for this.

We keep exporting address family and protocol outside of the key, for backwards
compatibility. This'll return misleading information to userspace in the NAT64
case, but it's assumed that userspace will either understand NAT64 (and thus
look for them in the correct place), or not configure it.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47787
2024-12-17 11:07:13 +01:00
Kristof Provost
e11dacbf84 pf: partially import OpenBSD's NAT rewrite
We won't follow this fully, because it involves breaking syntax changes
(removing nat/rdr rules and moving this functionality into regular rules) as
well as behaviour changes because NAT is now done after the rules evaluation,
rather than before it.

We import some related changes anyway, because it paves the way for nat64
support.
This change introduces a new pf_kpool in struct pf_krule, for nat. It is not yet
used (but will be for nat64) and renames the existing 'rpool' to 'rdr'.

Obtained from:	OpenBSD, henning <henning@openbsd.org>, 0ef3d4febe
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47783
2024-12-17 11:07:12 +01:00
Olivier Certner
ddb3eb4efe
New setcred() system call and associated MAC hooks
This new system call allows to set all necessary credentials of
a process in one go: Effective, real and saved UIDs, effective, real and
saved GIDs, supplementary groups and the MAC label.  Its advantage over
standard credential-setting system calls (such as setuid(), seteuid(),
etc.) is that it enables MAC modules, such as MAC/do, to restrict the
set of credentials some process may gain in a fine-grained manner.

Traditionally, credential changes rely on setuid binaries that call
multiple credential system calls and in a specific order (setuid() must
be last, so as to remain root for all other credential-setting calls,
which would otherwise fail with insufficient privileges).  This
piecewise approach causes the process to transiently hold credentials
that are neither the original nor the final ones.  For the kernel to
enforce that only certain transitions of credentials are allowed, either
these possibly non-compliant transient states have to disappear (by
setting all relevant attributes in one go), or the kernel must delay
setting or checking the new credentials.  Delaying setting credentials
could be done, e.g., by having some mode where the standard system calls
contribute to building new credentials but without committing them.  It
could be started and ended by a special system call.  Delaying checking
could mean that, e.g., the kernel only verifies the credentials
transition at the next non-credential-setting system call (we just
mention this possibility for completeness, but are certainly not
endorsing it).

We chose the simpler approach of a new system call, as we don't expect
the set of credentials one can set to change often.  It has the
advantages that the traditional system calls' code doesn't have to be
changed and that we can establish a special MAC protocol for it, by
having some cleanup function called just before returning (this is
a requirement for MAC/do), without disturbing the existing ones.

The mac_cred_check_setcred() hook is passed the flags received by
setcred() (including the version) and both the old and new kernel's
'struct ucred' instead of 'struct setcred' as this should simplify
evolving existing hooks as the 'struct setcred' structure evolves.  The
mac_cred_setcred_enter() and mac_cred_setcred_exit() hooks are always
called by pairs around potential calls to mac_cred_check_setcred().
They allow MAC modules to allocate/free data they may need in their
mac_cred_check_setcred() hook, as the latter is called under the current
process' lock, rendering sleepable allocations impossible.  MAC/do is
going to leverage these in a subsequent commit.  A scheme where
mac_cred_check_setcred() could return ERESTART was considered but is
incompatible with proper composition of MAC modules.

While here, add missing includes and declarations for standalone
inclusion of <sys/ucred.h> both from kernel and userspace (for the
latter, it has been working thanks to <bsm/audit.h> already including
<sys/types.h>).

Reviewed by:    brooks
Approved by:    markj (mentor)
Relnotes:       yes
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D47618
2024-12-16 15:42:39 +01:00
Olivier Certner
09290c3a0c
cred: Hide internal flag CRED_FLAG_CAPMODE
This flag is used in field 'cr_flags', which is never directly visible
outside the kernel.  That field is however exported through 'struct
kinfo_proc' objects (field 'ki_cr_flags'), either from the kernel via
sysctls or from libkvm, and is supposed to contain exported flags
prefixed with KI_CRF_ (currently, KI_CRF_CAPABILITY_MODE and
KI_CRF_GRP_OVERFLOW, this second one being a purely userland one
signaling overflow of 'ki_groups').

Make sure that KI_CRF_CAPABILITY_MODE is the flag actually exported and
tested by userland programs, and hide the internal CRED_FLAG_CAPMODE.
As both flags are currently defined to the same value, this doesn't
change the KBI, but of course does change the KPI.  A code search via
GitHub and Google fortunately doesn't reveal any outside uses for
CRED_FLAG_CAPMODE.

While here, move assignment of 'ki_uid' to a more logical place in
kvm_proclist(), and definition of XU_NGROUPS as well in 'sys/ucred.h'
(no functional/interface changes intended).

Reviewed by:    mhorne
Approved by:    markj (mentor)
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D46909
2024-12-16 15:42:29 +01:00
Kyle Evans
74ecdf86d8 Tweak ppoll() to include 1003.1-2024 visibility, take two
Note in the manpage that the 2024 edition finally added ppoll(), and
also add the appropriate declarations for the correct versions of
_POSIX_C_SOURCE (via __POSIX_VISIBLE).

Differential Revision:	https://reviews.freebsd.org/D48043
2024-12-14 22:40:16 -06:00
Kyle Evans
da5aed38d8 Revert "Tweak ppoll() to include 1003.1-2024 visibility"
This reverts commit 212d7f439a.  A last
minute change to remove __BSD_VISIBLE unearthed some breakage that I
failed to re-test.  Sigh.
2024-12-14 01:05:09 -06:00
Kyle Evans
dabf006a63 Add per-process flag to disable logsigexit
I added a third value for kern.logsigexit to mean 'auto' as an abundance
of caution, but I don't know how much it matters -- that can be easily
consolidated back to boolean-ish.

This is primarily targeted towards people running test suites under CI
(e.g. buildbot, jenkins). Oftentimes tests entail segfaults that are
expected, and logs get spammed -- this can be particularly high volume
depending on the application. Per-process control of this behavior is
desirable because they may still want to be logging legitimate
segfaults, so the system-wide atomic bomb kern.logsigexit=0 is not a
great option.

This adds a process flag to disable it, controllable via
procctl(2)/proccontrol(1); the latter knows it as "sigexitlog" due to
its length, but it's referred to almost everywhere else as
"sigexit_log."

Reviewed by:	kib (earlier version), pstef
Differential Revision:	https://reviews.freebsd.org/D21903
2024-12-13 23:18:30 -06:00
Kyle Evans
212d7f439a Tweak ppoll() to include 1003.1-2024 visibility
Note in the manpage that the 2024 edition finally added ppoll(), and
also add the appropriate declarations for the correct versions of
_POSIX_C_SOURCE.

Differential Revision:	https://reviews.freebsd.org/D48043
2024-12-13 22:15:19 -06:00
Warner Losh
7fdf597e96 jemalloc: Move generated files into lib/libc tree
Make it easire to update jemalloc by moving the FreeBSD specific files
and the generated files into lib/libc. This allows us to regenerate them
more easily, and emphasizes a bit that we may have to regenerate stuff
from upstream.

This is necessary to also unthin the import from the vendor branch as
well (which will be needed to simplify the imports in the future since
we are trying to use contrib/jemalloc for two different things).

No functional change.

Sponsored by:		Netflix
2024-12-13 16:04:39 -07:00
Warner Losh
b55f5e1c4a jemalloc: Move generated jemalloc.3 into lib/libc tree
The more generated things that are in contrib/jemalloc tree, the more
chances for interference goes way up. So, move this file into our
lib/libc tree. I didn't add a 'generated file' line / info, but this is
funky enough I don't think we need that. We do add things to the man
page, and that should be tracked in the contrib/jemalloc tree to allow
better importing experience.

Sponsored by:		Netflix
2024-12-13 15:58:31 -07:00
Brooks Davis
b9cf179622 libsys/i386/Symbol.sys.map: sort symbol names
No functional change.

Sponsored by:	DARPA, AFRL
2024-12-11 20:31:30 +00:00
Maxim Konovalov
d6917af2b9 login.conf.5: remove a stray quote
PR:	282858
2024-12-11 18:23:22 +00:00
Xin LI
26743408e9 MFV: xz 5.6.3
MFC after:	2 weeks
2024-12-09 07:20:04 -08:00
Dag-Erling Smørgrav
4285e024ba strptime: Fix day-of-week calculation.
The day-of-week calculation used the raw year value without adjusting
for TM_YEAR_BASE, so it was off by one for 300 years out of every 400;
it just happened to be correct for 1901 through 2000.  It also used a
loop where a simple addition would have sufficed.

While here, simplify our version of Gauss's algorithm, and document
that we assume the Gregorian calendar.

MFC after:	1 week
PR:		282916
Reviewed by:	imp, allanjude, philip
Differential Revision:	https://reviews.freebsd.org/D47977
2024-12-09 13:38:22 +01:00
Xin LI
908f215e80 MFV: expat 2.6.4.
MFC after:      2 weeks
2024-12-08 20:25:01 -08:00
Xin LI
7277ee2465 Vendor import of expat 2.6.4. 2024-12-08 11:17:41 -08:00
Maxim Sobolev
1e99be5dcd libc: lib_malloc_aligned(): add a missing NULL check
For some reason return value of the __je_bootstrap_malloc()
is not checked and then de-referenced few lines below, causing
a SEGV if an early allocation fails.

MFC after:      1 month
2024-12-08 11:14:36 -08:00
Xin LI
ae316d1d1c MFV: file 5.46.
MFC after:	2 weeks
2024-12-08 11:08:17 -08:00
Graham Percival
d0a3fd34a0 fgets.3: document gets_s() __STDC_WANT_LIB_EXT1__
This matches the man page for qsort_s().

PR:		281828
Signed-off-by:	Graham Percival <gperciva@tarsnap.com>
Sponsored by:	Tarsnap Backup Inc.
2024-12-06 13:20:19 -05:00
Dimitry Andric
71ac745d76 Merge llvm-project release/19.x llvmorg-19.1.5-0-gab4b5a2db582
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and
openmp to llvm-project release/19.x llvmorg-19.1.5-0-gab4b5a2db582,
a.k.a. 19.1.5 release.

PR:		280562
MFC after:	3 days
2024-12-06 18:29:48 +01:00
John Baldwin
8277c79017 procctl.2: Editing pass
- Add some missing .Pp macros after the end of literal blocks and some
  lists to ensure there is a blank line before the following text.

- Use an indent of Ds for nested lists to reduce excessive indentation and
  make the bodies of the nested list items easier to read.

- Various and sundry rewordings and clarifications.

Reviewed by:	kib, emaste
Differential Revision:	https://reviews.freebsd.org/D47782
2024-12-04 09:11:56 -05:00
Ed Maste
3505e0d667 cap_rights_is_empty: add MLINK
Fixes: a7100ae23a ("capsicum: introduce cap_rights_is_empty Function")
Sponsored by: The FreeBSD Foundation
2024-12-02 15:35:40 -05:00
Robert Clausecker
1730b5c791 lib/libc/tests: add unit test for arc4random_uniform()
The new unit test validates that the range reduction works correctly.
We do not currently validate that there is no bias as that would take
too much time and memory for a unit test.

Reviewed by:	cem
Approved by:	emaste
Differential Revision:	https://reviews.freebsd.org/D47659
2024-12-02 11:41:11 +01:00
Robert Clausecker
127709d30a lib/libc/gen: use Lemire's algorithm for arc4random_uniform().
Daniel Lemire has published a more efficient range reduction algorithm
for finding a random number in a given range without bias, reducing the
number of divisions to none in the common case and 1 in case the initial
sample is rejected.

This speeds up performance by 22% on amd64, 15% on i386, and 70% on armv7.

os: FreeBSD
arch: amd64
cpu: Intel(R) Core(TM) i7-4910MQ CPU @ 2.90GHz
                   │ benchmark.out │
                   │    sec/op     │
Arc4random_uniform     56.53n ± 0%
Fast_uniform           44.00n ± 0%
geomean                49.87n

Reviewed by:	cem
Approved by:	emaste
Differential Revision:	https://reviews.freebsd.org/D47659
2024-12-02 11:41:11 +01:00
Enji Cooper
991bd46162 lib/libsbuf/tests: reformat with clang-format
This change is being done first so any functional changes from the tests
will be clearer to reviewers.

No functional change intended.

MFC after:	2 weeks
Ref:	 https://reviews.freebsd.org/D47826
2024-12-01 20:39:52 -08:00
Ahmad Khalifa
d4f9e32639 libc/stdio: Increase BUF in vfprintf.c and vfwprintf.c
With the %b format specifier we need enough space to write a uintmax_t
in binary.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1400
2024-11-29 14:38:36 -07:00
Konstantin Belousov
7cd756ff4f fileno(3): set errno when returning -1
as required by IEEE Std 1003.1™-2024.

PR:	283014
Reported by:	Graham Percival <gperciva@tarsnap.com>
Reviewed by:	emaste, imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D47834
2024-11-29 17:25:32 +02:00
Konstantin Belousov
35ac34a23b stdio(3): correct summary information for fileno(3)
Reviewed by:	emaste, imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D47834
2024-11-29 17:25:31 +02:00
Edward Tomasz Napierala
60f87c7368 Regen 2024-11-29 12:10:45 +00:00
Edward Tomasz Napierala
b165e9e3ea Add fchroot(2)
This is similar to chroot(2), but takes a file descriptor instead
of path.  Same syscall exists in NetBSD and Solaris.  It is part of a larger
patch to make absolute pathnames usable in Capsicum mode, but should
be useful in other contexts too.

Reviewed By:	brooks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D41564
2024-11-29 12:10:02 +00:00
Wolfram Schneider
fb4cdd5160 fhreadlink.2: fix old typo in the manpage
PR: 282967
Approved by: kib
2024-11-25 18:38:20 +00:00
Kevin Bowling
c1e304c60c setsockopt.2: Clarify SO_SPLICE action
Reviewed by:	gallatin, markj
MFC after:	3 days
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D47720
Co-authored-by:	Mark Johnston <markj@FreeBSD.org>
2024-11-25 11:36:00 -07:00
Wolfram Schneider
aebac84982 manpage: cross link fhreadlink(2) <-> readlink(2) 2024-11-25 09:02:34 +00:00
Ed Maste
6643965998 getentropy: restore unistd.h include
It is needed for SSP support.

Reported by: netchild, Shawn Webb
Fixes: 62dab3d016 ("getentropy: Remove fallback code")
Sponsored by: The FreeBSD Foundation
2024-11-22 13:08:41 -05:00
David Gilbert
169e23d41f hexdump.3: Add missing LIBRARY section
All the other libutil section 3 manpages document this, and although
it's heavily implied by the libutil.h header in the synopsis, we should
still be explicit and consistent.

PR:		280078
Reviewed by:	jrtc27
MFC after:	1 week
2024-11-21 20:23:16 +00:00
Dimitry Andric
415efcecd8 Merge llvm-project release/19.x llvmorg-19.1.4-0-gaadaa00de76e
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and
openmp to llvm-project release/19.x llvmorg-19.1.4-0-gaadaa00de76e,
a.k.a. 19.1.4 release.

PR:		280562
MFC after:	1 month
2024-11-21 18:46:18 +01:00
Ed Maste
95b71a659a libc: Note that getentropy is nearly POSIX 2024
Our implementation currently diverges from POSIX 2024 in a couple of
ways, as now noted in the BUGS section.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47589
2024-11-20 14:30:34 -05:00
Ed Maste
5cc53d7965 memcmp.3: Clarify return value
The return value is not required to be the difference between the
differing bytes, only less than zero, zero, or greater than zero.

Reviewed by:	fuz
Event:		Kitchener-Waterloo Hackathon 202406
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47683
2024-11-20 12:15:11 -05:00
Ed Maste
62dab3d016 getentropy: Remove fallback code
We don't in general support running newer libc on an older kernel, but
have occasionally added support for specific functionality on a case-by-
case basis.  When we do this it is usually done as an aid for developers
to get across a change that introduced new functionality, as for 64-bit
inodes and the introduction of the getrandom syscall.

The getrandom syscall was added in commit e9ac27430c ("Implement
getrandom(2) and getentropy(3)") in 2018, and exists in all supported
FreeBSD versions.  The ECAPMODE special case applied to a few months
worth of kernel versions also in 2018 -- fixed as of commit ed1fa01ac4
("Regen after r337998.").

The backwards-compatibility support is no longer needed, so remove it.

Relnotes:	Yes
Reviewed by:	brooks, cem, delphij
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47636
2024-11-19 21:29:46 -05:00
Graham Percival
10343013a4 manuals: Fix some .Bl -tag lists
Signed-off-by:	Graham Percival <gperciva@tarsnap.com>
Reviewed by:	mhorne, Alexander Ziaee <concussious.bugzilla@runbox.com>
MFC after:	3 days
Sponsored by:	Tarsnap Backup Inc.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1528
2024-11-18 13:30:40 -04:00
Ed Maste
4ef07eb080 getentropy: Add Git hashes corresponding to SVN references
getentropy has a comment about a special case to support kernels between
SVN revisions r331280 and r337999.  Add the corresponding Git hashes so
there's a usable reference after Subversion infrastructure disappears.

Sponsored by:	The FreeBSD Foundation
2024-11-16 10:22:46 -05:00
Ed Maste
566c039d1e fork: Document _Fork (and fork) as POSIX 2024
Also remove some information from HISTORY that is no longer needed (and
could be confusing), now that _Fork is part of a standard.

Reported by:	kib
Reviewed by:	imp, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47588
2024-11-15 23:05:40 -05:00
Ed Maste
dfa0ac74c2 libc: indicate existing functions that are POSIX 2024
Reviewed by:	brooks, imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47581
2024-11-14 21:32:20 -05:00
Robert Clausecker
8983acc8de lib/libc/string: apply SSP hardening and tests to memset_explicit
Reviewed by:	emaste, kevans
Differential Revision:	https://reviews.freebsd.org/D47286
2024-11-14 23:10:00 +01:00
Robert Clausecker
007871c356 lib/libc/string: add memset_explicit() for compliance with C23
Patterned after explicit_bzero, visible from C23 onwards.

Reviewed by:	emaste, kevans
Differential Revision:	https://reviews.freebsd.org/D47286
2024-11-14 23:10:00 +01:00
Graham Percival
bc919e81e0 man: Misc syntax fixes
- loader.efi.8: use proper way of printing a backslash.
- usr.bin/gzip/gzip.1: contained a non-breaking space (in utf-8, 0xC2A0).
- lib/libpmc/pmc.*.3: remove two duplicate .Xr lines

Signed-off-by:	Graham Percival <gperciva@tarsnap.com>
Reviewed by:	mhorne, Alexander Ziaee <concussious.bugzilla@runbox.com>
MFC after:	3 days
Sponsored by:	Tarsnap Backup Inc.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1523
2024-11-14 16:59:22 -04:00