Commit graph

9995 commits

Author SHA1 Message Date
Ed Maste
6789b9f630 libc: Fix getentropy POSIX 2024 conformance issues
GETENTROPY_MAX should be defined in limits.h.  EINVAL is the return
value for buflen > GETENTROPY_MAX.

PR:		282783
Reviewed by:	markj, asomers, jhb
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47689
2025-02-20 09:13:25 -05:00
Li-Wen Hsu
ef3ed0726f Canonicalize the name of the FreeBSD Foundation
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit dab59af3bcc7cb7ba01569d3044894b3e860ad56)
2025-02-19 09:58:47 -05:00
Mark Johnston
028323d616 setfib.2: Note that the number of FIBs can be adjusted after boot
Reviewed by:	zlei, imp
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48545

(cherry picked from commit 010ee8215f5c899e23250828402af5b7bb354328)
2025-02-07 14:46:53 +00:00
Alan Somers
3dc01440a0 Fix lib/libc/nss/getgr_test with large numbers of groups
These tests create a linked list with one entry for every group on the
running system.  On a system with about 30,000 groups, the test took 69
seconds to run, and crashed Kyua with the below error:

kyua: E: string or blob too big (sqlite op: sqlite3_bind_blob) (sqlite db: /root/.kyua/store/results.usr_tests.20241231-203317-570235.db).

Fix the test by limiting it to operating on the first 1024 groups.
Apply the same change to getpw_test and getserv_test too, which are
vulnerable to the same problem.

Sponsored by:	ConnectWise
Reviewed by:	markj
Differential Revision: https://reviews.freebsd.org/D48275

(cherry picked from commit d11904b350214943dedb64c7121d4602799d7afd)
2025-01-20 09:54:45 -07:00
Ed Maste
e2cbfa1f50 munmap.2: Remove EINVAL for negative len
len is unsigned (it is size_t), so cannot be negative.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit fab411c4fd5224e3dd44e0eb288d60b27480e2d1)
2025-01-20 09:25:14 -05:00
Ed Maste
61c5090935 munmap.2: Unaligned addresses do not return error
We previously claimed that non-page-aligned addresses would return
EINVAL, but the address is in fact rounded down to the page boundary.

Reported by:	Harald Eilertsen <haraldei@anduin.net>
Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
Fixes: dabee6fecc ("kern_descrip.c: add fdshare()/fdcopy()")
Differential Revision: https://reviews.freebsd.org/D48465

(cherry picked from commit 9e36aaf0c24cf158e83c69c1d2312c000c3c36f3)
2025-01-20 09:25:14 -05:00
Graham Percival
334e641d38 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.

(cherry picked from commit d0a3fd34a05794bc5cbf48709001a78e9f85169a)
2024-12-27 10:48:27 -05:00
John Baldwin
66cb373c8f 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

(cherry picked from commit 8277c790179304159c2e4dcb1d99552518d5be8e)
2024-12-27 10:43:26 -05:00
Graham Percival
9a15a1fef9 manuals: Misc macro typos
These were reported by `mandoc -T lint` as
    ERROR: skipping unknown macro
When these pages were rendered with `man`, the "unknown macro" meant
that the entire line was omitted from the output.

Obvious typos in:
lib/libsys/swapon.2
lib/libsys/procctl.2
share/man/man9/firmware.9

lib/libcasper/services/cap_net/cap_net.3: 'mode' describes a function
    argument.

lib/libsys/statfs.2: there's no .Tm command ("trademark?"), and
    .Tn ("tradename") is deprecated, so remove the macro entirely.

usr.sbin/mfiutil/mfiutil.8: man was interpreting '/dev/' as a macro
    (which it didn't recognize).

share/man/man4/qat.4: same issue as above, but with '0'.  In this case,
    given the context of the previous line, rewriting as "Value '0'"
    seemed more appropriate.

usr.sbin/mlx5tool/mlx5tool.8: typo in .Xr

Signed-off-by:	Graham Percival <gperciva@tarsnap.com>
Sponsored by:	Tarsnap Backup Inc.
Reviewed by:	concussious, imp
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1417

(cherry picked from commit 2878d99dfcfbdd7a415a7f31cf95fbd53fc8e581)
2024-12-27 10:40:05 -05:00
Xin LI
97cf82ebe0 Revise qsort(3) reflect POSIX.1-2024 update.
Reviewed by:	emaste, trasz
Differential Revision: https://reviews.freebsd.org/D47262

(cherry picked from commit 3df1abdfd9c309efbdc7884d6b6f6fe25efcb397)
2024-12-21 23:30:52 -08:00
Dag-Erling Smørgrav
259dcedc4a 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

(cherry picked from commit 4285e024baa80f81d13cdcc016fdf0721fe57862)
2024-12-16 10:37:08 +00:00
Ed Maste
f2c09b4f32 cap_rights_is_empty: add MLINK
Fixes: a7100ae23aca ("capsicum: introduce cap_rights_is_empty Function")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 3505e0d6675b332c154e01110456d767e222c5d6)
2024-12-06 10:50:31 -05:00
Ed Maste
25caac4d45 sched_getcpu: Add man page
Moved from libsys to libc for stable/14.

Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47556

(cherry picked from commit 36887e04947fedfebb9b648fadd0dd6cc03142ea)
2024-12-04 13:32:58 -05:00
Mark Johnston
da44138dc2 unix: Add support for atomically setting the socket mode
With this patch, it is possible to call fchmod() on a unix socket prior
to binding it to the filesystem namespace, so that the mode is set
atomically.  Without this, one has to call chmod() after bind(), leaving
a window where threads can connect to the socket with the default mode.
After bind(), fchmod() reverts to failing with EINVAL.

This interface is copied from Linux.

The behaviour of fstat() is unmodified, i.e., it continues to return the
mode as set by soo_stat().

PR:		282393
Reviewed by:	kib
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D47361

(cherry picked from commit bfd03046d18776ea70785ca1ef36dfc60822de3b)
2024-12-03 01:03:26 +00:00
Konstantin Belousov
9fb5c02356 fileno(3): set errno when returning -1
PR:	283014

(cherry picked from commit 7cd756ff4fe7e65a9a3f588904998bf6f4b37623)
2024-12-03 02:39:22 +02:00
Konstantin Belousov
fb0014d04e stdio(3): correct summary information for fileno(3)
(cherry picked from commit 35ac34a23bc0e54eb2a2314b906c6e7769dee7f0)
2024-12-03 02:39:22 +02:00
Wolfram Schneider
7efa3a6028 fhreadlink.2: fix old typo in the manpage
PR: 282967

(cherry picked from commit fb4cdd51608f3008f035d01f6a499811cda41735)
2024-11-28 14:53:17 +02:00
Konstantin Belousov
ed4b2d1594 _dl_iterate_phdr_locked(): fix libc and libdl
Add prototype.  Export from libdl.

Fixes:	1426fd6cff0603f0ee275b99f2ba35dc36f3d0c2
Reviewed by:	kevans
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 209fd89a2810419309944f10d11834321f0ebb25)
2024-11-26 19:15:56 -06:00
Kyle Evans
708106fb80 rtld: implement _dl_iterate_phdr_locked
Some sanitizers need to be able to use dl_iterate_phdr() after stopping
the rest of the process, but it's very hard to do so reliably as a
non-participant in the main logic of the program.

Introduce _dl_iterate_phdr_locked to bypass the locking that's normally
required for dl_iterate_phdr() and slap some scary warning on it.  It
will remain undocumented and probably shouldn't be used for anything
else.

Reviewed by:	kib

(cherry picked from commit 1426fd6cff0603f0ee275b99f2ba35dc36f3d0c2)
2024-11-26 19:15:56 -06:00
Ed Maste
93a321b607 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

(cherry picked from commit 95b71a659a9bdc6e9071d80c7369a935c2bc16f4)
2024-11-24 11:46:00 -05:00
R. Christian McDonald
f424c4a907 libc: enable initial-exec (IE) as default thread-local storage model on arm
As suggested by jrtc27@ in https://reviews.freebsd.org/D42415, this
patch enables IE as default thread-local storage model in libc on arm.

Reviewed by:	kib
Approved by:    kp (mentor)
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D42445

(cherry picked from commit 6e5b1ff71e01bd48172483cb6df921f84300ea3a)
2024-11-22 10:36:32 -05:00
Ed Maste
2e8ab3d4e9 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

(cherry picked from commit 566c039d1e7555343fcf6439a10e56f5a632c0fe)
2024-11-20 19:45:07 -05:00
Ed Maste
098ed26bf4 libc: indicate existing functions that are POSIX 2024
Reviewed by:	brooks, imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47581

(cherry picked from commit dfa0ac74c2fbc1cde3e8cdb1ab9fe5cbb90a9b16)
2024-11-20 19:45:07 -05:00
Ed Maste
d45fb7b612 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

(cherry picked from commit 4ef07eb0802a6353faf79d58719d8008decabae0)
2024-11-19 08:57:43 -05:00
Konstantin Belousov
a2d4e8b93e rtld_get_var.3: fix typo
(cherry picked from commit e434c56fcd4f9eee04ac6bb5e0cf028db3006be3)
2024-11-14 02:42:17 +02:00
Konstantin Belousov
cc3978cb74 Document rtld_get_var(3)
(cherry picked from commit 3820f784597cf87deb42522f108c5ee477a1f282)
2024-11-14 02:42:17 +02:00
Konstantin Belousov
86a2abab0a rtld: add rtld_{get,set}_var
(cherry picked from commit c56df6ce71ae96f00b088790d3ad2e0ebebdd59a)
2024-11-14 02:42:17 +02:00
Konstantin Belousov
37095a500d libc: remove some XXX for russian translations of errnos
(cherry picked from commit 3b65da5b65a6bfaf1150075e1dab3c627cb32f92)
2024-11-09 21:31:29 +02:00
Konstantin Belousov
27f51b8c51 libc: mechanically convert ru_RU msg catalog from KOI8-R to UTF-8
(cherry picked from commit e2864e7189781d742b6899d110b565c9744bb948)
2024-11-09 21:31:29 +02:00
Konstantin Belousov
d43c3ae472 catopen(3): align returned errors with IEEE Std 1003.1™-2024
PR:	172805

(cherry picked from commit 1176390d2d2bbb1e207c840d1f7a66a6ac1096ff)
2024-11-09 21:31:28 +02:00
Mark Johnston
da80e62f96 linker: Make linker.h more self-contained
struct kld_file_stat embeds a reference to MAXPATHLEN, defined in
param.h.

PR:		280432
MFC after:	2 weeks

(cherry picked from commit f44029e322446469f116bbd26d51ba857083bacb)
2024-11-09 01:10:14 +00:00
Mark Johnston
b698c825f3 rpc: Fix the definition of xdr_void()
xdr_void() should have type xdrproc_t, make it so.

PR:		280514
Reviewed by:	brooks, dim
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D47340

(cherry picked from commit a5d1cf5e362a2e3c3ebdf6d8f2b86658a6d0b9d6)
2024-11-05 01:05:26 +00:00
Mitchell Horne
ba036fce25 thr_kill(2): fix title
Mandoc emits a STYLE warning due to the lowercase letters.

(cherry picked from commit 23cb03d145292d7a3e6165b4ca74837d497bd3db)
2024-11-04 12:15:11 -04:00
Graham Percival
ddf4df54a7 manuals: Fix "unusual .Xr" warnings with a script
These were reported by `mandoc -T lint ...` as warnings:
- unusual Xr order
- unusual Xr punctuation

Fixes made by script in https://github.com/Tarsnap/freebsd-doc-scripts

Signed-off-by:	Graham Percival <gperciva@tarsnap.com>
Reviewed by:	mhorne, Alexander Ziaee <concussious.bugzilla@runbox.com>
Sponsored by:	Tarsnap Backup Inc.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1464

(cherry picked from commit 6e1fc0118033f42b7c0d3623c8f67a89ebecabb2)
2024-11-04 12:13:13 -04:00
Graham Percival
c0bd4ec70b manuals: Fix "missing end of block" errors
These were reported by `mandoc -T lint ...` as errors.

The rendered output (in ascii and html) is not affected by this commit.

Signed-off-by:	Graham Percival <gperciva@tarsnap.com>
Reviewed by:	mhorne
MFC after:	3 days
Sponsored by:	Tarsnap Backup Inc.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1448

(cherry picked from commit d21e322d563e0fd1f92c22205c2ced4bcd22dc23)
2024-11-04 12:07:50 -04:00
Graham Percival
3a75b41bd9 manuals: Misc syntax fixes
These were reported by `mandoc -T lint ...` as errors.

The rendered output (in ascii and html) is not affected by this commit.

Additional clarification: there was a non-breaking space in
lib/libcasper/services/cap_grp/cap_grp.3.

Signed-off-by:	Graham Percival <gperciva@tarsnap.com>
Reviewed by:	mhorne
MFC after:	3 days
Sponsored by:	Tarsnap Backup Inc.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1449

(cherry picked from commit c8b31033c3971b2b7349804ffda0cea5e4835b40)
2024-11-04 11:56:24 -04:00
Graham Percival
3609e56813 manuals: Fix errors in .2 pages
These were reported by `mandoc -T lint ...` as errors.

fhlink.2, fhreadlink.2: remove unneeded block closing.

getfh.2, procctl.2: add necessary block closing.

ptrace.2: -width only takes one argument.

swapon.2: <sys/vmparam.h> and <vm/swap_pager.h> weren't being displayed,
    because .It is for a list item whereas .In is for included files.
    Also, we want a blank line between <sys/ > headers and the other
    one.

Signed-off-by:	Graham Percival <gperciva@tarsnap.com>
PR:		281597
Reviewed by:	mhorne
Sponsored by:	Tarsnap Backup Inc.

(cherry picked from commit 650056363baddb83c61c85b0539ee536f3d4b56c)
2024-11-04 11:56:24 -04:00
Ed Maste
4fbd6e0e3c libc: fix access mode tests in fmemopen(3)
Previously a stream opened as read-only could be written to.  Add a test
case for the fix.

Also correct another incorrect access mode check that worked by
accident, and improve the tests for that.

PR:		281953
Reported by:	Erkki Moorits, fuz
Reviewed by:	fuz, khng (earlier)
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47265

(cherry picked from commit 0953460ce149e6f384aafbcb1e6213dfbf8f6a16)
(cherry picked from commit 6b9f7133aba44189d9625c352bc2c2a59baf18ef)
2024-10-29 15:11:38 -04:00
Ed Maste
45b0537f0e membarrier: Add manual page
Add a minimal membarrier man page that documents the available cmd
values and errors that can be returned.  We can add more information and
iterate on it in the tree.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46967

(cherry picked from commit 1fc766e3b41d0cdbd166ef95258434069a90ca52)
(cherry picked from commit 92cd5abb64dd70c305535c9504c6a2b73552147f)
(cherry picked from commit 8b41e693fc3956385d5771d60ee93e18001a5a0d)
2024-10-20 23:32:46 -04:00
Mark Johnston
93ff7dbaea socket: Implement SO_SPLICE
This is a feature which allows one to splice two TCP sockets together
such that data which arrives on one socket is automatically pushed into
the send buffer of the spliced socket.  This can be used to make TCP
proxying more efficient as it eliminates the need to copy data into and
out of userspace.

The interface is copied from OpenBSD, and this implementation aims to be
compatible.  Splicing is enabled by setting the SO_SPLICE socket option.
When spliced, data that arrives on the receive buffer is automatically
forwarded to the other socket.  In particular, splicing is a
unidirectional operation; to splice a socket pair in both directions,
SO_SPLICE needs to be applied to both sockets.  More concretely, when
setting the option one passes the following struct:

    struct splice {
	    int fd;
	    off_t max;
	    struct timveval idle;
    };

where "fd" refers to the socket to which the first socket is to be
spliced, and two setsockopt(SO_SPLICE) calls are required to set up a
bi-directional splice.

select(), poll() and kevent() do not return when data arrives in the
receive buffer of a spliced socket, as such data is expected to be
removed automatically once space is available in the corresponding send
buffer.  Userspace can perform I/O on spliced sockets, but it will be
unpredictably interleaved with splice I/O.

A splice can be configured to unsplice once a certain number of bytes
have been transmitted, or after a given time period.  Once unspliced,
the socket behaves normally from userspace's perspective.  The number of
bytes transmitted via the splice can be retrieved using
getsockopt(SO_SPLICE); this works after unsplicing as well, up until the
socket is closed or spliced again.  Userspace can also manually trigger
unsplicing by splicing to -1.

Splicing work is handled by dedicated threads, similar to KTLS.  A
worker thread is assigned at splice creation time.  At some point it
would be nice to have a direct dispatch mode, wherein the thread which
places data into a receive buffer is also responsible for pushing it
into the sink, but this requires tighter integration with the protocol
stack in order to avoid reentrancy problems.

Currently, sowakeup() and related functions will signal the worker
thread assigned to a spliced socket.  so_splice_xfer() does the hard
work of moving data between socket buffers.

Co-authored by:	gallatin
Reviewed by:	brooks (interface bits)
MFC after:	3 months
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D46411

(cherry picked from commit a1da7dc1cdad8c000622a7b23ff5994ccfe9cac6)
2024-10-17 15:48:36 +00:00
Konstantin Belousov
b90d68c9b2 jemalloc: set LG_VADDR to 64 on amd64
(cherry picked from commit eade2001aa9d91440886de8359a4dec9edcde2a9)
2024-10-15 18:06:44 +03:00
Konstantin Belousov
27af5dad16 getrlimitusage.2: add the man page
(cherry picked from commit 3670421e21932c44225b9457c50dd67da3abcd84)
2024-10-10 12:10:33 +03:00
Konstantin Belousov
d19c86f203 sysctl.3: document missing oids from kern.proc. node
(cherry picked from commit cdd9629921c6551abac583aeafc5c6bd380ccac2)
2024-10-10 12:10:33 +03:00
Konstantin Belousov
387094ca8a sysctl.3: document missing fixed oids from the kern. node
(cherry picked from commit 4e2803878f547f2036d8e9bde4633e0ed96bc46c)
2024-10-10 12:10:32 +03:00
Konstantin Belousov
90f2414a00 sysctl.3: Remove KERN_QUANTUM
(cherry picked from commit 2918dbc1ccd899865fc6e5854fc056800617944f)
2024-10-10 12:10:32 +03:00
Dag-Erling Smørgrav
2403e6d5aa printf(): Save errno earlier.
The manual page says %m is replaced with “the string representation of
the error code stored in the errno variable at the beginning of the
call”.  However, we don't actually save `errno` until fairly late in
`__vfprintf()`.  Make sure it is saved before we do anything that
might perturb `errno`.

MFC after:	1 week
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D46718

(cherry picked from commit 74f1007fcc838501c74a633792c3f01833bf65e1)
2024-10-06 09:12:49 +00:00
Konstantin Belousov
dac3b7e394 Userspace enablement for getrlimitusage(2)
(cherry picked from commit 9b29fc89ae20a22516f54e146bfdfa0cfcd60b8b)
2024-10-05 10:08:55 +03:00
Konstantin Belousov
d20f0dae2f getrlimit(2): document RLIMIT_PIPEBUF
(cherry picked from commit 54a8d1fbbf65e976132809718525ba051a5525cf)
2024-10-05 10:08:54 +03:00
Bjoern A. Zeeb
ff26fd77ee libc/getnameinfo: stop adding NI_NUMERICHOST where inappropriate
Checking the first nibble of the IPv6 address to be 0 and then
excluding two well known cases (v4-mapped, loopback) leaves us with
more cases where the first nibble could be 0, e.g., the RFC 6052,
2.1 Well-Known Prefix 64:ff9b::/96.
It is not practical to track them all and it is not clear what lead
to this special casing originally, so remove them.

While here also remove the IN6_IS_ADDR_LINKLOCAL() + NI_NUMERICHOST
case as link-local address resolution does exist.

We do leave the IN6_IS_ADDR_MULTICAST() case for now as I could
not find any references to any official reverse lookups for these.

Adding comments for more case (and some historic behaviour) in order
to make it easier to follow the logic.

PR:		279618
Fixes:		6cb9418289
Reviewed by:	hrs
Differential Revision: https://reviews.freebsd.org/D45547

(cherry picked from commit c179937b986ec3959d89bfeb8eed0a6f58a28649)
2024-09-28 10:35:11 +00:00
Fernando Apesteguía
ddbbc129ae faccessat(2): Honor AT_SYMLINK_NOFOLLOW
Make the system call honor `AT_SYMLINK_NOFOLLOW`.

Also enable this from `linux_faccessat2` where the issue arised the first time.
Update manual pages accordingly.

PR:			275295
Reported by:		kenrap@kennethraplee.com
Approved by:		kib@
Differential Revision:	https://reviews.freebsd.org/D46267

(cherry picked from commit 5ab6ed93cd3680f8b69dd4d05823f4740a2bdef9)
2024-09-26 09:13:50 -04:00