]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
9 months agolinux(4): Regen for linux_nosys change
Dmitry Chagin [Tue, 3 Oct 2023 07:38:03 +0000 (10:38 +0300)]
linux(4): Regen for linux_nosys change

MFC after: 1 week

9 months agolinux(4): Deorbit linux_nosys from syscalls.master
Dmitry Chagin [Tue, 3 Oct 2023 07:38:02 +0000 (10:38 +0300)]
linux(4): Deorbit linux_nosys from syscalls.master

Differential Revision: https://reviews.freebsd.org/D41902
MFC after: 1 week

9 months agotests: Test that SIGSYS is not delivered if kern.signosys knob is off
Dmitry Chagin [Tue, 3 Oct 2023 07:38:02 +0000 (10:38 +0300)]
tests: Test that SIGSYS is not delivered if kern.signosys knob is off

Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D41979
MFC after: 1 week

9 months agolibfetch: don't rely on ca_root_nss for certificate validation
Michael Osipov [Tue, 3 Oct 2023 05:53:20 +0000 (07:53 +0200)]
libfetch: don't rely on ca_root_nss for certificate validation

Before certctl(8), there was no system trust store, and libfetch
relied on the CA certificate bundle from the ca_root_nss port to
verify peers.

We now have a system trust store and a reliable mechanism for
manipulating it (to explicitly add, remove, or revoke certificates),
but if ca_root_nss is installed, libfetch will still prefer that to
the system trust store.

With this change, unless explicitly overridden, libfetch will rely on
OpenSSL to pick up the default system trust store.

PR: 256902
MFC after: 3 days
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D42059

9 months agoSIGSYS: add tests
Konstantin Belousov [Mon, 25 Sep 2023 18:40:28 +0000 (21:40 +0300)]
SIGSYS: add tests

Reviewed by: dchagin, markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D41976

9 months agolinuxolator: fix nosys() to not send SIGSYS
Konstantin Belousov [Mon, 25 Sep 2023 16:39:48 +0000 (19:39 +0300)]
linuxolator: fix nosys() to not send SIGSYS

Reviewed by: dchagin, markj
Discussed with: jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D41976

9 months agonosys(): add kern.signosys tunable/sysctl to control SIGSYS
Konstantin Belousov [Mon, 25 Sep 2023 16:36:04 +0000 (19:36 +0300)]
nosys(): add kern.signosys tunable/sysctl to control SIGSYS

Reviewed by: dchagin, markj
Discussed with: jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D41976

9 months agosysentvec: add SV_SIGSYS flag
Konstantin Belousov [Mon, 25 Sep 2023 16:33:36 +0000 (19:33 +0300)]
sysentvec: add SV_SIGSYS flag

to allow ABIs to indicate that SIGSYS is needed.  Mark all native
FreeBSD ABIs with the flag.

This implicitly marks Linux' ABIs as not delivering SIGSYS on invalid
syscall.

Reviewed by: dchagin, markj
Discussed with: jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D41976

9 months agosyscalls: fix missing SIGSYS for several ENOSYS errors
Konstantin Belousov [Mon, 25 Sep 2023 16:32:52 +0000 (19:32 +0300)]
syscalls: fix missing SIGSYS for several ENOSYS errors

In particular, when the syscall number is too large, or when syscall is
dynamic.  For that, add nosys_sysent structure to pass fake sysent to
syscall top code.

Reviewed by: dchagin, markj
Discussed with: jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D41976

9 months agoamd64 cpu_fetch_syscall_args_fallback(): fix whitespace
Konstantin Belousov [Tue, 26 Sep 2023 09:20:30 +0000 (12:20 +0300)]
amd64 cpu_fetch_syscall_args_fallback(): fix whitespace

Reviewed by: dchagin, markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D41976

9 months agolibprocstat: style: space after switch
Brooks Davis [Mon, 2 Oct 2023 21:50:00 +0000 (22:50 +0100)]
libprocstat: style: space after switch

Style demands a space after the switch keyword.

Noticed reviewing code in CheriBSD that propagated the style bug.

Reported by: markj
Sponsored by: DARPA
Reviewed by: kib, markj
Differential Revision: https://reviews.freebsd.org/D42041

9 months agogeli tests: Use shorter passphrases in setkey_passphrase
Mark Johnston [Mon, 2 Oct 2023 20:55:26 +0000 (16:55 -0400)]
geli tests: Use shorter passphrases in setkey_passphrase

There is an undocumented limit on the length of a GELI passphrase, and
the test exceeded that.  Most of the time it worked because a nul
terminator would appear early enough in the string.

Reported by: Jenkins
Fixes: 2b7b09ac9675 ("geli tests: Add a regression test for geli setkey -J")

9 months agologin_cap.c: Don't set errno to ERANGE on memory allocation failure
Olivier Certner [Thu, 25 May 2023 11:48:40 +0000 (13:48 +0200)]
login_cap.c: Don't set errno to ERANGE on memory allocation failure

Modified functions: login_getcaptime(), login_getcapnum(),
login_getcapsize().

They all call cgetstr(), which returns -2 on such conditions and already
sets errno to ENOMEM, arguably the appropriate value for these functions
as well.

No in-tree consumer currently checks for errno on error reported by
these functions, so this change has no other code impact.

Reviewed by:            kib
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40342

9 months agosetusercontext(): Fix gap when setting a realtime-class priority
Olivier Certner [Thu, 25 May 2023 07:10:27 +0000 (09:10 +0200)]
setusercontext(): Fix gap when setting a realtime-class priority

The login.conf's "priority" capability allows to set priorities in the
idle or realtime classes in addition to the classical nice values (-20
to 20), through a natural extension where values greater than 20 put the
processes in the idle class (with priority adjusted within RTP_PRIO_MIN
and RTP_PRIO_MAX, 21 being converted to 0, 22 to 1, etc.) and values
lower than -20 put the process in the realtime class (with priority
adjusted within RTP_PRIO_MIN and RTP_PRIO_MAX, -21 being converted to
RTP_PRIO_MAX (31), -22 to 30, etc.).

Before this fix, in the latter case (realtime class), -21 was converted
to 30, and RTP_PRIO_MAX (31) could never be specified.

While here, change the priority computation for the idle-class case to
be symmetrical and use RTP_PRIO_MIN (in practice, this changes nothing
at all, since RTP_PRIO_MIN is 0; but this is the correct theoretical
formula, which would work as well with other values of RTP_PRIO_MIN).

PR:                     271727
Reviewed by:            imp, kib
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40339

9 months agox86: AMD Zen2: Zenbleed chicken bit mitigation
Olivier Certner [Mon, 11 Sep 2023 14:18:30 +0000 (16:18 +0200)]
x86: AMD Zen2: Zenbleed chicken bit mitigation

Applies only to bare-metal Zen2 processors.  The system currently
automatically applies it to all of them.

Tunable/sysctl 'machdep.mitigations.zenbleed.enable' can be used to
forcibly enable or disable the mitigation at boot or run-time.  Possible
values are:

    0: Mitigation disabled
    1: Mitigation enabled
    2: Run the automatic determination.

Currently, value 2 is the default and has identical effect as value 1.
This might change in the future if we choose to take into account
microcode revisions in the automatic determination process.

The tunable/sysctl value is simply ignored on non-applicable CPU models,
which is useful to apply the same configuration on a set of machines
that do not all have Zen2 processors.  Trying to set it to any integer
value not listed above is silently equivalent to setting it to value 2
(automatic determination).

The current mitigation state can be queried through sysctl
'machdep.mitigations.zenbleed.state', which returns "Not applicable",
"Mitigation enabled" or "Mitigation disabled".  Note that this state is
not guaranteed to be accurate in case of intervening modifications of
the corresponding chicken bit directly via cpuctl(4) (this includes the
cpucontrol(8) utility).  Resetting the desired policy through
'machdep.mitigations.zenbleed.enable' (possibly to its current value)
will reset the hardware state and ensure that the reported state is
again coherent with it.

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

9 months agolib/libc/tests/string: expand memcmp test to bcmp, timingsafe_{b,mem}cmp
Robert Clausecker [Wed, 30 Aug 2023 15:30:24 +0000 (15:30 +0000)]
lib/libc/tests/string: expand memcmp test to bcmp, timingsafe_{b,mem}cmp

The four functions more or less perform the same operation.
Reuse the same unit test with slight changes so we can cover
them all.  Constant-time operation is not verified for the
timingsafe_* functions.

Sponsored by: The FreeBSD Foundation
Approved by: ngie
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D41528

9 months agolib/libc/tests/string/memcmp_test.c: extend test to support custom memcmp function
Robert Clausecker [Fri, 14 Jul 2023 11:56:12 +0000 (11:56 +0000)]
lib/libc/tests/string/memcmp_test.c: extend test to support custom memcmp function

Extend the tests to permit loading an external memcmp function
and testing it over using the libc version. This was added by the
example of other tests in the test suite doing the same thing and
helped tremendously in development.

This change was originally part of D41442 but was taken out to
permit separate review as extrapolated from @ngie's request in
D41349.

Sponsored by: FreeBSD Foundation
Approved by: ngie
Differential Revision: https://reviews.freebsd.org/D41528

9 months agoossl: Rebuild the openssl asm
Andrew Turner [Thu, 21 Sep 2023 13:06:54 +0000 (14:06 +0100)]
ossl: Rebuild the openssl asm

This adds the new BTI instructions when needed to the arm64 assembly.

Sponsored by: Arm Ltd

Reviewed by: Pierre Pronchery <pierre@freebsdfoundation.org> (earlier version)
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D41941

9 months agoaarch64: fix branch target indications in arm64cpuid.pl and keccak1600
Tom Cosgrove [Mon, 7 Feb 2022 14:44:56 +0000 (14:44 +0000)]
aarch64: fix branch target indications in arm64cpuid.pl and keccak1600

Add missing AARCH64_VALID_CALL_TARGET to armv8_rng_probe(). Also add
these to the functions defined by gen_random(), and note that this Perl
sub prints the assembler out directly, not going via the $code xlate
mechanism (and therefore coming before the include of arm_arch.h). So
fix this too.

In KeccakF1600_int, AARCH64_SIGN_LINK_REGISTER functions as
AARCH64_VALID_CALL_TARGET on BTI-only builds, so it needs to come before
the 'adr' line.

Change-Id: If241efe71591c88253a3e36647ced00300c3c1a3

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17653)

Obtained from: OpenSSL 3a23f01268ec

9 months agoaarch64: support BTI and pointer authentication in assembly
Russ Butler [Sat, 28 Aug 2021 18:57:09 +0000 (13:57 -0500)]
aarch64: support BTI and pointer authentication in assembly

This change adds optional support for
- Armv8.3-A Pointer Authentication (PAuth) and
- Armv8.5-A Branch Target Identification (BTI)
features to the perl scripts.

Both features can be enabled with additional compiler flags.
Unless any of these are enabled explicitly there is no code change at
all.

The extensions are briefly described below. Please read the appropriate
chapters of the Arm Architecture Reference Manual for the complete
specification.

Scope
-----

This change only affects generated assembly code.

Armv8.3-A Pointer Authentication
--------------------------------

Pointer Authentication extension supports the authentication of the
contents of registers before they are used for indirect branching
or load.

PAuth provides a probabilistic method to detect corruption of register
values. PAuth signing instructions generate a Pointer Authentication
Code (PAC) based on the value of a register, a seed and a key.
The generated PAC is inserted into the original value in the register.
A PAuth authentication instruction recomputes the PAC, and if it matches
the PAC in the register, restores its original value. In case of a
mismatch, an architecturally unmapped address is generated instead.

With PAuth, mitigation against ROP (Return-oriented Programming) attacks
can be implemented. This is achieved by signing the contents of the
link-register (LR) before it is pushed to stack. Once LR is popped,
it is authenticated. This way a stack corruption which overwrites the
LR on the stack is detectable.

The PAuth extension adds several new instructions, some of which are not
recognized by older hardware. To support a single codebase for both pre
Armv8.3-A targets and newer ones, only NOP-space instructions are added
by this patch. These instructions are treated as NOPs on hardware
which does not support Armv8.3-A. Furthermore, this patch only considers
cases where LR is saved to the stack and then restored before branching
to its content. There are cases in the code where LR is pushed to stack
but it is not used later. We do not address these cases as they are not
affected by PAuth.

There are two keys available to sign an instruction address: A and B.
PACIASP and PACIBSP only differ in the used keys: A and B, respectively.
The keys are typically managed by the operating system.

To enable generating code for PAuth compile with
-mbranch-protection=<mode>:

- standard or pac-ret: add PACIASP and AUTIASP, also enables BTI
  (read below)
- pac-ret+b-key: add PACIBSP and AUTIBSP

Armv8.5-A Branch Target Identification
--------------------------------------

Branch Target Identification features some new instructions which
protect the execution of instructions on guarded pages which are not
intended branch targets.

If Armv8.5-A is supported by the hardware, execution of an instruction
changes the value of PSTATE.BTYPE field. If an indirect branch
lands on a guarded page the target instruction must be one of the
BTI <jc> flavors, or in case of a direct call or jump it can be any
other instruction. If the target instruction is not compatible with the
value of PSTATE.BTYPE a Branch Target Exception is generated.

In short, indirect jumps are compatible with BTI <j> and <jc> while
indirect calls are compatible with BTI <c> and <jc>. Please refer to the
specification for the details.

Armv8.3-A PACIASP and PACIBSP are implicit branch target
identification instructions which are equivalent with BTI c or BTI jc
depending on system register configuration.

BTI is used to mitigate JOP (Jump-oriented Programming) attacks by
limiting the set of instructions which can be jumped to.

BTI requires active linker support to mark the pages with BTI-enabled
code as guarded. For ELF64 files BTI compatibility is recorded in the
.note.gnu.property section. For a shared object or static binary it is
required that all linked units support BTI. This means that even a
single assembly file without the required note section turns-off BTI
for the whole binary or shared object.

The new BTI instructions are treated as NOPs on hardware which does
not support Armv8.5-A or on pages which are not guarded.

To insert this new and optional instruction compile with
-mbranch-protection=standard (also enables PAuth) or +bti.

When targeting a guarded page from a non-guarded page, weaker
compatibility restrictions apply to maintain compatibility between
legacy and new code. For detailed rules please refer to the Arm ARM.

Compiler support
----------------

Compiler support requires understanding '-mbranch-protection=<mode>'
and emitting the appropriate feature macros (__ARM_FEATURE_BTI_DEFAULT
and __ARM_FEATURE_PAC_DEFAULT). The current state is the following:

-------------------------------------------------------
| Compiler | -mbranch-protection | Feature macros     |
+----------+---------------------+--------------------+
| clang    | 9.0.0               | 11.0.0             |
+----------+---------------------+--------------------+
| gcc      | 9                   | expected in 10.1+  |
-------------------------------------------------------

Available Platforms
------------------

Arm Fast Model and QEMU support both extensions.

https://developer.arm.com/tools-and-software/simulation-models/fast-models
https://www.qemu.org/

Implementation Notes
--------------------

This change adds BTI landing pads even to assembly functions which are
likely to be directly called only. In these cases, landing pads might
be superfluous depending on what code the linker generates.
Code size and performance impact for these cases would be negligible.

Interaction with C code
-----------------------

Pointer Authentication is a per-frame protection while Branch Target
Identification can be turned on and off only for all code pages of a
whole shared object or static binary. Because of these properties if
C/C++ code is compiled without any of the above features but assembly
files support any of them unconditionally there is no incompatibility
between the two.

Useful Links
------------

To fully understand the details of both PAuth and BTI it is advised to
read the related chapters of the Arm Architecture Reference Manual
(Arm ARM):
https://developer.arm.com/documentation/ddi0487/latest/

Additional materials:

"Providing protection for complex software"
https://developer.arm.com/architectures/learn-the-architecture/providing-protection-for-complex-software

Arm Compiler Reference Guide Version 6.14: -mbranch-protection
https://developer.arm.com/documentation/101754/0614/armclang-Reference/armclang-Command-line-Options/-mbranch-protection?lang=en

Arm C Language Extensions (ACLE)
https://developer.arm.com/docs/101028/latest

Addional Notes
--------------

This patch is a copy of the work done by Tamas Petz in boringssl. It
contains the changes from the following commits:

aarch64: support BTI and pointer authentication in assembly
    Change-Id: I4335f92e2ccc8e209c7d68a0a79f1acdf3aeb791
    URL: https://boringssl-review.googlesource.com/c/boringssl/+/42084
aarch64: Improve conditional compilation
    Change-Id: I14902a64e5f403c2b6a117bc9f5fb1a4f4611ebf
    URL: https://boringssl-review.googlesource.com/c/boringssl/+/43524
aarch64: Fix name of gnu property note section
    Change-Id: I6c432d1c852129e9c273f6469a8b60e3983671ec
    URL: https://boringssl-review.googlesource.com/c/boringssl/+/44024

Change-Id: I2d95ebc5e4aeb5610d3b226f9754ee80cf74a9af

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16674)

Reviewed by: emaste, Pierre Pronchery <pierre@freebsdfoundation.org>
Obtained from: OpenSSL 19e277dd19f2
Differential Revision: https://reviews.freebsd.org/D41940

9 months agonvme: Fix memory leak in pt ioctl commands
David Sloan [Thu, 7 Sep 2023 16:22:21 +0000 (10:22 -0600)]
nvme: Fix memory leak in pt ioctl commands

When running nvme passthrough commands through the ioctl interface
memory is mapped with vmapbuf() but not unmapped. This results in leaked
memory whenever a process executes an nvme passthrough command with a
data buffer. This can be replicated with a simple c function (error
checks skipped for brevity):

void leak_memory(int nvme_ns_fd, uint16_t nblocks) {
struct nvme_pt_command pt = {
.cmd = {
.opc = NVME_OPC_READ,
.cdw12 = nblocks - 1,
},
.len = nblocks * 512, // Assumes devices with 512 byte lba
.is_read = 1, // Reads and writes should both trigger leak
}
void *buf;

posix_memalign(&buf, nblocks * 512);
pt.buf = buf;
ioctl(nvme_ns_fd, NVME_PASSTHROUGH_COMMAND, &pt);
free(buf);
}

Signed-off-by: David Sloan <david.sloan@eideticom.com>
PR: 273626
Reviewed by: imp, markj
MFC after: 1 week

9 months agonet80211 / drivers: remove public use of ieee80211_node_incref()
Bjoern A. Zeeb [Mon, 2 Oct 2023 14:44:29 +0000 (14:44 +0000)]
net80211 / drivers: remove public use of ieee80211_node_incref()

ieee80211_node_incref() is the FreeBSD implementation of
ieee80211_ref_node().  Not being interested in the node returned
it was used as a shortcut in 3 drivers (ath, uath, wpi).
Replace the call with the public KPI of ieee80211_ref_node() and
ignore the result.
This leaves us with the single internal call going
ieee80211_ref_node() -> ieee80211_node_incref() and that should
help increasing portability but also limiting the places to trace
for node reference operations.

Sponsored by: The FreeBSD Foundation
MFC after: 4 weeks

9 months agonet80211: make ieee80211_alloc_node() private
Bjoern A. Zeeb [Mon, 2 Oct 2023 13:57:45 +0000 (13:57 +0000)]
net80211: make ieee80211_alloc_node() private

Looking through the allocation/free and reference cycle of nodes we have
a few (publicly) (almost) unused macros and functions.
Start making them private and reducing the amount of entry paths to the
same/similar functionality.
First is to make ieee80211_alloc_node() static as it is nowhere used
in the tree outside this file.

Sponsored by: The FreeBSD Foundation
X-MFC: no

9 months agonet80211: improve ddb output for sta and rate
Bjoern A. Zeeb [Mon, 2 Oct 2023 13:53:33 +0000 (13:53 +0000)]
net80211: improve ddb output for sta and rate

Add more missing fields to the ddb output of sta (including spares so
people will notice if they use them to adjust ddb as well).
There are still more missing fields (some left as reminder in an
uncompiled __notyet__ block).

Add _db_show_rate() to print iv_rate as well optionally including
function pointers.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days

9 months agoofwdump: install dependent on MK_FDT
Mitchell Horne [Mon, 2 Oct 2023 13:40:18 +0000 (10:40 -0300)]
ofwdump: install dependent on MK_FDT

The utility depends on the presence of the openfirm(4) pseudo-device,
which is gated by the FDT kernel option. The MK_FDT knob is correctly
set to "yes" for FDT/OFW-enabled platforms (powerpc* included); use it
to install the utility and eliminate the arch-specific Makefile logic.

No functional change intended.

Reviewed by: emaste, pkubaj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41977

9 months agonetdump: Check the return value of ifunit_ref()
Mark Johnston [Mon, 2 Oct 2023 12:08:20 +0000 (08:08 -0400)]
netdump: Check the return value of ifunit_ref()

We may fail to match if the specific interface doesn't exist or was
renamed.

PR: 273715
Reported by: grembo
MFC after: 1 week

9 months agoswap_pager: Fix a race in swap_pager_swapoff_object()
Mark Johnston [Mon, 2 Oct 2023 11:49:27 +0000 (07:49 -0400)]
swap_pager: Fix a race in swap_pager_swapoff_object()

When we disable swapping to a device, we scan the full VM object list
looking for objects with swap trie nodes that reference the device in
question.  The pages corresponding to those nodes are paged in.

While paging in, we drop the VM object lock.  Moreover, we do not hold a
reference for the object; swap_pager_swapoff_object() merely bumps the
paging-in-progress counter.  vm_object_terminate() waits for this
counter to drain before proceeding and freeing pages.

However, swap_pager_swapoff_object() decrements the counter before
re-acquiring the VM object lock, which means that vm_object_terminate()
can race to acquire the lock and free the pages.  Then,
swap_pager_swapoff_object() ends up unbusying a freed page.  Fix the
problem by acquiring the lock before waking up sleepers.

PR: 273610
Reported by: Graham Perrin <grahamperrin@gmail.com>
Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42029

9 months agoObsoleteFiles.inc: only leave ofwdump.8.gz when WITH_FDT is set
Piotr Kubaj [Sun, 1 Oct 2023 21:36:37 +0000 (23:36 +0200)]
ObsoleteFiles.inc: only leave ofwdump.8.gz when WITH_FDT is set

Approved by: mhorne
Differential Revision: https://reviews.freebsd.org/D41905
MFC after: 3 days

9 months agomakefs/zfs: fix build with gcc 12 after b5a2bf512dbe
Dimitry Andric [Sat, 30 Sep 2023 18:27:20 +0000 (20:27 +0200)]
makefs/zfs: fix build with gcc 12 after b5a2bf512dbe

Due to integer promotion rules, dn_nlevels (uint8_t) gets promoted to a
plain int, resulting in -Werror warnings with gcc 12:

  In file included from /workspace/src/usr.sbin/makefs/zfs.c:35:
  /workspace/src/usr.sbin/makefs/zfs.c: In function '_dnode_cursor_flush':
  /workspace/src/usr.sbin/makefs/zfs.c:684:23: error: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Werror=sign-compare]
    684 |         assert(levels <= c->dnode->dn_nlevels - 1);
        |                       ^~
  /workspace/src/usr.sbin/makefs/zfs.c:691:27: error: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Werror=sign-compare]
    691 |                 if (level == c->dnode->dn_nlevels - 1) {
        |                           ^~
  /workspace/src/usr.sbin/makefs/zfs.c: In function 'dnode_cursor_next':
  /workspace/src/usr.sbin/makefs/zfs.c:739:41: error: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Werror=sign-compare]
    739 |                 for (levels = 0; levels < c->dnode->dn_nlevels - 1; levels++) {
        |                                         ^

Fix it by subtracting 1U instead of 1.

Fixes: b5a2bf512dbe
MFC after: 3 days

9 months agoLinuxKPI: 802.11: improve lkpi_ic_vap_delete()
Bjoern A. Zeeb [Sat, 30 Sep 2023 15:20:53 +0000 (15:20 +0000)]
LinuxKPI: 802.11: improve lkpi_ic_vap_delete()

Changing the order of cleanup in lkpi_ic_vap_delete() will avoid
firmware crashes or a direct panic as observed as ieee80211_vap_detach()
will do most cleanup for us and get us into the correct state.

The solution is not fully developed yet and one may not be able
to create a new vap (lkpi_ic_vap_create may fail with error 17)
afterwards.  It is supposed to be a step towards more stability
for now.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
PR:  269842

9 months agoLinuxKPI: 802.11: fix problem removing sta
Bjoern A. Zeeb [Sat, 30 Sep 2023 07:59:48 +0000 (07:59 +0000)]
LinuxKPI: 802.11: fix problem removing sta

Move the call to lkpi_disassoc() before the state change to
IEEE80211_STA_NOTEXIST which will remove the sta (from firmware).
Based on a comment it seems that originally we had to do it the
other way round.
iwlwifi(4) has a check and will silently not remove the sta from
the firmware when vif->cfg.assoc is still set (see iwl_mvm_sta_del()).
This leads to the LinuxKPI 802.11 code thinking the sta is gone as
downward state changes by the mac80211 op (*sta_state)() may not fail.
Once we try to assoc with a newly added station later, iwlwifi firmware
will run into an assert having two ap_sta set on the same vif.
We can observe that problem in iwlwifi(4) having __le32 sta_id = 1
instead of sta_id = 0 in iwl_mvm_sta_cfg_cmd{} on the HCMD.

This should fix one of the most seen problems with iwlwifi(4), e.g.,
when running service netif restart wlan0 or
service wpa_supplicant restart wlan0.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days

9 months agozfs: merge openzfs/zfs@e13538856
Martin Matuska [Fri, 29 Sep 2023 23:21:44 +0000 (01:21 +0200)]
zfs: merge openzfs/zfs@e13538856

Notable upstream pull request merges:
 #15308 5551dcd76 Don't allocate from new metaslabs
 #15312 ba769ea35 Fix ENOSPC for extended quota
 #15321 e13538856 Restrict short block cloning requests
 #15324 f9c39dc86 Tweak rebuild in-flight hard limit

Obtained from: OpenZFS
OpenZFS commit: e13538856479ff79ca6642e53dddf8a593deb2c9

9 months agoAllow for CSTD to be set kernel module Makefiles before inclusion
Stephen J. Kiernan [Fri, 29 Sep 2023 15:04:45 +0000 (11:04 -0400)]
Allow for CSTD to be set kernel module Makefiles before inclusion

Use ?= when setting the default value for CSTD so it can be set by
Makefiles before inclusion and not be overridden by the .mk file.

Reviewed by: imp, sjg
Obtained from: Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D42019

9 months agopf: only create sctp multihome states if we pass the packet
Kristof Provost [Fri, 29 Sep 2023 07:23:43 +0000 (09:23 +0200)]
pf: only create sctp multihome states if we pass the packet

If we've decided to drop the packet we shouldn't create additional
states based off it.

MFC after: 3 days
Sponsored by: Orange Business Services

9 months agopf: ensure 'off' is always set before use
Kristof Provost [Thu, 28 Sep 2023 07:04:32 +0000 (09:04 +0200)]
pf: ensure 'off' is always set before use

If we bail out early from pf_test(6)() we still need to clean up/finish
SCTP multihome work, which requires the 'off' value to be set. Set it
early enough.

MFC after: 3 days
Sponsored by: Orange Business Services

9 months agoObsoleteFiles: remove duplicated and incorrect libclang_rt powerpc64le entries
Dimitry Andric [Fri, 29 Sep 2023 18:41:52 +0000 (20:41 +0200)]
ObsoleteFiles: remove duplicated and incorrect libclang_rt powerpc64le entries

PR: 273776
MFC after: 3 days

9 months agoRestrict short block cloning requests
Alexander Motin [Fri, 29 Sep 2023 15:22:46 +0000 (11:22 -0400)]
Restrict short block cloning requests

If we are copying only one block and it is smaller than recordsize
property, do not allow destination to grow beyond one block if it
is not there yet.  Otherwise the destination will get stuck with
that block size forever, that can be as small as 512 bytes, no
matter how big the destination grow later.

Reviewed-by: Kay Pedersen <mail@mkwg.de>
Reviewed-by: Rob Norris <rob.norris@klarasystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by: iXsystems, Inc.
Closes #15321

9 months agoTweak rebuild in-flight hard limit
Brian Behlendorf [Fri, 29 Sep 2023 15:21:25 +0000 (08:21 -0700)]
Tweak rebuild in-flight hard limit

Vendor testing shows we should be able to get a little more
performance if we further relax the hard limit which we're hitting.

Authored-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes #15324

9 months agodtc: Ensure it is built in C++17 mode
Jose Luis Duran [Fri, 29 Sep 2023 13:24:32 +0000 (09:24 -0400)]
dtc: Ensure it is built in C++17 mode

Explicitly specify the C++ standard to be used in the Makefile.
This prevents macOS cross-builds from using the default gnu++98 and
fail.  This syncs dtc with upstream commit
39a58cfaab7d55c7975ebf905d859ba91a369fa0.

Reviewed by: emaste
Fixes: 29a55fd09b0a ("dtc: Sync with upstream commit 26a0fe5")
Differential Revision: https://reviews.freebsd.org/D42006

9 months agoipfilter: Add sysctl flag CTLFLAG_TUN to loader tunable
Zhenlei Huang [Fri, 29 Sep 2023 00:01:43 +0000 (08:01 +0800)]
ipfilter: Add sysctl flag CTLFLAG_TUN to loader tunable

The sysctl variable `net.inet.ipf.large_nat` is actually a loader
tunable. Add sysctl flag CTLFLAG_TUN to it so that `sysctl -T` will
report it correctly.

No functional change intended.

Reviewed by: cy (for #network)
Fixes: a805ffbcbce8 ipfilter: Make LARGE_NAT a tunable
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D42005

9 months agoEC2: Add experimental cloud-init images
Colin Percival [Sat, 9 Sep 2023 00:55:16 +0000 (17:55 -0700)]
EC2: Add experimental cloud-init images

Known issues:

1. The ec2-user user is created with a homedir of /usr/home/ec2-user
instead of /home/ec2-user; this appears to be a bug in cloud-init's
FreeBSD support.

2. Cloud-init configures IPv4 networking but not IPv6 networking.

releng/14.0 candidate.

Discussed with: gjb
Reviewed by: imp
MFC after: 5 days
Relnotes: yes
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D41793

9 months agoEC2: Split off reusable configuration bits
Colin Percival [Sat, 9 Sep 2023 00:54:11 +0000 (17:54 -0700)]
EC2: Split off reusable configuration bits

Split ec2-base.conf into ec2-base.conf and a reusable ec2.conf,
similar to how Vagrant flavours share a common vagrant.conf.

releng/14.0 candidate.

Discussed with: gjb
MFC after: 5 days
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D41792

9 months agoEC2: Flavour existing AMIs as "base"
Colin Percival [Sat, 9 Sep 2023 00:51:57 +0000 (17:51 -0700)]
EC2: Flavour existing AMIs as "base"

Using the recently-added "cloudware flavours" mechanism, turn the
existing EC2 AMIs into a new "base" flavour.  The only user-visible
change is that AMI names now include the word "base".

releng/14.0 candidate.

Discussed with: gjb
Reviewed by: imp
MFC after: 5 days
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D41791

9 months agorelease/Makefile.vm: Add support for CW flavours
Colin Percival [Sat, 9 Sep 2023 00:51:08 +0000 (17:51 -0700)]
release/Makefile.vm: Add support for CW flavours

There are two "Vagrant" images right now: "Vagrant Image for VirtualBox"
and "Vagrant Image for VMWare".  Rather than listing these separately in
a CLOUDWARE list, place "VAGRANT" into a CLOUDWARE_TYPES list and then
use a VAGRANT_FLAVOURS variable to identify the two versions.  Add make
logic to allow defaults (in this case, image format and filesystem) to
be specified once for VAGRANT and inherited by both flavours.

This will make future work to add flavoured EC2 images simpler.

releng/14.0 candidate.

Discussed with: gjb
Reviewed by: imp
MFC after: 5 days
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D41790

9 months agorelease/Makefile.vm: Garbage collect unused bits
Colin Percival [Sat, 9 Sep 2023 00:49:35 +0000 (17:49 -0700)]
release/Makefile.vm: Garbage collect unused bits

The cw*-package targets were introduced in February 2015 as part of
adding support for building GCE images; but GCE support was reworked
in June 2015 and the cw*-package targets were in fact never used.
Remove them.

The *_DISK variables were introduced in February 2015 as part of
adding the cloudware-install target; this was removed in May 2016 as
the cloudware images are published via the respective cloud systems
and not published as disk images via the FreeBSD FTP site.  As such,
the *_DISK variables are not unused; remove them.

releng/14.0 candidate.

Discussed with: gjb
Reviewed by: imp
MFC after: 5 days
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D41789

9 months agobsd-family-tree: add macOS 14
Sergey A. Osokin [Thu, 28 Sep 2023 21:42:08 +0000 (17:42 -0400)]
bsd-family-tree: add macOS 14

MFC after: 3 days

9 months agoRemove unnecessary -isystem for host
Simon J. Gerraty [Thu, 28 Sep 2023 21:19:11 +0000 (14:19 -0700)]
Remove unnecessary -isystem for host

Turns out we do not need -isystem/usr/include and
it can interfere with newer toolchains.

Reviewed by: stevek

9 months agoFix ENOSPC for extended quota
Akash B [Thu, 28 Sep 2023 21:10:07 +0000 (02:40 +0530)]
Fix ENOSPC for extended quota

When unlinking multiple files from a pool at 100% capacity, it
was possible for ENOSPC to be returned after the first few unlinks.
This issue was fixed previously by PR #13172 but then this was
again introduced by PR #13839.

This is resolved using the existing mechanism of returning ERESTART
when over quota as long as we know enough space will shortly be
available after processing the pending deferred frees.

Also, updated the existing testcase which reliably reproduced the
issue without this patch.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Dipak Ghosh <dipak.ghosh@hpe.com>
Signed-off-by: Akash B <akash-b@hpe.com>
Closes #15312

9 months agoDon't allocate from new metaslabs
Paul Dagnelie [Thu, 28 Sep 2023 21:08:52 +0000 (14:08 -0700)]
Don't allocate from new metaslabs

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #15307
Closes #15308

9 months agox86: Properly align interrupt vectors for MSI
John Hay [Thu, 28 Sep 2023 21:08:08 +0000 (14:08 -0700)]
x86: Properly align interrupt vectors for MSI

MSI (not MSI-X) interrupt vectors must be allocated in groups that are
powers of 2, and the block of IDT vectors must be aligned to the size
of the request.

The code in native_apic_alloc_vectors() does an alignment check in the loop:

    if ((vector & (align - 1)) != 0)
        continue;
    first = vector;

But it adds APIC_IO_INTS to the value it returns:

    return (first + APIC_IO_INTS);

The problem is that APIC_IO_INTS is not a multiple of 32. It is 48:

As a result, a request for 32 vectors (the max supported by MSI), was
not always aligned.  To fix, check the alignment of
'vector + APIC_IO_INTS' in the loop.

PR: 274074
Reviewed by: jhb

9 months agoMove the adding of CFLAGS_LAST to bsd.sys.mk
Simon J. Gerraty [Thu, 28 Sep 2023 21:01:56 +0000 (14:01 -0700)]
Move the adding of CFLAGS_LAST to bsd.sys.mk

The point of CFLAGS_LAST is to be the last thing in CFLAGS
so add it last.

For DIRDEPS_BUILD this can best be done via local.dirdeps-build.mk
which is guaranteed to be the last makefile read, but that does nothing
for non-DIRDEPS_BUILD

bsd.sys.mk is close enough to the end.

Reviewed by: obrien
Differential Revision: https://reviews.freebsd.org/D42001

9 months agomakefs/zfs tests: Add a test case which appends to a file after import
Mark Johnston [Thu, 28 Sep 2023 20:25:06 +0000 (16:25 -0400)]
makefs/zfs tests: Add a test case which appends to a file after import

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

9 months agomakefs/zfs: Ensure that the last block of a file has the right size
Mark Johnston [Thu, 28 Sep 2023 20:16:17 +0000 (16:16 -0400)]
makefs/zfs: Ensure that the last block of a file has the right size

When copying a file's contents into the pool, a loop copies blocks of
the maximum size (128KB), allocating space from the vdev for each block.
The space allocator rounds up to the nearest block size, but for files
larger than the maximum size, this can result in the last block having a
smaller logical size than the rest of the blocks belonging to that
dnode.  This violates some ZFS invariants when appending to that file.

Modify fs_populate_file() to use the same block size for the final
block.

Reported by: cperciva
MFC after: 1 week
Sponsored by: The FreeBSD Foundation

9 months agosplit: Improve GNU compatibility.
Dag-Erling Smørgrav [Thu, 28 Sep 2023 16:30:00 +0000 (18:30 +0200)]
split: Improve GNU compatibility.

* Like GNU split, turn autoextend back on if given -a0.
* Add a test case that verifies that -a<non-zero> turns autoextend off.
* Add a test case that verifies that -a0 turns autoextend back on.

Sponsored by: Klara, Inc.
Reviewed by: christos, kevans
Differential Revision: https://reviews.freebsd.org/D42011

9 months agosplit: Further option parsing improvements.
Dag-Erling Smørgrav [Thu, 28 Sep 2023 16:29:52 +0000 (18:29 +0200)]
split: Further option parsing improvements.

* Whenever possible, use strtonum() to parse numeric arguments.
* Improve usefulness and consistency of error messages.
* While here, fix some type and style issues.

Sponsored by: Klara, Inc.
Reviewed by: christos, kevans
Differential Revision: https://reviews.freebsd.org/D42010

9 months agosyslogd: Do not add shutdown sockets to the kqueue
Jake Freeland [Fri, 1 Sep 2023 02:51:33 +0000 (21:51 -0500)]
syslogd: Do not add shutdown sockets to the kqueue

If syslogd is in secure mode, all INET sockets are shutdown. Do not
add these to the kqueue because we can't read from them.

Also, remove the listen() call when setting up sockets. Syslogd
exclusively uses SOCK_DGRAM sockets, so calling listen() is useless.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41526

9 months agosyslogd: Use pipe to communicate with daemon
Jake Freeland [Fri, 1 Sep 2023 02:51:28 +0000 (21:51 -0500)]
syslogd: Use pipe to communicate with daemon

Previously, syslogd's daemon process would signal that it had finished
initialization using SIGALRM. In capability mode, signal delivery is not
allowed, so use a pipe to indicate that it is ready to accept messages.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41459

9 months agosyslogd: Ignore signals in sigcatch[]
Jake Freeland [Fri, 1 Sep 2023 02:51:22 +0000 (21:51 -0500)]
syslogd: Ignore signals in sigcatch[]

Instead of blocking signals in sigcatch[], just ignore them. This frees
up some space on the proc's sigqueue.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41433

9 months agosyslogd: Pre-open null file descriptor
Jake Freeland [Fri, 1 Sep 2023 02:51:17 +0000 (21:51 -0500)]
syslogd: Pre-open null file descriptor

Open _PATH_DEVNULL before entering capability mode. Access to /dev/null
is needed for dup2() when piping commands.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41381

9 months agosyslogd: Do not open console descriptor
Jake Freeland [Fri, 1 Sep 2023 02:51:12 +0000 (21:51 -0500)]
syslogd: Do not open console descriptor

Setup consfile filed for logging while Initialized is false, but do not
bother opening the console. Close console/tty descriptors after parsing,
as well. The ttymsg() function will re-open these descriptors for us.

Also, remove references to the ctty global variable since it will always
be _PATH_CONSOLE.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41380

9 months agosyslogd: unlink() -> unlinkat()
Jake Freeland [Fri, 1 Sep 2023 02:51:06 +0000 (21:51 -0500)]
syslogd: unlink() -> unlinkat()

Save basename and dirname for use in unlinkat() when removing UNIX
sockets from fs.

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41379

9 months agosyslogd: Add closelogfiles() function
Jake Freeland [Fri, 1 Sep 2023 02:51:00 +0000 (21:51 -0500)]
syslogd: Add closelogfiles() function

The closelogfiles() function completely disassembles the global filed
list by freeing all filed components and removing them from the list.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41388

9 months agosyslogd: Fix sizeof() styling
Jake Freeland [Fri, 1 Sep 2023 02:50:55 +0000 (21:50 -0500)]
syslogd: Fix sizeof() styling

Use parentheses when applying sizeof() per style(9).

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41376

9 months agosyslogd: Move action parsing into its own function
Jake Freeland [Fri, 1 Sep 2023 02:50:49 +0000 (21:50 -0500)]
syslogd: Move action parsing into its own function

Clean up the cfline() function by moving action parsing into its own
function.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41375

9 months agosyslogd: Move selector parsing into its own function
Jake Freeland [Fri, 1 Sep 2023 02:50:45 +0000 (21:50 -0500)]
syslogd: Move selector parsing into its own function

Clean up the cfline() function by moving selector parsing into its
own function.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41374

9 months agosyslogd: Move prop_filter allocation into function
Jake Freeland [Fri, 1 Sep 2023 02:50:39 +0000 (21:50 -0500)]
syslogd: Move prop_filter allocation into function

Clean up the cfline() function by moving the prop_filter memory
allocation into the prop_filter_compile() function.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41373

9 months agosyslogd: Do not print bad data
Jake Freeland [Fri, 1 Sep 2023 02:50:35 +0000 (21:50 -0500)]
syslogd: Do not print bad data

If errno is zero, then buf is never filled and we're printing
uninitialized data. Print the msg buffer instead to mitigate this.

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41371

9 months agosyslogd: Merge loops
Jake Freeland [Fri, 1 Sep 2023 02:50:26 +0000 (21:50 -0500)]
syslogd: Merge loops

Merge the two loops that traverse the global filed queue. Both loops'
actions are not dependent on the other, so combining them is safe.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41370

9 months agosyslogd: Do not reap child processes
Jake Freeland [Fri, 1 Sep 2023 02:50:19 +0000 (21:50 -0500)]
syslogd: Do not reap child processes

Use the SA_NOCLDWAIT sigaction() flag to disable the creation of
zombie processes. This leaves no reason to wait() on children, so
remove the reaping routine.

Previously, deadq entries were removed in reapchild(). Move deadq
removal into markit() after SIGKILL is sent.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41415

9 months agosyslogd: Use process descriptors
Jake Freeland [Fri, 1 Sep 2023 02:50:14 +0000 (21:50 -0500)]
syslogd: Use process descriptors

Prepare for program Capsicumization by storing process descriptors
instead of pids. Signal delivery is not permitted in capability mode,
so we can use pdkill(2) to terminate child processes.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41369

9 months agosyslogd: Simplify filed structure
Jake Freeland [Fri, 1 Sep 2023 02:50:08 +0000 (21:50 -0500)]
syslogd: Simplify filed structure

Rearrange fields and add some comments.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41368

9 months agosyslogd: Style fixes
Jake Freeland [Fri, 1 Sep 2023 02:50:03 +0000 (21:50 -0500)]
syslogd: Style fixes

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41367

9 months agosyslogd: Simplify property filters
Jake Freeland [Fri, 1 Sep 2023 02:49:58 +0000 (21:49 -0500)]
syslogd: Simplify property filters

* Use enums for property filter properties and comparisons.
* Rename property and comparison values.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41366

9 months agosyslogd: Clean up allowedpeer structure
Jake Freeland [Fri, 1 Sep 2023 02:49:53 +0000 (21:49 -0500)]
syslogd: Clean up allowedpeer structure

* Use boolean values in validate() and struct allowedpeer.
* Remove useless peer count loop.

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41365

9 months agosyslogd: Only use peerlist during flag parsing
Jake Freeland [Fri, 1 Sep 2023 02:49:45 +0000 (21:49 -0500)]
syslogd: Only use peerlist during flag parsing

Add logging sockets directly to the socklist, unless parsing flags. The
peerlist is still needed to temporarily hold socket information until
the configuration flags have been parsed.

It is tempting to remove the entire peerlist, but addsock() can not
determine if syslogd is in secure mode unless the flags have been
parsed.

Also, call pidfile_open() right after flag parsing so we can terminate
if another syslogd instance is already running.

Reviewed by: markj
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41364

9 months agosyslogd: Use boolean reload parameter for init()
Jake Freeland [Fri, 1 Sep 2023 02:49:36 +0000 (21:49 -0500)]
syslogd: Use boolean reload parameter for init()

Replace init()'s integer "signo" parameter with boolean "reload"
for clarity.

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41416

9 months agosyslogd: Centralize operations into a kevent loop
Jake Freeland [Fri, 1 Sep 2023 02:49:29 +0000 (21:49 -0500)]
syslogd: Centralize operations into a kevent loop

Use kqueue(2) for socket I/O and signal notification. Previously,
select(2) and traditional signal handlers were being used.

This change centralizes all of the async notification delivery into a
single loop so future Capsicum sandboxing will be easier. It also
simplifies the code by removing boiler-plate cruft that comes with the
older interfaces.

Reviewed by: Slawa Olhovchenkov, markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41363

9 months agosyslogd: Replace int with bool, where applicable
Jake Freeland [Fri, 1 Sep 2023 02:49:14 +0000 (21:49 -0500)]
syslogd: Replace int with bool, where applicable

Many of syslogd's global configuration options are declared as integers
but are treated as booleans. Declare those options as booleans instead.

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41362

9 months agosyslogd: Move fhead under filed struct declaration
Jake Freeland [Fri, 1 Sep 2023 02:49:07 +0000 (21:49 -0500)]
syslogd: Move fhead under filed struct declaration

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41360

9 months agosyslogd: Remove addfile() and free up some memory
Jake Freeland [Fri, 1 Sep 2023 02:49:00 +0000 (21:49 -0500)]
syslogd: Remove addfile() and free up some memory

cfline() already allocates a filed structure on the heap, so we can
avoid redundant memory allocations by skipping a second calloc() inside
addfile().

addfile() can be removed altogether since a simple STAILQ_INSERT_TAIL()
will add the filed to the global filed list.

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41359

9 months agosyslogd: Read configuration outside of init loop
Jake Freeland [Fri, 1 Sep 2023 02:48:53 +0000 (21:48 -0500)]
syslogd: Read configuration outside of init loop

Move all configuration-file code outside of the initialization loop and
into its own set of functions. Create a readconfigfile() to open the
config and call parseconfigfile() to parse it.

The init() function no longer returns if there was a failure to open the
configuration file. Initialization will be finished, using the backup
logging rules: *.ERR to /dev/console and *.PANIC to all logged in users.

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41358

9 months agosyslogd: Fix fd type, add enum for filed types
Mark Johnston [Fri, 1 Sep 2023 02:48:18 +0000 (21:48 -0500)]
syslogd: Fix fd type, add enum for filed types

Reviewed by: markj, emaste
MFC after: 3 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41357

9 months agosysctl(8): Mention more security.bsd knobs; Refer to security(7)
Olivier Certner [Thu, 17 Aug 2023 23:54:49 +0000 (01:54 +0200)]
sysctl(8): Mention more security.bsd knobs; Refer to security(7)

Reviewed by:            mhorne, pauamma_gundo.com, emaste
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D41113

9 months agoptrace(2): Disabling: Describe influence of security.bsd.see_jail_proc
Olivier Certner [Thu, 17 Aug 2023 23:54:48 +0000 (01:54 +0200)]
ptrace(2): Disabling: Describe influence of security.bsd.see_jail_proc

Reviewed by:            mhorne, emaste, pauamma_gundo.com
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D41109

9 months agosecurity(7): security.bsd.see*: Be more accurate
Olivier Certner [Thu, 17 Aug 2023 23:54:48 +0000 (01:54 +0200)]
security(7): security.bsd.see*: Be more accurate

Reviewed by:            mhorne, pauamma_gundo.com
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D41108

9 months agogroupmember(9), realgroupmember(9): Impact of signature change
Olivier Certner [Thu, 17 Aug 2023 23:54:47 +0000 (01:54 +0200)]
groupmember(9), realgroupmember(9): Impact of signature change

Reviewed by:            mhorne
MFC after:              2 weeks
MFC to:                 stable/14 releng/14.0
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40959

9 months agogroupmember(), realgroupmember(): Return a bool instead of an int
Olivier Certner [Thu, 17 Aug 2023 23:54:47 +0000 (01:54 +0200)]
groupmember(), realgroupmember(): Return a bool instead of an int

Requested by:           mhorne
Reviewed by:            mhorne
MFC after:              2 weeks
MFC to:                 stable/14 releng/14.0
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40958

9 months agocr_canseeothergids(): Policy change's manual pages impact
Olivier Certner [Thu, 17 Aug 2023 23:54:46 +0000 (01:54 +0200)]
cr_canseeothergids(): Policy change's manual pages impact

See previous commit that made cr_canseeothergids() use the new
realgroupmember() function, taking into account real group IDs instead
of effective ones.

PR:                     272093
Reviewed by:            pauamma_gundo.com, mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40644

9 months agorealgroupmember(9): Link to groupmember(9), document the function
Olivier Certner [Thu, 17 Aug 2023 23:54:46 +0000 (01:54 +0200)]
realgroupmember(9): Link to groupmember(9), document the function

Reviewed by:            bcr (older version), mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40643

9 months agocr_canseeothergids(): Use real instead of effective group membership
Olivier Certner [Thu, 17 Aug 2023 23:54:45 +0000 (01:54 +0200)]
cr_canseeothergids(): Use real instead of effective group membership

Using the effective group and not the real one when testing membership
has the consequence that unprivileged processes cannot see setuid
commands they launch until these have relinquished their privileges.
This is also in contradiction with how the similar cr_canseeotheruids()
works, i.e., by taking into account real user IDs.

Fix this by substituting groupmember() with realgroupmember().  While
here, simplify the code.

PR:                     272093
Reviewed by:            mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40642

9 months agoNew realgroupmember()
Olivier Certner [Thu, 17 Aug 2023 23:54:45 +0000 (01:54 +0200)]
New realgroupmember()

Like groupmember(), but taking into account the real group instead of
the effective group.  Leverages the new supplementary_group_member()
function.

Reviewed by:            mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40641

9 months agogroupmember(): Extract the supplementary group search in a separate function
Olivier Certner [Thu, 17 Aug 2023 23:54:44 +0000 (01:54 +0200)]
groupmember(): Extract the supplementary group search in a separate function

This is in preparation for the introduction of the new realgroupmember()
function, which does the same search into supplementary groups as
groupmember().

Reviewed by:            mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40640

9 months agoprison_check(9): Bring up-to-date with hierarchical jails
Olivier Certner [Thu, 17 Aug 2023 23:54:44 +0000 (01:54 +0200)]
prison_check(9): Bring up-to-date with hierarchical jails

Reviewed by:            bcr, emaste, pauamma_gundo.com, mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40639

9 months agop_candebug(9): cr_bsd_visible() impacts, misc fixes
Olivier Certner [Thu, 17 Aug 2023 23:54:43 +0000 (01:54 +0200)]
p_candebug(9): cr_bsd_visible() impacts, misc fixes

Mention cr_bsd_visible(9).  Remove references to cr_canseeothergids(9)
and cr_canseeotheruids(9), as well as indirect references not
immediately useful.

Fix description of credentials checks to match reality.

Re-order errors to match code's check order.

Reviewed by:            bcr, pauamma_gundo.com
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40638

9 months agop_cansee(9): Bring up-to-date, misc fixes
Olivier Certner [Thu, 17 Aug 2023 23:54:43 +0000 (01:54 +0200)]
p_cansee(9): Bring up-to-date, misc fixes

Essentially defer to cr_cansee(9), except for the specifics.

Be more specific on the return codes.

Reviewed by:            bcr, pauamma_gundo.com
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40637

9 months agocr_cansee(9): cr_bsd_visible() impacts, simplifications
Olivier Certner [Thu, 17 Aug 2023 23:54:42 +0000 (01:54 +0200)]
cr_cansee(9): cr_bsd_visible() impacts, simplifications

Remove references to cr_canseeothergids(9) and cr_canseeotheruids(9).
Defer to cr_bsd_visible() for controlling sysctl(8) variables.

Reviewed by:            bcr, mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40636

9 months agocr_canseeotheruids(9): Revamp, mark as internal
Olivier Certner [Thu, 17 Aug 2023 23:54:42 +0000 (01:54 +0200)]
cr_canseeotheruids(9): Revamp, mark as internal

Significantly clarify.  Replace references to cr_canseeothergids(9) by
ones to cr_bsd_visible(9).

Reviewed by:            bcr, mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40635

9 months agogroupmember(9): Detail which groups are considered, simplify
Olivier Certner [Thu, 17 Aug 2023 23:54:41 +0000 (01:54 +0200)]
groupmember(9): Detail which groups are considered, simplify

Reviewed by:            mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40634

9 months agocr_canseeothergids(9): Revamp, mark as internal
Olivier Certner [Thu, 17 Aug 2023 23:54:41 +0000 (01:54 +0200)]
cr_canseeothergids(9): Revamp, mark as internal

Significantly clarify.  Replace references to cr_canseeotheruids(9) by
ones to cr_bsd_visible(9).

Reviewed by:            pauamma_gundo.com, mhorne
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40633

9 months agocr_bsd_visible(9): New man page
Olivier Certner [Thu, 17 Aug 2023 23:54:40 +0000 (01:54 +0200)]
cr_bsd_visible(9): New man page

Reviewed by:            bcr, pauamma_gundo.com
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D40632