HardenedBSD/src 1333444 — sys/kern kern_loginclass.c, sys/sys syscallsubr.h

kern_loginclass.c: add kern_ implementations

Effort:         CHERI upstreaming
Sponsored by:   DARPA, AFRL, Innovate UK
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
DeltaFile
+16-3sys/kern/kern_loginclass.c
+2-0sys/sys/syscallsubr.h
+18-32 files

HardenedBSD/src 58a758c — sys/kern kern_linker.c, sys/sys syscallsubr.h

kern_linker.c: add kern_ implementations

kldsym(2) is more complex than typical because it requires translation
of struct kld_sym_lookup which is a weird in/out structure.  Out of
paranoia we avoid copying out the symname pointer in the capability
version to eliminate the possiblity of leaking a capability (but not
invalidating a pointer userspace might be using via copyout()).

Effort:         CHERI upstreaming
Sponsored by:   DARPA, AFRL, Innovate UK
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
DeltaFile
+50-23sys/kern/kern_linker.c
+4-0sys/sys/syscallsubr.h
+54-232 files

HardenedBSD/src 6189085 — sys/kern kern_ktrace.c, sys/sys syscallsubr.h

[ku]trace(2): add kern_[ku]trace

Effort:         CHERI upstreaming
Sponsored by:   Innovate UK
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
DeltaFile
+23-11sys/kern/kern_ktrace.c
+3-0sys/sys/syscallsubr.h
+26-112 files

HardenedBSD/src 7c9060c — sys/kern kern_fork.c, sys/sys syscallsubr.h

pdfork(2): add kern_pdfork

Effort:         CHERI upstreaming
Sponsored by:   Innovate UK
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
DeltaFile
+11-5sys/kern/kern_fork.c
+1-0sys/sys/syscallsubr.h
+12-52 files

HardenedBSD/src d477542 — sys/kern kern_ffclock.c, sys/sys syscallsubr.h

ffclock: add kern_ interfaces

Effort:         CHERI upstreaming
Sponsored by:   Innovate UK
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
DeltaFile
+24-4sys/kern/kern_ffclock.c
+7-0sys/sys/syscallsubr.h
+31-42 files

HardenedBSD/src 52bd0d1 — sys/kern kern_exit.c, sys/sys syscallsubr.h

wait6(2): add user_wait6

sys_wait6 is a little more complicated than typical as compat layers
need to translate siginfo_t.

Effort:         CHERI upstreaming
Sponsored by:   Innovate UK
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
DeltaFile
+24-19sys/kern/kern_exit.c
+3-0sys/sys/syscallsubr.h
+27-192 files

HardenedBSD/src 2e3ba76 — sys/kern kern_exit.c, sys/sys syscallsubr.h

wait4(2): add kern_wait4

Effort:         CHERI upstreaming
Sponsored by:   Innovate UK
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
DeltaFile
+14-6sys/kern/kern_exit.c
+2-0sys/sys/syscallsubr.h
+16-62 files

HardenedBSD/src 0a42a5c — sys/kern kern_event.c, sys/sys syscallsubr.h

kevent(2): add kern_kevent_generic

Effort:         CHERI upstreaming
Sponsored by:   Innovate UK
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
DeltaFile
+1-14sys/kern/kern_event.c
+11-0sys/sys/syscallsubr.h
+12-142 files

HardenedBSD/src 4cb5268 — usr.sbin/flowctl flowctl.8

flowctl.8: Describe better

Align description with EuroBSD netgraph document descriptions rewrite.

MFC after:      3 days
DeltaFile
+2-4usr.sbin/flowctl/flowctl.8
+2-41 files

HardenedBSD/src 4cbfaea — usr.sbin/adduser adduser.conf.5

adduser.conf.5: No crossreferences in titles

Crossreferences in titles are strongly discouraged and incompatible
with our own tooling. This is a wontfix by most of manpages ecosystem
because it is bad editorial style in the first place.

MFC after:      3 days
DeltaFile
+1-3usr.sbin/adduser/adduser.conf.5
+1-31 files

HardenedBSD/src 1794dd6 — lib/libc/locale freelocale.3

freelocale.3: No crossreferences in titles

Crossreferences in titles are strongly discouraged and incompatible
with our own tooling. This is a wontfix by most of manpages ecosystem
because it is bad editorial style in the first place.

MFC after:      3 days
DeltaFile
+1-4lib/libc/locale/freelocale.3
+1-41 files

HardenedBSD/src 115f0a2 — lib/libc/gen fmtcheck.3

fmtcheck.3: No crossreferences in titles

Crossreferences in titles are strongly discouraged and incompatible
with our own tooling. This is a wontfix by most of manpages ecosystem
because it is bad editorial style in the first place.

MFC after:      3 days
DeltaFile
+1-3lib/libc/gen/fmtcheck.3
+1-31 files

HardenedBSD/src 5e91181 — share/man/man7 arch.7

arch.7: Mechanical fixes

+ Increase portability by never starting content lines with symbols
+ Improve search results by adding tunables to the variable database
+ Improve search result consistency by correcting description style

MFC after:      3 days
DeltaFile
+9-7share/man/man7/arch.7
+9-71 files

HardenedBSD/src c9dc22c — sys/amd64/amd64 machdep.c, sys/dev/virtio/pci virtio_pci_modern.c

Merge branch 'freebsd/15-stable/main' into hardened/15-stable/main
DeltaFile
+141-0tests/sys/file/fork_lowfd_test.c
+34-7sys/dev/virtio/random/virtio_random.c
+22-3sys/amd64/amd64/machdep.c
+10-0sys/dev/virtio/pci/virtio_pci_modern.c
+1-0tests/sys/file/Makefile
+208-105 files

HardenedBSD/src 769c49d — secure/lib/libcrypto/engines Makefile.inc Version.map

openssl: export only the engine entry points

Upstream links every dynamic engine with a version script,
engines/<name>.ld, that exports bind_engine and v_check and makes
everything else local.  FreeBSD's engines had no version script, so
they exported every global symbol, including _init and _fini.
loader_attic.so compiles its own copy of crypto/pem/pvkfmt.c and so
also exported 21 of its functions; 14 of them (b2i_*, i2b_*) have the
same names as public libcrypto functions.

Add one Version.map for all engines, the same as upstream's, and use it
from engines/Makefile.inc.

The engines are loaded only with dlopen(), and libcrypto looks up only
bind_engine and v_check, so hiding the other symbols does not affect
any consumer.

Tested via tinderbox: capi.so, devcrypto.so and loader_attic.so link
with --no-undefined-version and export only bind_engine and v_check.

    [8 lines not shown]
DeltaFile
+6-0secure/lib/libcrypto/engines/Version.map
+3-0secure/lib/libcrypto/engines/Makefile.inc
+9-02 files

HardenedBSD/src 56741ec — secure/lib/libcrypto/engines/loader_attic Makefile, secure/lib/libcrypto/engines/padlock Makefile

openssl: fix engine defines to match upstream

Two engine Makefiles define different macros from upstream's
engines/build.info:

- padlock: engines/e_padlock.c builds the engine only when PADLOCK_ASM
  is defined.  Upstream defines it on x86 and x86_64, but our Makefile
  never did, so padlock.so has been a stub whose bind_engine() returns
  0 and the e_padlock-x86*.S code it links was never called.  Define
  PADLOCK_ASM on amd64 and i386, where that asm is built.

- loader_attic: upstream defines OPENSSL_NO_PROVIDER_CODE; the Makefile
  had OPENSSL_NO_PROVIDER_CORE.  No source tests either name, so the
  build does not change; this only follows upstream.

Found by comparing per-file compile flags against an upstream 3.5.9
build.  Checked by preprocessing e_padlock.c for amd64 and i386:
COMPILE_PADLOCKENG is now defined.


    [5 lines not shown]
DeltaFile
+1-1secure/lib/libcrypto/engines/loader_attic/Makefile
+2-0secure/lib/libcrypto/engines/padlock/Makefile
+3-12 files

HardenedBSD/src 89d6dde — lib/libsys poll.2

libsys/poll.2: bump .Dd for the prior change

MFC after:      1 week
MFC with:       72a80a4733b2
DeltaFile
+1-1lib/libsys/poll.2
+1-11 files

HardenedBSD/src 72a80a4 — lib/libsys poll.2

poll.2: document that poll is not restarted after signals

Signed-off-by: _ov4 <ov4 at ov4.org>
Reviewed-by: ngie
Pull-Request: https://github.com/freebsd/freebsd-src/pull/2526
DeltaFile
+12-0lib/libsys/poll.2
+12-01 files

HardenedBSD/src 3c6c65b — tests/sys/file Makefile fork_lowfd_test.c

tests/sys/file: add tests for the lowest fd after fork

fdcopy() skips plain kqueues and close-on-fork descriptors when it
copies the table into the child.  Check that dup(2) in the child still
returns the lowest unused descriptor, both when the skipped descriptor
is the lowest free slot and when it sits above an existing hole.

Test cases:

  kqueue_no_hole      a plain kqueue is the lowest descriptor; the
                      child's dup() reuses its slot
  kqueue_two          two adjacent plain kqueues; the child's dup()
                      returns the lower one
  kqueue_above_hole   a plain kqueue sits above a closed descriptor;
                      the child's dup() returns the hole
  kqueue_cponfork     a KQUEUE_CPONFORK kqueue is copied; the child's
                      dup() returns the next slot
  clofork_no_hole     an O_CLOFORK descriptor is the lowest one; the
                      child's dup() reuses its slot

    [14 lines not shown]
DeltaFile
+141-0tests/sys/file/fork_lowfd_test.c
+1-0tests/sys/file/Makefile
+142-02 files

HardenedBSD/src 1a10bff — sys/dev/virtio/random virtio_random.c

virtio_random: defer first enqueue until after DRIVER_OK

According to the virtio spec:

> The driver MUST NOT send any buffer available notifications to the
> device before setting DRIVER_OK.

DRIVER_OK isn't set until after attach completes, so defer the first
enqueue.  We haven't found any problems as a result of this to the best
of my knowledge: q35 and other devices that we *have* been used with
will apparently check when we go DRIVER_OK.

Tested with q35 virtio-random, which still works.

Reported by:    llm-postcr
Reviewed by:    kfv, markj
Fixes:  f1c5a2e3a62505 ("virtio_random: Pipeline fetching the data")
Sponsored by:   Stormshield
Sponsored by:   Klara, Inc.

    [2 lines not shown]
DeltaFile
+16-2sys/dev/virtio/random/virtio_random.c
+16-21 files

HardenedBSD/src ffa1d4d — sys/dev/virtio/pci virtio_pci_modern.c

virtio_pci_modern: enable virtqueues before completing attach

Most of our drivers setup interrupt(s) and virtqueues are enabled at
that time, but nothing will currently enable them for devices that we're
only going to poll.  This most notably affects virtio-random, and the
problem can be observed with qemu's q35 emulation and a random device
attached.  The q35 implementation ignores the ring unless it's enabled,
so vtrnd_harvest() will consistently EAGAIN rather than contribute
anything of value, but with this patch it becomes functional.

This can be reproduced with a qemu invocation like so:

qemu-system-x86_64 -machine q35,accel=tcg -cpu max -smp 2 -m 2G \
  -drive file=FreeBSD-16.0-CURRENT-amd64-ufs.qcow2,if=virtio \
  -device pcie-root-port,id=rp1,bus=pcie.0,chassis=1 \
  -object rng-random,id=rng0,filename=/dev/urandom \
  -device virtio-rng-pci,rng=rng0,bus=rp1 \
  -display curses


    [5 lines not shown]
DeltaFile
+10-0sys/dev/virtio/pci/virtio_pci_modern.c
+10-01 files

HardenedBSD/src ddfd685 — sys/dev/virtio/random virtio_random.c

virtio_random: stop on detach, don't poll

If the device is hung, then polling will block the detach and hang us.
Stop it and drain the queue instead.  This fixes a hang on detach in
some circumstances without the upcoming virtio_pci_modern fix.

Reviewed by:    bnovkov, kfv
Sponsored by:   Stormshield
Sponsored by:   Klara, Inc.

(cherry picked from commit cce522853aae3da45b131c2522dd2510edf083e7)
DeltaFile
+9-3sys/dev/virtio/random/virtio_random.c
+9-31 files

HardenedBSD/src 45819a7 — sys/dev/virtio/random virtio_random.c

virtio_random: avoid using vtrnd_detach in the failure path

On the off chance that we discover more than one virtio-random device,
the second one will deregister the global instance or trip an invariant
when it fails to attach and calls vtrnd_detach().

We don't have that many resources to free, so just inline those.  This
is purely a hygiene thing, we haven't seen an instance of this in the
wild (to my knowledge).

Reviewed by:    bnovkov, kfv
Sponsored by:   Stormshield
Sponsored by:   Klara, Inc.

(cherry picked from commit 26ba71f73e8914ecd9e5b1e7bb864fee41158d04)
DeltaFile
+9-2sys/dev/virtio/random/virtio_random.c
+9-21 files

HardenedBSD/src ec66296 — sys/compat/linux linux_file.c

linux: Bound native getdents and getdents64 batches

linux_getdents() and linux_getdents64() round their native read size up
to DEV_BSIZE before converting entries. For an unaligned caller buffer,
the native batch can contain more entries than fit in the Linux buffer.
Conversion then returns EINVAL even after copying complete entries,
and the native read has already advanced the directory position.

For counts of at least DEV_BSIZE, use min(args->count, MAXBSIZE) instead.
A 768-byte request, such as rustix's initial directory read, now uses a
768-byte native buffer rather than 1024. The converted Linux dirent and
dirent64 records are no larger than their native counterparts, so the
whole translated batch fits. Returning a short batch is allowed, and
consuming the whole native batch avoids needing to rewind the directory
position.

Keep the existing sizing for counts below DEV_BSIZE. This fixes the
oversized-batch case in both getdents interfaces, including legacy
getdents for 32-bit and 64-bit callers. The remaining small-buffer,

    [8 lines not shown]
DeltaFile
+18-2sys/compat/linux/linux_file.c
+18-21 files

HardenedBSD/src 91bcaea — sys/amd64/amd64 machdep.c

amd64: make hw.splitlock_force adjustable at runtime

(cherry picked from commit 57bc1e1c2f4c01953336bdf03743e30f4ba12cdc)
DeltaFile
+22-3sys/amd64/amd64/machdep.c
+22-31 files

HardenedBSD/src edaa6ba — sys/opencrypto cryptodev.c

cryptodev: zero key material before freeing it

The /dev/crypto cipher and MAC keys are copied from userland and
released with free(), leaving the key bytes in freed kernel memory.
Use zfree() so the key material is cleared on session teardown and on
the setup error path.

Reviewed by:    markj
MFC after:      1 week
Differential Revision:  https://reviews.freebsd.org/D61324
DeltaFile
+4-4sys/opencrypto/cryptodev.c
+4-41 files

HardenedBSD/src 04a3a6e — sys/powerpc/powerpc cpu.c

powerpc/idle: Set 'RL' field in PSSCR on POWER9

The POWER9 does not do automatic state transitions when idling, so the
'MTL' field (Maximum Transition Level) is ignored.  Thus, setting '0'
for the 'RL' field (Requested Level) as was done means it
doesn't transition to any power saving level.  To fix this, set both the
'MTL' and the 'RL' fields to the same level.

On a Talos II at idle this drops the reported temperatures by ~10-15%.

MFC after:      3 days
DeltaFile
+2-1sys/powerpc/powerpc/cpu.c
+2-11 files

HardenedBSD/src f22d659 — contrib/elftoolchain/libdwarf dwarf.h dwarf_dump.c

libdwarf: standard DWARF 5 form names, DW_LANG_C17 and C23

7bb441c86678 added the fixed-size string and address index forms
0x25 to 0x2c as DW_FORM_ref_strx1..4 and DW_FORM_ref_addrx1..4; the
standard (DWARF 5, table 7.6) names them DW_FORM_strx1..4 and
DW_FORM_addrx1..4, with no "ref".  Rename them, keep the old spellings
as aliases since the header is installed, and update dwarf_dump.c's
form names accordingly.  Add DW_LANG_C17 (0x2c) and DW_LANG_C23 (0x3e),
which clang emits for -std=c17 and -std=c23 units.  ctfconv(1) needs
all of these; it carried them in a private header until now.

Reviewed by:    markj, emaste
MFC after:      1 week
Differential Revision: https://reviews.freebsd.org/D61154
DeltaFile
+16-16contrib/elftoolchain/libdwarf/dwarf_dump.c
+19-8contrib/elftoolchain/libdwarf/dwarf.h
+35-242 files

HardenedBSD/src ea623d9 — sys/crypto/openssl/aarch64 sm4-armv8.S vpsm4_ex-armv8.S, sys/crypto/openssl/i386 rc5-586.S cast-586.S

openssl: stop generating asm that nothing builds

Makefile.asm generated eight perlasm outputs that neither libcrypto nor
the kernel builds. Additionally, upstream does not build them for these
architectures with FreeBSD's configuration:

- aarch64: ecp_sm2p256-armv8, sm3-armv8, sm4-armv8, vpsm4-armv8 and
  vpsm4_ex-armv8.  SM2, SM3 and SM4 are disabled (disable-sm2/sm3/sm4).
- i386: cast-586 (upstream's x86 configuration uses the C CAST code)
  and rc5-586 (RC5 is disabled by default).
- powerpc: aes-gcm-ppc.  Upstream builds it only for 64-bit
  little-endian; libcrypto and ossl(4) use it only on powerpc64 and
  powerpc64le, whose copies stay.

Remove them from Makefile.asm and delete the generated files, so the
next vendor import does not regenerate them.  If one of these algorithms
is ever enabled, add its script back to Makefile.asm and run "make
buildasm".


    [10 lines not shown]
DeltaFile
+0-5,021sys/crypto/openssl/aarch64/vpsm4-armv8.S
+0-4,543sys/crypto/openssl/aarch64/vpsm4_ex-armv8.S
+0-2,002sys/crypto/openssl/i386/cast-586.S
+0-1,264sys/crypto/openssl/i386/rc5-586.S
+0-1,093sys/crypto/openssl/aarch64/sm4-armv8.S
+0-988sys/crypto/openssl/powerpc/aes-gcm-ppc.S
+0-14,9113 files not shown
+3-16,2769 files

HardenedBSD/src 1a65fd9 — lib/libc/string bstring.3

Revert "bstring.3: no cross reference to self"

This reverts commit ef7d29b0df91d32c0b880796acd969a0a00ecf47.
DeltaFile
+9-1lib/libc/string/bstring.3
+9-11 files