Commit graph

1968 commits

Author SHA1 Message Date
Gleb Smirnoff
c62ae124cc rpc: limited multithread support for svc_nl
The rpc(3) itself was not designed with multithreading in mind, but we can
actually achieve some parallelism without modifying the library and the
framework.  This transport will allow to process RPCs in threads, with
some hacks on the application side (documented in code).  We make
reentrable only one method - SVC_REPLY().  Reading and parsing of incoming
calls is still done synchronously.  But the actual processing of the calls
can be offloaded to a thread, and once finished the thread can safely
execute svc_sendreply() and the reply would be sent with the correct xid.

Differential Revision:	https://reviews.freebsd.org/D48569
2025-02-01 01:00:28 -08:00
Gleb Smirnoff
c5d671b711 libc/rpc: add userland side RPC server over netlink(4)
To be used by NFS related daemons that provide RPC services to the kernel.
Some implementation details inside the new svc_nl.c.

Reviewed by:		rmacklem
Differential Revision:	https://reviews.freebsd.org/D48550
2025-02-01 01:00:25 -08:00
Gleb Smirnoff
fa1b961259 krpc: add kernel side client over netlink(4)
This shall be the official transport to connect kernel side RPC clients
to userland side RPC servers.  All current kernel side clients that
hijack unix(4) sockets will be converted to it.  Some implementation
details are available inside new clnt_nl.c.

The complementary RPC server over netlink(4) coming in next commit.

Reviewed by:		rmacklem
Differential Revision:	https://reviews.freebsd.org/D48549
2025-02-01 01:00:25 -08:00
Ed Maste
473681a1a5 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-01-17 13:23:23 -05:00
Kyle Evans
712f81feea include: add a userland version of __assert_unreachable
The kernel has had a version of this since
c79cee7136 ("kernel: provide panicky version of __unreachable"), and
userland can benefit from the same.  __unreachable is largely
inadequate because it's *not* an assertion of any sort, so we're not
really alerted to a problem that we could've anticipated.

Reviewed by:	emaste, imp, jhb, olce
Differential Revision:	https://reviews.freebsd.org/D48077
2025-01-12 18:41:37 -06:00
Alexander Motin
e6c96c7af7 Revert "isp: Fix abort issue introduced by previous commit"
This reverts commit 1f7c379c07.

Leaked unintended changes.  I'm sorry.
2025-01-08 13:20:09 -05:00
Alexander Motin
1f7c379c07 isp: Fix abort issue introduced by previous commit
Aborting ATIO while its CTIOs are in progress makes impossible to
handle their completions, making them stuck forever.  Detect this
case by checking ctcnt counter and if so instead of aborting just
mark the ATIO as dead to block any new CTIOs.  It is not perfect
since the task id can not be reused for some more time, but not
as bad as the task stuck forever.

MFC after:	1 week
2025-01-08 13:04:34 -05:00
Warner Losh
6553c31c96 endian.h: Update comments now that POSIX Issue 8 is POSIX.1-2024
Now that Issue 8 has been published, replace the informal Issue 8
language with the more typical POSIX.1-xxxx citation.

Sponsored by:		Netflix
2024-12-30 13:38:39 -07:00
Mark Johnston
9ba7351fcf ssp: Make ssp.h more self-contained
Include a header to provide __size_t.

Fixes:	c10d567ea0 ("include: de-macro __ssp_overlap(), improve semantics and checking")
PR:		283653
Reviewed by:	kevans, imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D48226
2024-12-29 17:57:46 +00: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
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
Stephen Hurd
59677aecb6 Expose POSIX functions incorporated into C23
C23 has incoporated a small number of POSIX functions, so these
should be exposed for C23, regardless of POSIX.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D47856
2024-12-01 10:34:40 -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
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
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
Mark Johnston
5af09f50d7 include: Add required guards for dev/vmm headers
Reported by:	Jenkins
Fixes:		ebd48f1e52 ("include: Install dev/vmm headers")
2024-11-05 04:23:49 +00:00
Mark Johnston
ebd48f1e52 include: Install dev/vmm headers
In preparation for their use in libvmmapi.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D47029
2024-11-05 01:40:41 +00:00
Mark Johnston
a5d1cf5e36 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
2024-10-30 19:27:18 +00:00
Simon J. Gerraty
a64729f507 Update Makefile.depend files
After building packages we have a number of new
and updated Makefile.depend files

Reviewed by:	stevek
2024-10-14 10:26:17 -07:00
Kirk McKusick
5b21d4ad06 Ensure that soft updates are not enabled by default when using mdmfs(8)
When soft updates began being enabled by default that change carried
over to mdmfs(8) which does not want or need them. This fix ensures
that they are only enabled in mdmfs(8) when requested with the -U flag.

Reported by: Ivan Rozhuk
Tested by:   Ivan Rozhuk
PR:          279308
MFC after:   1 week
2024-10-03 08:06:28 -07:00
Graham Percival
eb84c129d6 stdio.h: don't expose rsize_t unless __EXT1_VISIBLE
This is how the other typedefs for rsize_t handle it (in <stddef.h>,
<stdlib.h>, and <string.h>).  In particular, we shouldn't have any
rsize_t if a C environment earlier C11 was requested.

This reapplies b35f0aa495, chasing c25e55bcf8, fixing ports build
failures following b35f0aa495 without c25e55bcf8.

PR:		281768
Sponsored by:	Tarsnap Backup Inc.
Signed-off-by:	Graham Percival
2024-10-02 11:01:39 -07:00
Kyle Evans
c25e55bcf8 include: ssp: hide gets_s behind __EXT1_VISIBLE
These were supposed to match the visibility of the system's declaration,
but this one was overlooked.  Fix it now so that `rsize_t` can be hidden
appropriately.

Reported by:	Shawn Webb (and now others)
2024-10-02 12:47:55 -05:00
Cy Schubert
fe55d62ab9 Revert "stdio.h: don't expose rsize_t unless __EXT1_VISIBLE"
This change has caused a number of port build failures. Let's
revert this for now and request an exp-run.

This reverts commit b35f0aa495.
2024-10-02 08:51:56 -07:00
Graham Percival
b35f0aa495 stdio.h: don't expose rsize_t unless __EXT1_VISIBLE
PR:		281768
Fixes:		c13559d31e
MFC after:	1 week
2024-09-30 20:07:43 -07:00
Stefan Eßer
12e0d31664 vendor/bc: upgrade to version 7.0.0
This is a production release to fix three bugs, none of which
affects well formed scripts on FreeBSD:

The first bug is that bc/dc will exit on macOS when the terminal
is resized.

The second bug is that an array, which should only be a function
parameter, was accepted as part of larger expressions.

The third bug is that the value stack for dc was cleared on any error.
However, this is not how other dc behave. To bring dc more in line
with other implementations, this behavior was changed. This change is
why this version is a new major version.

(cherry picked from commit 54d20d67e2af28d948ce2df13feb039fa10900fc)

MFC after:	3 days
2024-08-26 18:27:29 +02:00
Kyle Evans
de866aa352 ssp: switch to _limits.h for the upper bound of size_t
The definitions in _stdint.h has some complications around visibility
that _limits.h does not have.  Switch to __SIZE_T_MAX to avoid those.

This fixes the devel/gperf, devel/glib20 and math/mpfr builds with
_FORTIFY_SOURCE enabled to unlock a large fraction of the ports tree to
build.

Reported by:	Shawn Webb (HardenedBSD)
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
2024-08-01 15:42:17 -05:00
Kyle Evans
9333e1cbd0 include: ssp: hide ppoll redirect behind __BSD_VISIBLE
This mirrors ppoll's visibility in sys/poll.h and fixes a build issue
with some _POSIX_C_SOURCE requests due to missing the sigset_t typedef.

Reported by:	eduardo
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
2024-07-30 11:36:58 -05:00
Ed Maste
5c2bc3db20 Remove "All Rights Reserved" from FreeBSD Foundation copyrights
These ones were unambiguous cases where the Foundation was the only
listed copyright holder.

Sponsored by:	The FreeBSD Foundation
2024-07-30 12:16:36 -04:00
Kyle Evans
9a3f7fb46c include: ssp: fix last bare inline
This was missed in b8730c11a3 ("include: ssp: fix the build [...]"),
but <ssp/wchar.h> also had a bare `inline` in use.  Swap it over to
__ssp_inline as well.

Reported by:	netchild
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
2024-07-20 23:17:55 -05:00
Kyle Evans
0c47b9c211 include: ssp: don't shadow the mempcpy builtin
GCC emits a warning about shadowing a builtin with our mempcpy
declaration, so switch it to using the same model as memcpy() and
use the apparently-existing __builtin___mempcpy_chk().

Reviewed by:	kib (earlier version), markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45976
2024-07-16 00:12:28 -05:00
Kyle Evans
b8730c11a3 include: ssp: fix the build with earlier C standards
`inline` isn't always a keyword, so we should be using __ssp_inline
as we do everywhere else in the _FORTIFY_SOURCE support.  Variable
declarations in a loop initializer are also not always supported, so
declare any loop vars in advance.

Reviewed by:	kib (earlier version), markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45976
2024-07-16 00:12:27 -05:00
Warner Losh
e9ac41698b Remove residual blank line at start of Makefile
This is a residual of the $FreeBSD$ removal.

MFC After: 3 days (though I'll just run the command on the branches)
Sponsored by: Netflix
2024-07-15 16:43:39 -06:00
Kyle Evans
1f155d48f8 include: ssp: fortify <sys/socket.h>
The entire recv*() implementation set is ripe for opportunities to
validate, so do what we can with what we have.

Reviewed by:	markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45686
2024-07-13 00:16:26 -05:00
Kyle Evans
1ace24b30c include: ssp: fortify <sys/uio.h>
Check both the buffer size of the iov object itself, as well as that
of each indidvidually io base.

Reviewed by:	markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45684
2024-07-13 00:16:25 -05:00
Kyle Evans
062d9380b9 include: ssp: fortify <sys/random.h>
That is to say, fortify getrandom(2).

Reviewed by:	markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45683
2024-07-13 00:16:25 -05:00
Kyle Evans
b53d7aa88f include: ssp: fortify <wchar.h>
This includes all of the w*() equivalents to str*()/mem*() implemented
in more or less the same way.  For these ones, we'll just use
header-only implementations from the start to stop further cluttering
the libc symbol table.

Reviewed by:	markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45682
2024-07-13 00:16:25 -05:00
Kyle Evans
d0b7445904 include: ssp: fortify <stdlib.h>
The immediately obvious and attractive targets from <stdlib.h> are
arc4random_buf(3) and realpath(3) -- scraping the header didn't reveal
much else of interest.

Reviewed by:	markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45681
2024-07-13 00:16:24 -05:00
Kyle Evans
88276dfbf1 include: ssp: fortify poll/ppoll from <poll.h>
For poll/ppoll we just need to bounds-check the poll array that we're
about to write out to.

Reviewed by:	kib, markj (earlier version)
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45680
2024-07-13 00:16:24 -05:00
Kyle Evans
cf8e5289a1 include: ssp: round out fortification of current set of headers
ssp/ssp.h needed some improvements:
 - `len` isn't always a size_t, it may need casted
 - In some cases we may want to use a len that isn't specified as a
    parameter (e.g., L_ctermid), so __ssp_redirect() should be more
    flexible.
 - In other cases we may want additional checking, so pull all of the
    declaration bits out of __ssp_redirect_raw() so that some functions
    can implement the body themselves.

strlcat/strlcpy should be the last of the fortified functions that get
their own __*_chk symbols, and these cases are only done to be
consistent with the rest of the str*() set.

Reviewed by:	markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45679
2024-07-13 00:16:24 -05:00
Kyle Evans
c10d567ea0 include: de-macro __ssp_overlap(), improve semantics and checking
Switch away from pointer arithmetic to provide more obvious semantics
for checking overlap on pointer ranges.  This lets us remove some casts
that need not exist and removes some possible fragility in its use.

While we're here, check for overflow just in case; sometimes we use a
caller-supplied size if __builtin_object_size(3) can't deduce the buffer
size, and we should fail the check if the size is nonsensical for the
provided buffers.

Reviewed by:	markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
2024-07-13 00:16:23 -05:00
Kyle Evans
4719366192 libc: move __ssp_overlap back out into <ssp/ssp.h>
We'll be using it in some upcoming definitions in headers, so move it
back now but slap a warning on it.  Our upcoming uses will all be inside
of inline functions, so we're not overly concerned about double
evaluation immediately.

Reviewed by:	markj
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D45677
2024-07-13 00:16:23 -05:00
Warner Losh
4a86b26b84 stdlib: Support compiling with tinyc by omitting compat qsort code
TinyC doesn't support the .symver assembler directive. Add a generic way
to signal this and use that not to define __sym_() macros that use
it. Only use the __sym_* macros in headers when they are defined (which
currently is only for the qsort_r compat code. Not supporting this for
tcc is fine: It's an edge case for legacy binaries / code anyway which
isn't relevant to tinyc.

Sponsored by:		Netflix
Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D45651
2024-06-21 09:53:07 -06:00
Brooks Davis
39c4f65c72 stddef.h/stdlib.h: Remove unused rune_t
This non-standard type is unused in the base system (__ct_rune_t or
__rune_t are used instead) and ports.  It has been around as long as our
current source repo, but we have avoided using it.  In sys/_types.h
where the __*rune_t typedefs are defined, the following appears in a
comment:

    NOTE: rune_t is not covered by ANSI nor other standards, and should
    not be instantiated outside of lib/libc/locale.  Use wchar_t.

The definition of this unused type meant we gratutiously differed from
standards compliant stddef.h/stdlib.h.

PR:		279357 (exp-run by antoine)

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D45426
2024-06-02 19:41:22 +01:00
Kyle Evans
5af6fbd727 ssp: appease -Wgnu-statement-expression-from-macro-expansion
It's a stupid warning, but some ports enable it by default and were
already defining _FORTIFY_SOURCE, thus exposing the new macros
immediately.  This at least fixes the libfido2 build, perhaps others as
well.

While we're here, fix a fresh build of stand w/ FORTIFY_SOURCE enabled
by not pulling in the ssp headers if _STANDALONE is defined.  We do not
have runtime support in libsa as of the time of writing.

Reported by:	netchild
Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
2024-05-14 18:22:18 -05:00
Kyle Evans
0ed58ac88a include: ssp: kill off leftover $FreeBSD$ tag
Most of these were fixed when rebasing the patch forward, but this one
seems to have been missed.

Reported by:	marck
Fixes:	be04fec426 ("Import _FORTIFY_SOURCE implementation [...]")
2024-05-13 17:45:55 -05:00
Kyle Evans
8b0682644e Fix the GCC build after _FORTIFY_SOURCE import
We haven't exposed gets(3) in a long time, rip out __gets_chk before
it's too late and something builds a gets(3) user with it enabled.
2024-05-13 11:21:38 -05:00
Kyle Evans
9bfd3b4076 Add a build knob for _FORTIFY_SOURCE
In the future, we will Default to _FORTIFY_SOURCE=2 if SSP is enabled,
otherwise default to _FORTIFY_SOURCE=0.  For now we default it to 0
unconditionally to ease bisect across older versions without the new
symbols, and we'll put out a call for testing.

include/*.h include their ssp/*.h equivalents as needed based on the
knob. Programs and users are allowed to override FORTIFY_SOURCE in their
Makefiles or src.conf/make.conf to force it off.

Reviewed by:	des, markj
Relnotes:	yes
Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D32308
2024-05-13 00:23:50 -05:00
Kyle Evans
e55512504d Prepare the system for _FORTIFY_SOURCE
Notably:
- libc needs to #undef some of the macros from ssp/* for underlying
  implementations
- ssp/* wants a __RENAME() macro (snatched more or less from NetBSD)

There's some extra hinkiness included for read(), since libc spells it
as "_read" while the rest of the world spells it "read."

Reviewed by:	imp, ngie
Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D32307
2024-05-13 00:23:50 -05:00