]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agoMerge commit 'ee914ef902ae018bd4f67192832120f9bf05651f' into new_merge
Simon J. Gerraty [Fri, 25 Jun 2021 21:31:14 +0000 (14:31 -0700)]
Merge commit 'ee914ef902ae018bd4f67192832120f9bf05651f' into new_merge

(cherry picked from commit b0c40a00a67f611868fc0f10bde6b28eb75931be)

2 years agoHave fsck_ffs(8) properly correct superblock check-hash failures.
Kirk McKusick [Wed, 16 Feb 2022 01:09:07 +0000 (17:09 -0800)]
Have fsck_ffs(8) properly correct superblock check-hash failures.

cherry pick cleanups from commit c0bfa109b942659f609b7e2bf3ba042ec0cb3f9d

PR:           245916

2 years agoHave fsck_ffs(8) properly correct superblock check-hash failures.
Kirk McKusick [Fri, 4 Feb 2022 19:46:36 +0000 (11:46 -0800)]
Have fsck_ffs(8) properly correct superblock check-hash failures.

(cherry picked from commit c0bfa109b942659f609b7e2bf3ba042ec0cb3f9d)

PR:           245916

2 years agonfsd: Reply NFSERR_SEQMISORDERED for bogus seqid argument
Rick Macklem [Wed, 9 Feb 2022 23:17:50 +0000 (15:17 -0800)]
nfsd: Reply NFSERR_SEQMISORDERED for bogus seqid argument

The ESXi NFSv4.1 client bogusly sends the wrong value
for the csa_sequence argument for a Create_session operation.
RFC8881 requires this value to be the same as the sequence
reply from the ExchangeID operation most recently done for
the client ID.

Without this patch, the server replies NFSERR_STALECLIENTID,
which is the correct response for an NFSv4.0 SetClientIDConfirm
but is not the correct error for NFSv4.1/4.2, which is
specified as NFSERR_SEQMISORDERED in RFC8881.
This patch fixes this.

This change does not fix the issue reported in the PR, where
the ESXi client loops, attempting ExchangeID/Create_session
repeatedly.

PR: 261291

(cherry picked from commit 17a56f3fabdfacb62f6d8858643cdb1861c8c1b5)

2 years agonfsd: Allow file owners to perform Open(Delegate_cur)
Rick Macklem [Wed, 2 Feb 2022 22:10:16 +0000 (14:10 -0800)]
nfsd: Allow file owners to perform Open(Delegate_cur)

Commit b0b7d978b6a8 changed the NFSv4 server's default
behaviour to check the file's mode or ACL for permission to
open the file, to be Linux and Solaris compatible.
However, it turns out that Linux makes an exception for
the case of Claim_delegate_cur(_fh).

When a NFSv4 client is returning a delegation, it must
acquire Opens against the server to replace the ones
done locally in the client.  The client does this via
an Open operation with Claim_delegate_cur(_fh).  If
this operation fails, due to a change to the file's
mode or ACL after the delegation was issued, the
client does not have any way to retain the open.

As such, the Linux client allows the file's owner
to perform an Open with Claim_delegate_cur(_fh)
no matter what the mode or ACL allows.

This patch makes the FreeBSD server allow this case,
to be Linux compatible.

This patch only affects the case where delegations
are enabled, which is not the default.

(cherry picked from commit e2fe58d61b7ca95cbe87ce841a87c9ae8cecb47b)

2 years agopciconf: Fix PCIS_CRYPTO_ENTERTAIN copy/paste.
Alexander Motin [Wed, 9 Feb 2022 20:56:30 +0000 (15:56 -0500)]
pciconf: Fix PCIS_CRYPTO_ENTERTAIN copy/paste.

Submitted by:   Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after: 1 week

(cherry picked from commit c04506fd4cc82cf0715142b5927de69a425086ba)

2 years agosnd_hda: Add some ATI HDMI codec IDs.
Alexander Motin [Wed, 9 Feb 2022 21:27:15 +0000 (16:27 -0500)]
snd_hda: Add some ATI HDMI codec IDs.

Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after: 1 week

(cherry picked from commit 98d59d2e0d8c61d145796b723021a90daf4439d9)

2 years agovt: fix splash_cpu logos use of vd_drawrect
Stefan Grundmann [Wed, 9 Feb 2022 03:15:53 +0000 (22:15 -0500)]
vt: fix splash_cpu logos use of vd_drawrect

In the (extremely unlikely) case of vd->vd_height ==
vt_logo_sprite_height the vd_drawrect code would write outside of
frame-buffer memory.

MFC after: 1 week
Reviewed by: cem
Differential Revision: https://reviews.freebsd.org/D34220

(cherry picked from commit 06296f77c5bc5ec1710a28b68b9410d192163087)

2 years agoIn GEOM debugging output, show consumer for cloned and duplicated bio's.
Kirk McKusick [Mon, 31 Jan 2022 01:20:10 +0000 (17:20 -0800)]
In GEOM debugging output, show consumer for cloned and duplicated bio's.

(cherry picked from commit 85f7e9a4f0393277b85a247543f71700c5eebb1f)

2 years agoufs: handle LoR between snap lock and vnode lock
Kirk McKusick [Fri, 28 Jan 2022 07:00:51 +0000 (23:00 -0800)]
ufs: handle LoR between snap lock and vnode lock

(cherry picked from commit ddf162d1d15f63e871fa1e44334c9461772b7f7a)

Differential Revision: https://reviews.freebsd.org/D33946

2 years agofreebsd-update: improve BE creation feature
Kyle Evans [Sat, 12 Feb 2022 21:36:24 +0000 (15:36 -0600)]
freebsd-update: improve BE creation feature

This addresses one nit and one bug in the BE creation feature of
freebsd-update:

The nit addressed is that it currently only names the BEs after the
userland version, but the kernel version may be higher.  After this
change, we request both and pass them through sort(1) to choose the
highest.  This is especially helpful if a freebsd-update patch touched
one but not the other.

The bug fixed is that roots updated that are not located at '/', e.g.,
by using -b or -j, will no longer create boot environments
automatically.  There's a very low chance these will actually change the
BE in any meaningful way, anyways.  It could make sense in the future
to allow an argument-override to create the BE anyways if someone comes
up with a non-standard setup, e.g., where a jail is an important part of
their boot environment on an appliance or some such setup.

Half of this patch is submitted by delphij@, the other half kevans@.

PR: 261446

(cherry picked from commit e01e8f911b935eabcc35b4d121951e4e21042ee5)

2 years agolibc binuptime(): use the right function to get the most significant bit index
Konstantin Belousov [Tue, 8 Feb 2022 19:13:40 +0000 (21:13 +0200)]
libc binuptime(): use the right function to get the most significant bit index

PR: 261781

(cherry picked from commit a1f9326607dea5ab6979935e3ca2d7402dcc7cc1)

2 years agoFix gzip compressed core dumps on big endian architectures
Justin Hibbits [Thu, 10 Feb 2022 15:21:36 +0000 (09:21 -0600)]
Fix gzip compressed core dumps on big endian architectures

The gzip trailer words (size and CRC) are both little-endian per the spec.

MFC after: 3 days
Sponsored by: Juniper Networks, Inc.

(cherry picked from commit 6db44b0158c37f2206f2c4ea7f29f5b774389e54)

2 years agostrftime.3: Fix a typo and use St for standards
Mateusz Piotrowski [Mon, 7 Feb 2022 14:14:47 +0000 (15:14 +0100)]
strftime.3: Fix a typo and use St for standards

MFC after: 1 week

(cherry picked from commit 407391740865106bc8ba2186d936f94815d0cc12)

2 years agoocs_fc: Fix a possible Null pointer dereference
Ram Kishore Vegesna [Wed, 9 Feb 2022 10:14:12 +0000 (15:44 +0530)]
ocs_fc: Fix a possible Null pointer dereference

Fix a possible Null pointer dereference in ocs_hw_get_profile_list_cb()

PR: 261453
Reported by: lwhsu

MFC after: 3 days

(cherry picked from commit 7bf31432fd03e2a5a815d1cc81de9a7b1ea3d3ca)

2 years agoucred.9: fix typo
Johan Jansson [Fri, 11 Feb 2022 16:46:37 +0000 (18:46 +0200)]
ucred.9: fix typo

PR: 261889

(cherry picked from commit d4b0fa45dc1531fafb1f3f1a1956056597a4722c)

2 years agoFix the spelling of '*/' in the vnic driver
Andrew Turner [Tue, 27 Jul 2021 19:43:08 +0000 (19:43 +0000)]
Fix the spelling of '*/' in the vnic driver

Sponsored by: The FreeBSD Foundation

(cherry picked from commit c007408c245b7aff0f203b021e70f263e57d5173)

2 years agoAPEI: Make sure event data fit into the buffer.
Alexander Motin [Thu, 3 Feb 2022 20:18:31 +0000 (15:18 -0500)]
APEI: Make sure event data fit into the buffer.

There seem to be systems returning some garbage here.  I still don't
know why, but at least I hope this check fix indefinite printf loop.

MFC after: 2 weeks

(cherry picked from commit 3b248a2113829e43c382f5e2b1f85c626c01f024)

2 years agong pppoe(4): Add the required NET_EPOCH section to the hook
Aleksandr Fedorov [Wed, 9 Feb 2022 19:00:50 +0000 (22:00 +0300)]
ng pppoe(4): Add the required NET_EPOCH section to the hook
disconnection function.

Disconnecting hooks are called outside of NET_EPOCH, but
ng_pppoe_disconnect() calls NG_SEND_DATA_ONLY() which should be called
in NET_EPOCH.

PR: 257067
Reported by: niels=freebsd@bakker.net
Reviewed by: vmaffione (mentor), glebius, donner
Approved by: vmaffione (mentor), glebius, donner
Sponsored by: vstack.com
Differential Revision: https://reviews.freebsd.org/D34185

(cherry picked from commit b27e6e91d0ad1f87b296f7583d4f5d938d7a997c)

2 years agonetmap: fix LOR in iflib_netmap_register
Vincenzo Maffione [Fri, 14 Jan 2022 21:09:04 +0000 (21:09 +0000)]
netmap: fix LOR in iflib_netmap_register

In iflib_device_register(), the CTX_LOCK is acquired first and then
IFNET_WLOCK is acquired by ether_ifattach(). However, in netmap_hw_reg()
we do the opposite: IFNET_RLOCK is acquired first, and then CTX_LOCK
is acquired by iflib_netmap_register(). Fix this LOR issue by wrapping
the CTX_LOCK/UNLOCK calls in iflib_device_register with an additional
IFNET_WLOCK. This is safe since the IFNET_WLOCK is recursive.

MFC after: 1 month

(cherry picked from commit e0e12405285b61a724c646b8f8e99e3ec775291e)

2 years agoipsec(4): Fix a few typos in error messages
Gordon Bergling [Sun, 6 Feb 2022 12:43:42 +0000 (13:43 +0100)]
ipsec(4): Fix a few typos in error messages

- s/receieve/receive/

(cherry picked from commit ecc467ebad065299804ca556e86c0c5ebf060700)

2 years agoInstall ipmi man page also on arm64
Ed Maste [Sat, 29 May 2021 20:49:20 +0000 (16:49 -0400)]
Install ipmi man page also on arm64

Fixes: 40d0971bbe5d ("arm64: enable build of the ipmi module")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 62174eaf460544c7645172cdde2c9204dcfd7321)

2 years agongatm: remove one of doubled semicolons
Ed Maste [Mon, 30 Aug 2021 15:38:51 +0000 (11:38 -0400)]
ngatm: remove one of doubled semicolons

Discussed with: harti

(cherry picked from commit 0637070b5bca4691bf54c5985a74f4d7888050dc)

2 years agomgb: Connect if_mgb module to the build
Ed Maste [Tue, 28 Sep 2021 16:58:40 +0000 (12:58 -0400)]
mgb: Connect if_mgb module to the build

It supports the following Microchip devices:

LAN7430 PCIe Gigabit Ethernet controller with PHY
LAN7431 PCIe Gigabit Ethernet controller with RGMII interface

The driver has a number of caveats and limitations, but is functional.

Relnotes: Yes
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 543df609072fe49079c36d6bee510e1645edde3a)

2 years agovnic: add TODO list
Ed Maste [Tue, 27 Jul 2021 21:51:21 +0000 (17:51 -0400)]
vnic: add TODO list

- non-promisc mode
- multicast filter support

Also drop ARM64TODO comments; this is an issue with this specific
driver, not a general arm64 issue.

PR: 223575
PR: 223573

(cherry picked from commit 941650aae9762293f4c63788ddb17e0114828813)
(cherry picked from commit 29e9b487c1d427409a8bf1f893bc71a57c76f4b0)

2 years agoAnnotate geom_md with MODULE_VERSION
Kyle Evans [Thu, 10 Feb 2022 06:15:29 +0000 (00:15 -0600)]
Annotate geom_md with MODULE_VERSION

This was missed in 74d6c131cbe2 where other geom modules were annotated
with MODULE_VERSION.  Again, the problem is the same: we can't detect
that geom_md is loaded into the kernel without it.

This was noticed in release builds on the cluster; mdconfig attempts to
load geom_md because it can't detect it in the kernel, but the cluster
config includes md(4) and does not build the kmod.  This problem would
have been masked on hosts with the kmod built, as the kmod attempts to
register the g_md module and fails.  With this commit, mdconfig would
not even try to load it again.

(cherry picked from commit b9c92d631cfb06c12b0d2d9ad29a9f3f0b856237)

2 years agostyle.mdoc.5: Document the conventions for -width
Mateusz Piotrowski [Sat, 29 Jan 2022 21:23:49 +0000 (22:23 +0100)]
style.mdoc.5: Document the conventions for -width

Reviewed by: debdrup
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D33394

(cherry picked from commit 79afae3b3f245ffa79726ae097cc843628ae9d92)

2 years agoipheth.4: Simplify output filtering example
Mateusz Piotrowski [Sat, 29 Jan 2022 21:16:50 +0000 (22:16 +0100)]
ipheth.4: Simplify output filtering example

MFC after: 2 weeks

(cherry picked from commit 60401b3883149cfa8ab8158523282715441be66e)

2 years agoipheth.4: Fix examples
Mateusz Piotrowski [Sat, 29 Jan 2022 21:13:42 +0000 (22:13 +0100)]
ipheth.4: Fix examples

It is now necessary to use the -d flag for some of the usbconfig(8)
invocations.

MFC after: 2 weeks

(cherry picked from commit d0b92c068e36bbaf06b6a7dc00cfc7d275878b6c)

2 years agoRemove device lio from i386's LINT-NOIP
Dimitry Andric [Tue, 8 Feb 2022 18:53:52 +0000 (19:53 +0100)]
Remove device lio from i386's LINT-NOIP

This fixes link errors for the LINT-NOIP kernel on i386:

```
ld: error: undefined symbol: tcp_lro_flush_all
>>> referenced by lio_droq.c
>>>               lio_droq.o:(lio_droq_process_packets)

ld: error: undefined symbol: tcp_lro_rx
>>> referenced by lio_core.c
>>>               lio_core.o:(lio_push_packet)

ld: error: undefined symbol: tcp_lro_init
>>> referenced by lio_main.c
>>>               lio_main.o:(lio_attach)

ld: error: undefined symbol: tcp_lro_free
>>> referenced by lio_main.c
>>>               lio_main.o:(lio_attach)
>>> referenced by lio_main.c
>>>               lio_main.o:(lio_destroy_nic_device)
*** [kernel] Error code 1
```

MFC after: 3 days

(cherry picked from commit 14a15342bbc88906c97fbf84553eb5c6de8295ca)

2 years agotty_info: Avoid warning by using logical instead of bitwise operators
Dimitry Andric [Sun, 6 Feb 2022 17:41:20 +0000 (18:41 +0100)]
tty_info: Avoid warning by using logical instead of bitwise operators

Since TD_IS_RUNNING() and TS_ON_RUNQ() are defined as logical
expressions involving '==', clang 14 warns about them being checked with
a bitwise operator instead of a logical one:

```
sys/kern/tty_info.c:124:9: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
        runa = TD_IS_RUNNING(td) | TD_ON_RUNQ(td);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                 ||
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
sys/kern/tty_info.c:124:9: note: cast one or both operands to int to silence this warning
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
sys/kern/tty_info.c:129:9: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
        runb = TD_IS_RUNNING(td2) | TD_ON_RUNQ(td2);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  ||
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
sys/kern/tty_info.c:129:9: note: cast one or both operands to int to silence this warning
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
```

Fix this by using logical operators instead. No functional change
intended.

Reviewed by: cem, emaste, kevans, markj
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D34186

(cherry picked from commit 7d8a4eb943a907a92dd400432c3c3adcbd93dad9)

2 years agoDisable clang 14 warning about bitwise operators in one more place
Dimitry Andric [Thu, 10 Feb 2022 18:48:31 +0000 (19:48 +0100)]
Disable clang 14 warning about bitwise operators in one more place

Follow up 5f2aca839400, where I missed the -Werror warning still being
emitted in libsa.

Fixes: 5f2aca839400
MFC after: 3 days

(cherry picked from commit 74f7afdfd2f5c1beaed7af1bfe89b8b520744500)

2 years agoDisable clang 14 warning about bitwise operators in zstd
Dimitry Andric [Tue, 8 Feb 2022 20:46:03 +0000 (21:46 +0100)]
Disable clang 14 warning about bitwise operators in zstd

Parts of zstd, used in openzfs and other places, trigger a new clang 14
-Werror warning:

```
sys/contrib/zstd/lib/decompress/huf_decompress.c:889:25: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
                        (BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished)
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

While the warning is benign, it should ideally be fixed upstream and
then vendor-imported, but for now silence it selectively.

MFC after: 3 days

(cherry picked from commit 5f2aca83940097d7d23b4137073fb601f8e74232)

2 years agox86 atomic.h: remove obsoleted comment
Konstantin Belousov [Thu, 3 Feb 2022 17:46:22 +0000 (19:46 +0200)]
x86 atomic.h: remove obsoleted comment

(cherry picked from commit 9596b349bb57e50a2baec8497ced9f712f08f147)

2 years agox86 atomics: use lock prefix unconditionally
Konstantin Belousov [Thu, 3 Feb 2022 09:51:36 +0000 (11:51 +0200)]
x86 atomics: use lock prefix unconditionally

(cherry picked from commit 9c0b759bf9b520537616d026f21a0a98d70acd11)

2 years agox86 atomic.h: cleanup comments for preprocessor directives
Konstantin Belousov [Thu, 3 Feb 2022 09:25:03 +0000 (11:25 +0200)]
x86 atomic.h: cleanup comments for preprocessor directives

(cherry picked from commit cbf999e75d61c6efadeed8d32212eefa4dfb3dcb)

2 years agomlx5en: Make sure the NIC IP addresses are written to firmware on link up.
Hans Petter Selasky [Thu, 10 Feb 2022 10:12:21 +0000 (11:12 +0100)]
mlx5en: Make sure the NIC IP addresses are written to firmware on link up.

Fixes e059c120b4223fd5ec3af9def21c0519f439fe57 .

PR: 261746
Sponsored by: NVIDIA Networking

(cherry picked from commit 04f407a3e5e7bf452768201ace260b575f1a7924)

2 years agoUse CPUID leaf 0x40000010 for local APIC freq
Colin Percival [Sun, 9 Jan 2022 00:59:31 +0000 (16:59 -0800)]
Use CPUID leaf 0x40000010 for local APIC freq

Some VM systems announce the frequency of the local APIC via the
CPUID leaf 0x40000010.  Using this allows us to boot slightly
faster by avoiding the need for timer calibration.

Reviewed by: markj
Sponsored by: https://www.patreon.com/cperciva

(cherry picked from commit de1292c6ff8a445fd453effba8cc23c38cea223f)

2 years agoTSC: Use 0x40000010 CPUID leaf for all VM types
Colin Percival [Tue, 4 Jan 2022 07:28:36 +0000 (23:28 -0800)]
TSC: Use 0x40000010 CPUID leaf for all VM types

While this CPUID leaf was originally only used by VMWare, other
hypervisors now also use it to announce the TSC frequency to guests.

This speeds up the boot process by 100 ms in EC2 and other systems,
by allowing the early calibration DELAY to be skipped.

Reviewed by: markj
Sponsored by: https://www.patreon.com/cperciva

(cherry picked from commit 4a432614f68cf35879dbb4ebef089f5b8db95334)

2 years agoDetect CPU type before asking VMWare for TSC freq
Colin Percival [Tue, 4 Jan 2022 07:00:39 +0000 (23:00 -0800)]
Detect CPU type before asking VMWare for TSC freq

This allows us to set tsc_is_invariant and select appropriately
fenced versions of RDTSC based on the CPU type.

Reviewed by: markj
Sponsored by: https://www.patreon.com/cperciva

(cherry picked from commit fd980feb574d0924918b42cd449cedf557dfb9e0)

2 years agox86: Speed up clock calibration
Colin Percival [Mon, 10 Jan 2022 01:22:20 +0000 (17:22 -0800)]
x86: Speed up clock calibration

Prior to this commit, the TSC and local APIC frequencies were calibrated
at boot time by measuring the clocks before and after a one-second sleep.
This was simple and effective, but had the disadvantage of *requiring a
one-second sleep*.

Rather than making two clock measurements (before and after sleeping) we
now perform many measurements; and rather than simply subtracting the
starting count from the ending count, we calculate a best-fit regression
between the target clock and the reference clock (for which the current
best available timecounter is used). While we do this, we keep track
of an estimate of the uncertainty in the regression slope (aka. the ratio
of clock speeds), and stop measuring when we believe the uncertainty is
less than 1 PPM.

In order to avoid the risk of aliasing resulting from the data-gathering
loop synchronizing with (a multiple of) the frequency of the reference
clock, we add some additional spinning depending upon the iteration number.

For numerical stability and simplicity of implementation, we make use of
floating-point arithmetic for the statistical calculations.

On the author's Dell laptop, this reduces the time spent in calibration
from 2000 ms to 29 ms; on an EC2 c5.xlarge instance, it is reduced from
2000 ms to 2.5 ms.

Reviewed by: bde (previous version), kib
Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D33802

(cherry picked from commit c2705ceaeb09d8579661097fd358ffb5defb5624)

2 years agoGEOM: Set G_CF_DIRECT_SEND/RECEIVE for taste consumers.
Alexander Motin [Sun, 30 Jan 2022 02:59:03 +0000 (21:59 -0500)]
GEOM: Set G_CF_DIRECT_SEND/RECEIVE for taste consumers.

All I/O requests through the taste consumers are synchronous, done
with g_read_data() and without any locks held.  It makes no sense
to delegate the I/O to g_down/g_up threads.

This removes many of context switches during disk retaste.

MFC after: 2 weeks

(cherry picked from commit 10ae42ccbde4fe7c8c9de3d54f3c0d63457a1a68)

2 years agoglabel: Set G_CF_DIRECT_SEND/RECEIVE for taste consumer.
Alexander Motin [Fri, 28 Jan 2022 19:22:41 +0000 (14:22 -0500)]
glabel: Set G_CF_DIRECT_SEND/RECEIVE for taste consumer.

All I/O requests through the taste consumer are synchronous, done
with g_read_data() and without any locks held.  It makes no sense
to delegate the I/O to g_down/g_up threads.

This removes many of context switches during disk retaste.

MFC after: 2 weeks

(cherry picked from commit 29998bf2ac4cc3ac49827336655bdbcb755eeffc)

2 years agoGEOM: Relax direct dispatch for GEOM threads.
Alexander Motin [Fri, 28 Jan 2022 19:12:29 +0000 (14:12 -0500)]
GEOM: Relax direct dispatch for GEOM threads.

The only cases when direct dispatch does not make sense is for I/O
submission from down thread and for completion from up thread.  In
all other cases, if both consumer and producer are OK about it, we
can save on context switches.

MFC after: 2 weeks

(cherry picked from commit ffc1cc95e78ec05a3e1a0aed869e33a44d9f6641)

2 years agograid: Set G_CF_DIRECT_SEND for task consumer.
Alexander Motin [Fri, 28 Jan 2022 16:09:30 +0000 (11:09 -0500)]
graid: Set G_CF_DIRECT_SEND for task consumer.

Unlike normal consumers all taste consumer I/O is synchronous, done
with g_read_data() and without any locks held.  It makes no sense to
delegate I/O submission to g_down thread.

This should remove number of context switches during disk retaste.

MFC after: 2 weeks

(cherry picked from commit 0d8cec7658d50e4190899376330c2c1eb5d8c659)

2 years agoCTL: Fix mode page trucation on HA synchronization.
Alexander Motin [Thu, 3 Feb 2022 15:48:19 +0000 (10:48 -0500)]
CTL: Fix mode page trucation on HA synchronization.

Due to variable size of struct ctl_ha_msg_mode ctl_isc_announce_mode()
sent only first 4 bytes of modified mode page to the other HA side,
that caused its corruption there, noticeable only after failover.

I've found alike bug also in ctl_isc_announce_lun(), but there it was
sending slightly more than needed, that is a smaller problem.

MFC after: 1 week
Sponsored by: iXsystems, Inc.

(cherry picked from commit 1a8d8a3a909f906ed69cca080a6446e7295bcbbb)

2 years agosched: separate out schedinit_ap()
Kyle Evans [Tue, 2 Nov 2021 18:06:47 +0000 (13:06 -0500)]
sched: separate out schedinit_ap()

schedinit_ap() sets up an AP for a later call to sched_throw(NULL).

Currently, ULE sets up some pcpu bits and fixes the idlethread lock with
a call to sched_throw(NULL); this results in a window where curthread is
setup in platforms' init_secondary(), but it has the wrong td_lock.
Typical platform AP startup procedure looks something like:

- Setup curthread
- ... other stuff, including cpu_initclocks_ap()
- Signal smp_started
- sched_throw(NULL) to enter the scheduler

cpu_initclocks_ap() may have callouts to process (e.g., nvme) and
attempt to sched_add() for this AP, but this attempt fails because
of the noted violated assumption leading to locking heartburn in
sched_setpreempt().

Interrupts are still disabled until cpu_throw() so we're not really at
risk of being preempted -- just let the scheduler in on it a little
earlier as part of setting up curthread.

(cherry picked from commit 589aed00e36c22733d3fd9c9016deccf074830b1)

2 years agoFix a memory leak when ip_output_send() returns EAGAIN due to send tag issues
Andrew Gallatin [Thu, 27 Jan 2022 15:28:15 +0000 (10:28 -0500)]
Fix a memory leak when ip_output_send() returns EAGAIN due to send tag issues

When ip_output_send() returns EAGAIN due to issues with send tags (route
change, lagg failover, etc), it must free the mbuf. This is because
ip_output_send() was written as a wrapper/replacement for a direct
call to  if_output(), and the contract with if_output() has
historically been that it owns the mbufs once called. When
ip_output_send() failed to free mbufs, it violated this assumption
and lead to leaked mbufs.

This was noticed when using NIC TLS in combination with hardware
rate-limited connections. When seeing lots of NIC output drops
triggered ratelimit send tag changes, we noticed we were leaking
ktls_sessions, send tags and mbufs. This was due ip_output_send()
leaking mbufs which held references to ktls_sessions, which in
turn held references to send tags.

Many thanks to jbh, rrs, hselasky and markj for their help in
debugging this.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D34054
Reviewed by: hselasky, jhb, rrs
MFC after: 2 weeks

(cherry picked from commit 9ba117960e1755a693f9361e4d076630dfe13dba)

2 years agotests: add a basic test for argc == 0
Kyle Evans [Wed, 26 Jan 2022 01:22:03 +0000 (19:22 -0600)]
tests: add a basic test for argc == 0

The kernel should reject such exec()s now, early on. Instead of adding
the needed boilerplate to write a test in C, just add an -n argument for
"(n)ull argv" to the execve helper and exec this other helper that just
exits silently with argv count.

(cherry picked from commit e5b431fc0c20771a2a18cb5169d75cf337d0f1dd)

2 years agoexecve: disallow argc == 0
Kyle Evans [Tue, 25 Jan 2022 22:47:23 +0000 (16:47 -0600)]
execve: disallow argc == 0

The manpage has contained the following verbiage on the matter for just
under 31 years:

"At least one argument must be present in the array"

Previous to this version, it had been prefaced with the weakening phrase
"By convention."

Carry through and document it the rest of the way.  Allowing argc == 0
has been a source of security issues in the past, and it's hard to
imagine a valid use-case for allowing it.  Toss back EINVAL if we ended
up not copying in any args for *execve().

The manpage change can be considered "Obtained from: OpenBSD"

(cherry picked from commit 773fa8cd136a5775241c3e3a70f1997633ebeedf)
(cherry picked from commit c9afc7680f3e1f0510518de9de4264553a31aade)

2 years agobhyve/virtio: use correct device id for virtio-scsi
Robert Wing [Mon, 31 Jan 2022 18:44:47 +0000 (09:44 -0900)]
bhyve/virtio: use correct device id for virtio-scsi

Section 4.1.2.1 of the virtio spec states that the transitional PCI
device id for a scsi device is 0x1004.

Fix suggested by reporter.

PR:             259961
Reported by:    me@nanaya.pro
Reviewed by: imp, jhb
Fixes: f9c005a17f4e ("Add bhyve virtio-scsi storage backend support.")
Differential Revision: https://reviews.freebsd.org/D34103

(cherry picked from commit b4cc5d63b6112746598d21413c9800a43171da52)

2 years agocam: don't lock while handling an AC_UNIT_ATTENTION
Robert Wing [Tue, 4 Jan 2022 01:21:58 +0000 (16:21 -0900)]
cam: don't lock while handling an AC_UNIT_ATTENTION

Don't take the device_mtx lock in daasync() when handling an
AC_UNIT_ATTENTION. Instead, assert the lock is held before modifying the
periph's softc flags.

The device_mtx lock is taken in xptdevicetraverse() before daasync()
is eventually called in xpt_async_bcast().

PR:             240917, 226510, 226578
Reviewed by:    imp
MFC after:      3 weeks
Differential Revision: https://reviews.freebsd.org/D27735

(cherry picked from commit bb8441184bab60cd8a07c2b94bd6c4ae8b56ec25)

2 years agosyncache: accept packet with no SA when TCP_MD5SIG is set
Robert Wing [Sun, 9 Jan 2022 01:07:50 +0000 (16:07 -0900)]
syncache: accept packet with no SA when TCP_MD5SIG is set

When TCP_MD5SIG is set on a socket, all packets are dropped that don't
contain an MD5 signature. Relax this behavior to accept a non-signed
packet when a security association doesn't exist with the peer.

This is useful when a listen socket set with TCP_MD5SIG wants to handle
connections protected with and without MD5 signatures.

Reviewed by: bz (previous version)
Sponsored by:   nepustil.net
Sponsored by:   Klara Inc.
Differential Revision: https://reviews.freebsd.org/D33227

(cherry picked from commit eb18708ec8c7e1de6a05aba41971659549991b10)

2 years agotcpmd5: return ENOENT when security association not found
Robert Wing [Sun, 9 Jan 2022 01:07:10 +0000 (16:07 -0900)]
tcpmd5: return ENOENT when security association not found

Return ENOENT from tcp_ipsec_input() when a security association is not
found. This allows callers of TCP_MD5_INPUT() to differentiate between a
security association not found and receiving a bad signature.

Also return ENOENT from tcp_ipsec_output() for consistency.

Reviewed by: ae
Sponsored by:   nepustil.net
Sponsored by:   Klara Inc.
Differential Revision: https://reviews.freebsd.org/D33226

(cherry picked from commit 91d388119ae229702538b96d79cf76556cf0ecf4)

2 years agocompiler-rt: support ReExec() on FreeBSD
Ed Maste [Wed, 19 Jan 2022 18:08:18 +0000 (13:08 -0500)]
compiler-rt: support ReExec() on FreeBSD

Based on getMainExecutable() in llvm/lib/Support/Unix/Path.inc.
This will need a little more work for an upstream change as it must
support older FreeBSD releases that lack elf_aux_info() / AT_EXEC_PATH.

No objection: dim
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33934

(cherry picked from commit 96fe7c8ab0f65cf829619abd74ae6c126b21e15f)

2 years agossh: pass 0 to procctl(2) to operate on self
Ed Maste [Thu, 20 Jan 2022 18:41:39 +0000 (13:41 -0500)]
ssh: pass 0 to procctl(2) to operate on self

As of f833ab9dd187 procctl(2) allows idtype P_PID with id = 0 as a
shortcut for the calling process ID.  The shortcut also bypasses the
p_cansee / p_candebug test (since the process is able to act on itself.)

At present if the security.bsd.unprivileged_proc_debug sysctl is 0 then
procctl(P_PID, getpid(), ... for a process to act on itself will fail,
but procctl(P_PID, 0, ... will succeed.  This should likely be addressed
with a kernel change.

In any case the id = 0 shortcut is a tiny optimization for a process to
act on itself and allows the self-procctl to succeed, so use it in ssh.

Reported by: Shawn Webb
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33970

(cherry picked from commit 0746301c4995d9e4a82b0e5034b62e310694d1ef)
(cherry picked from commit e38610abcadbfeba5f7a32aa8a6bc8981be64908)

2 years agossh: update to OpenSSH v8.8p1
Ed Maste [Sun, 19 Dec 2021 16:02:02 +0000 (11:02 -0500)]
ssh: update to OpenSSH v8.8p1

OpenSSH v8.8p1 was motivated primarily by a security update and
deprecation of RSA/SHA1 signatures.  It also has a few minor bug fixes.

The security update was already applied to FreeBSD as an independent
change, and the RSA/SHA1 deprecation is excluded from this commit but
will immediately follow.

MFC after: 1 month
Relnotes: Yes
Sponsored by: The FreeBSD Foundation

(cherry picked from commit e9e8876a4d6afc1ad5315faaa191b25121a813d7)
(cherry picked from commit 2ffb13149c8e46cb7d7e891b237255615906dc60)

2 years agoApply fix for ThreadSanitizer false positive data race reports
Dimitry Andric [Mon, 7 Feb 2022 18:39:02 +0000 (19:39 +0100)]
Apply fix for ThreadSanitizer false positive data race reports

Merge commit 28fb22c90fe7 from llvm git (by Dimitry Andric):

  [TSan] Handle FreeBSD specific indirection of libpthread functions

  Similar to 60cc1d3218fc for NetBSD, add aliases and interceptors for the
  following pthread related functions:

  - pthread_cond_init(3)
  - pthread_cond_destroy(3)
  - pthread_cond_signal(3)
  - pthread_cond_broadcast(3)
  - pthread_cond_wait(3)
  - pthread_mutex_init(3)
  - pthread_mutex_destroy(3)
  - pthread_mutex_lock(3)
  - pthread_mutex_trylock(3)
  - pthread_mutex_unlock(3)
  - pthread_rwlock_init(3)
  - pthread_rwlock_destroy(3)
  - pthread_rwlock_rdlock(3)
  - pthread_rwlock_tryrdlock(3)
  - pthread_rwlock_wrlock(3)
  - pthread_rwlock_trywrlock(3)
  - pthread_rwlock_unlock(3)
  - pthread_once(3)
  - pthread_sigmask(3)

  In FreeBSD's libc, a number of internal aliases of the pthread functions
  are invoked, typically with an additional prefixed underscore, e.g.
  _pthread_cond_init() and so on.

  ThreadSanitizer needs to intercept these aliases too, otherwise some
  false positive reports about data races might be produced.

  Reviewed By: dvyukov

  Differential Revision: https://reviews.llvm.org/D119034

MFC after: 3 days

(cherry picked from commit 1c21bfb1b1a368f9833b9fb84ed323eeb58c5d4c)

2 years agombuf(9): Assert receive mbufs don't carry a send tag.
Hans Petter Selasky [Wed, 26 Jan 2022 11:13:53 +0000 (12:13 +0100)]
mbuf(9): Assert receive mbufs don't carry a send tag.

Else we would start leaking reference counts.

Discussed with: jhb@
Sponsored by: NVIDIA Networking

(cherry picked from commit 17cbcf33c3b6d0361d71bdb00b8633ec9bb5ae53)

2 years agombuf(9): Properly declare some function macros when debugging is disabled.
Hans Petter Selasky [Wed, 26 Jan 2022 11:00:12 +0000 (12:00 +0100)]
mbuf(9): Properly declare some function macros when debugging is disabled.

No functional change intended.

Sponsored by: NVIDIA Networking

(cherry picked from commit a6d45243233ccd26940df7fed127357cdc2d6b75)

2 years agortwn(4): Add new USB ID.
Hans Petter Selasky [Tue, 11 Jan 2022 20:18:50 +0000 (21:18 +0100)]
rtwn(4): Add new USB ID.

Submitted by: Wensi <supdrewin@outlook.com>
PR: 261098
Sponsored by: NVIDIA Networking

(cherry picked from commit 75d20a5e386c9f15043600b1b2d7041eb64d0e99)

2 years agouchcom(4): Add new USB ID.
Hans Petter Selasky [Fri, 7 Jan 2022 12:56:47 +0000 (13:56 +0100)]
uchcom(4): Add new USB ID.

Submitted by: darius@dons.net.au
PR: 260783
Sponsored by: NVIDIA Networking

(cherry picked from commit 34bedcee3c5a8640f3e344218b47c2d970df78ed)

2 years agortwn(4): Add new USB ID.
Hans Petter Selasky [Fri, 7 Jan 2022 13:00:36 +0000 (14:00 +0100)]
rtwn(4): Add new USB ID.

Submitted by: arved@
PR: 260952
Sponsored by: NVIDIA Networking

(cherry picked from commit 2891a2805289dc4fe221eb4901b9edb6f9559dd8)

2 years agousb(4): Ignore port resume failures.
Hans Petter Selasky [Wed, 2 Feb 2022 11:59:00 +0000 (12:59 +0100)]
usb(4): Ignore port resume failures.

If port resume fails, likely the USB device is detached. Ignore such errors,
because else the USB stack might try forever trying to resume the device,
before it will proceed detaching it.

Sponsored by: NVIDIA Networking

(cherry picked from commit a88e1a04df8bf192da607cfb068020c357a4c3ce)

2 years agoRevert "vm_pageout_scans: correct detection of active object"
Konstantin Belousov [Thu, 10 Feb 2022 14:50:42 +0000 (16:50 +0200)]
Revert "vm_pageout_scans: correct detection of active object"

This reverts commit 3de96d664aaaf8e3fb1ca4fc4bd864d2cf734b24.

PR: 261707

(cherry picked from commit b51927b7b018d268c91b2127d82786caf68254de)

2 years agofilemon.4: Document FILEMON_SET_FD errors and refine wording a bit
Mark Johnston [Thu, 3 Feb 2022 14:42:14 +0000 (09:42 -0500)]
filemon.4: Document FILEMON_SET_FD errors and refine wording a bit

Reviewed by: emaste, debdrup, Pau Amma
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 03399cd6e04eb108db0392c8e77eb6ea00c5532e)

2 years agofilemon: Reject FILEMON_SET_FD commands when the fd is a kqueue
Mark Johnston [Thu, 3 Feb 2022 14:41:17 +0000 (09:41 -0500)]
filemon: Reject FILEMON_SET_FD commands when the fd is a kqueue

When FILEMON_SET_FD is used, the filemon handle effectively wraps the
passed file.  In particular, the handle may be inherited by a child
process, or transferred over a unix domain socket, so we must verify
that the backing file permits this.

Reported by: syzbot+36e6be9e02735fe66ca8@syzkaller.appspotmail.com
Reviewed by: emaste
Sponsored by: The FreeBSD Foundation

(cherry picked from commit b84ed4e7f626de5475cf26bae6d7ff15ec9f9675)

2 years agoshsec: Allocate data blocks only for BIO_READ/WRITE requests
Mark Johnston [Thu, 27 Jan 2022 14:53:02 +0000 (09:53 -0500)]
shsec: Allocate data blocks only for BIO_READ/WRITE requests

In particular, there is no need to allocate a data block when passing
BIO_FLUSH requests to child providers, and g_io_request() asserts that
bp->bio_data == NULL for such requests.

PR: 255131
Reported and tested by: nvass@gmx.com
Sponsored by: The FreeBSD Foundation

(cherry picked from commit a2dfffb98917a57bfacb155b9d7d423c3e8ff792)

2 years agogeom: Assert that BIO_SPEEDUP BIOs have bio_data set to NULL
Mark Johnston [Thu, 27 Jan 2022 14:58:19 +0000 (09:58 -0500)]
geom: Assert that BIO_SPEEDUP BIOs have bio_data set to NULL

Like BIO_FLUSH, there is no reason for consumers to pass a BIO_SPEEDUP
request with non-NULL bio_data, so assert this.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 38da0c96dc1b4698931f65d8d58e864dfc3a600e)

2 years agoSwitch to using drive-supplied timeouts for the sa(4) driver.
Kenneth D. Merry [Thu, 13 Jan 2022 21:07:58 +0000 (16:07 -0500)]
Switch to using drive-supplied timeouts for the sa(4) driver.

Summary:
The sa(4) driver has historically used tape drive timeouts that
were one-size fits all, with compile-time options to adjust a few
of them.

LTO-9 drives (and presumably other tape drives in the future)
implement a tape characterization process that happens the first
time a tape is loaded.  The characterization process formats the
tape to account for the temperature and humidity in the environment
it is being used in.  The process for LTO-9 tapes can take from 20
minutes (I have observed 17-18 minutes) to 2 hours according to the
documentation.

As a result, LTO-9 drives have significantly longer recommended
load times than previous LTO generations.

To handle this, change the sa(4) driver over to using timeouts
supplied by the tape drive using the timeout descriptors obtained
through the REPORT SUPPORTED OPERATION CODES command.  That command
was introduced in SPC-4.  IBM tape drives going back to at least
LTO-5 report timeout values.  Oracle/Sun/StorageTek tape drives
going back to at least the T10000C report timeout values.  HP LTO-5
and newer drives report timeout values.  The sa(4) driver only
queries drives that claim to support SPC-4.

This makes the timeout settings automatic and accurate for newer
tape drives.

Also, add loader tunable and sysctl support so that the user can
override individual command type timeouts for all tape drives in
the system, or only for specific drives.

The new global (these affect all tape drives) loader tunables are:

kern.cam.sa.timeout.erase
kern.cam.sa.timeout.load
kern.cam.sa.timeout.locate
kern.cam.sa.timeout.mode_select
kern.cam.sa.timeout.mode_sense
kern.cam.sa.timeout.prevent
kern.cam.sa.timeout.read
kern.cam.sa.timeout.read_position
kern.cam.sa.timeout.read_block_limits
kern.cam.sa.timeout.report_density
kern.cam.sa.timeout.reserve
kern.cam.sa.timeout.rewind
kern.cam.sa.timeout.space
kern.cam.sa.timeout.tur
kern.cam.sa.timeout.write
kern.cam.sa.timeout.write_filemarks

The new per-instance loader tunable / sysctl variables are:

kern.cam.sa.%d.timeout.erase
kern.cam.sa.%d.timeout.load
kern.cam.sa.%d.timeout.locate
kern.cam.sa.%d.timeout.mode_select
kern.cam.sa.%d.timeout.mode_sense
kern.cam.sa.%d.timeout.prevent
kern.cam.sa.%d.timeout.read
kern.cam.sa.%d.timeout.read_position
kern.cam.sa.%d.timeout.read_block_limits
kern.cam.sa.%d.timeout.report_density
kern.cam.sa.%d.timeout.reserve
kern.cam.sa.%d.timeout.rewind
kern.cam.sa.%d.timeout.space
kern.cam.sa.%d.timeout.tur
kern.cam.sa.%d.timeout.write
kern.cam.sa.%d.timeout.write_filemarks

The values are reported and set in units of thousandths of a
second.

share/man/man4/sa.4:
Document the new loader tunables in the sa(4) man page.

sys/cam/scsi/scsi_sa.c:
Add a new timeout_info array to the softc.

Add a default timeouts array, along with descriptions.

Add a new sysctl tree to the softc to handle the timeout
sysctl values.

Add a new function, saloadtotunables(), that will load
the global loader tunables first and then any per-instance
loader tunables second.

Add creation of the new timeout sysctl variables in
sasysctlinit().

Add a new, optional probe state to the sa(4) driver.  We
previously didn't do any probing, but now we probe for
timeout descriptors if the drive claims to support SPC-4 or
later.  In saregister(), we check the SCSI revision and
either launch the probe state machine, or announce the
device and become ready.

In sastart() and sadone(), add support for the new
SA_STATE_PROBE.  If we're probing, we don't go through
saerror(), since that is currently only written to handle
I/O errors in the normal state.

Change every place in the sa(4) driver that fills in
timeout values in a CCB to use the new timeout_info[] array
in the softc.

Add a new saloadtimeouts() routine to parse the returned
timeout descriptors from a completed REPORT SUPPORTED
OPERATION CODES command, and set the values for the
commands we support.

Add comments explaining the priority order of the various
sources of timeout values.  Also, explain that the probe
that pulls in drive recommended timeouts via the REPORT
SUPPORTED OPERATION CODES command is in a race with the
thread that creates the sysctl variables.  Because of that
race, it is important that the sysctl thread not load any
timeout values from the kernel environment.

Sponsored by: Spectra Logic

Test Plan:
Try this out with a variety of tape drives and make sure the timeouts that
result (sysctl kern.cam.sa to see them) are reasonable.

Reviewers: #manpages, #cam

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D33883

(cherry picked from commit 5719b5a1bb643d5622557afe78dca63a800d9b7c)
(cherry picked from commit bcff64c54a74268742f52d40d1eb2acd8ab6f07d)
(cherry picked from commit 6e8a2f04001735353e445570f0d83aa88d4b9b37)

2 years agonfsclient: Delete unused function nfscl_getcookie()
Rick Macklem [Thu, 27 Jan 2022 23:30:26 +0000 (15:30 -0800)]
nfsclient: Delete unused function nfscl_getcookie()

The function nfscl_getcookie(), which is essentially the
same as ncl_getcookie(), is never called, so delete it.
This is probably cruft left over from the port of the
NFSv4 code to FreeBSD several years ago.

Found while modifying the code to better use the
directory offset cookies.

(cherry picked from commit 98c788737f71be0a54a23456082453ec674987fe)

2 years agossh: enable FIDO/U2F keys
Ed Maste [Thu, 7 Oct 2021 03:31:17 +0000 (23:31 -0400)]
ssh: enable FIDO/U2F keys

Description of FIDO/U2F support (from OpenSSH 8.2 release notes,
https://www.openssh.com/txt/release-8.2):

  This release adds support for FIDO/U2F hardware authenticators to
  OpenSSH. U2F/FIDO are open standards for inexpensive two-factor
  authentication hardware that are widely used for website
  authentication.  In OpenSSH FIDO devices are supported by new public
  key types "ecdsa-sk" and "ed25519-sk", along with corresponding
  certificate types.

  ssh-keygen(1) may be used to generate a FIDO token-backed key, after
  which they may be used much like any other key type supported by
  OpenSSH, so long as the hardware token is attached when the keys are
  used. FIDO tokens also generally require the user explicitly
  authorise operations by touching or tapping them.

  Generating a FIDO key requires the token be attached, and will
  usually require the user tap the token to confirm the operation:

    $ ssh-keygen -t ecdsa-sk -f ~/.ssh/id_ecdsa_sk
    Generating public/private ecdsa-sk key pair.
    You may need to touch your security key to authorize key generation.
    Enter file in which to save the key (/home/djm/.ssh/id_ecdsa_sk):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/djm/.ssh/id_ecdsa_sk
    Your public key has been saved in /home/djm/.ssh/id_ecdsa_sk.pub

  This will yield a public and private key-pair. The private key file
  should be useless to an attacker who does not have access to the
  physical token. After generation, this key may be used like any
  other supported key in OpenSSH and may be listed in authorized_keys,
  added to ssh-agent(1), etc. The only additional stipulation is that
  the FIDO token that the key belongs to must be attached when the key
  is used.

To enable FIDO/U2F support, this change regenerates ssh_namespace.h,
adds ssh-sk-helper, and sets ENABLE_SK_INTERNAL (unless building
WITHOUT_USB).

devd integration is not included in this change, and is under
investigation for the base system.  In the interim the security/u2f-devd
port can be installed to provide appropriate devd rules.

Reviewed by: delphij, kevans
Relnotes: Yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D32509

(cherry picked from commit e9a994639b2af232f994ba2ad23ca45a17718d2b)

2 years agoAdd libfido2 to the build
Ed Maste [Thu, 7 Oct 2021 01:52:05 +0000 (21:52 -0400)]
Add libfido2 to the build

From https://github.com/Yubico/libfido2:

    libfido2 provides library functionality and command-line tools to
    communicate with a FIDO device over USB, and to verify attestation
    and assertion signatures.

    libfido2 supports the FIDO U2F (CTAP 1) and FIDO 2.0 (CTAP 2)
    protocols.

libfido2 will be used by ssh to support FIDO/U2F keys. It is currently
intended only for use by ssh, and so is installed as a PRIVATELIB and is
placed in the ssh pkgbase package.

This is currently disabled for the 32-bit library build as libfido2 is
not compatible with the COMPAT_32BIT hack in usb_ioctl.h.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D32448

(cherry picked from commit 7b1e19ad78c6a3f84f81cb1a16a39500f0337062)
(cherry picked from commit 93942379cced89ad4ac653f262ac8277a8550853)

2 years agoAdd libcbor to the build
Ed Maste [Thu, 7 Oct 2021 00:42:40 +0000 (20:42 -0400)]
Add libcbor to the build

From https://github.com/PJK/libcbor:

    libcbor is a C library for parsing and generating CBOR, the general-
    purpose schema-less binary data format.

libcbor will be used by ssh to support FIDO/U2F keys.  It is currently
intended only for use by ssh, and so is installed as a PRIVATELIB and is
placed in the ssh pkgbase package.

cbor_export.h and configuration.h were generated by the upstream CMake
build.  We could create them with bmake rules instead (as NetBSD has
done) but this is a fine start.

This is currently disabled for the 32-bit library build as libfido2 is
not compatible with the COMPAT_32BIT hack in usb_ioctl.h, and there is
no need for libcbor without libfido2.

Reviewed by: kevans
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D32347

(cherry picked from commit 2e85df652caef859c532b7e1e8a178c75f1a4a92)

2 years agolibfido2: Address CHERI compatibility
Jessica Clarke [Sat, 2 Oct 2021 15:51:38 +0000 (16:51 +0100)]
libfido2: Address CHERI compatibility

Cherry-picked from libfido2 upstream f20a735c0a6f:

iso7816: Avoid storing pointers in a packed structure

On CHERI, and thus Arm's experimental Morello prototype architecture,
pointers are represented as capabilities, which are unforgeable bounded
pointers, providing always-on fine-grained spatial memory safety. The
unforgeability is enforced through the use of tagged memory, with one
validity tag bit per capability-sized-and-aligned word in memory. This
means that storing a pointer to an unaligned location, which is not
guaranteed to work per the C standard, either traps or results in the
capability losing its tag (and thus never being dereferenceable again),
depending on how exactly the store is done (specifically, whether a
capability store or memcpy is used).

However, iso7816 itself does not need to be packed, and doing so likely
causes inefficiencies on existing architectures. The iso7816_header_t
member is packed, and the flexible payload array is a uint8_t (which by
definition has no padding bits and is exactly 8 bits in size and, since
CHAR_BITS must be at least 8, its existence implies that it has the same
representation as unsigned char, and that it has size and alignment 1)
so there will never be any padding inserted between header and payload
(but payload may overlap with padding at the end of the struct due to
how flexible arrays work, which means we need to be careful about our
calculations).

Co-authored-by: pedro martelletto <pedro@yubico.com>
(cherry picked from commit 224a95f124270275ddd7ab9f8f87dd47bad7c282)

2 years agoImport libfido2 at 'contrib/libfido2/'
Ed Maste [Thu, 7 Oct 2021 01:27:02 +0000 (21:27 -0400)]
Import libfido2 at 'contrib/libfido2/'

git-subtree-dir: contrib/libfido2
git-subtree-mainline: d586c978b9b4216869e589daa5bbcc33225a0e35
git-subtree-split: a58dee945a5da64d0e97f35a508928e0d17c9cc7
(cherry picked from commit 0afa8e065e14bb8fd338d75690e0238c00167d40)

2 years agoImport libcbor at 'contrib/libcbor/'
Ed Maste [Thu, 7 Oct 2021 00:26:10 +0000 (20:26 -0400)]
Import libcbor at 'contrib/libcbor/'

git-subtree-dir: contrib/libcbor
git-subtree-mainline: 293663f4da9e8b8aeb106ce3b73a8ed2aa2a8a90
git-subtree-split: 5b2defbd2a1aa991bd0a2855eef8e15107572747
(cherry picked from commit 10ff414c14eef433d8157f0c17904d740693933b)

2 years agoMakefile.inc1: remove lorder from build/cross tools
Ed Maste [Mon, 18 Oct 2021 20:27:34 +0000 (16:27 -0400)]
Makefile.inc1: remove lorder from build/cross tools

As lorder is not used by the base system build there is no need to
include it in bootstrap-tools or NXBDIRS.

Fixes: 0e1e341b486c ("Stop using lorder and ranlib when...")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 1a724aa97265c9023d2aa69b444b46c4f7c5d9f2)

2 years agomgb: Update man page wrt state of the driver
Ed Maste [Tue, 28 Sep 2021 20:27:28 +0000 (16:27 -0400)]
mgb: Update man page wrt state of the driver

Be explicit that the driver has caveats and limitations, and remove the
note about not being connected to the build: I plan to connect it soon.
(Also the note serves no real purpose in a man page that is not
installed.)

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 667ea7385d9ce45c376260e9c2c893c51514e25e)

2 years agomgb: remove set but not used variables
Ed Maste [Tue, 23 Nov 2021 01:32:29 +0000 (20:32 -0500)]
mgb: remove set but not used variables

Sponsored by: The FreeBSD Foundation

(cherry picked from commit c0aa5f6a321b8e7a921eda69ec0ab7373890c155)

2 years agosysctl.9: put negative sense sysctl note in own paragraph
Ed Maste [Tue, 17 Aug 2021 15:58:03 +0000 (11:58 -0400)]
sysctl.9: put negative sense sysctl note in own paragraph

The sysctl man page cautions against negative-sense boolean sysctls
(foobar_disable), but it gets lost at the end of a large paragraph.
Move it to a separate paragraph in an attempt to make it more clear.

This man page could use a more holistic review and edit pass.  This
change is simple and straightforward and I hope provides a small but
immediate benefit.

(cherry picked from commit dff1ba09f74725bb0a0b7b8c229ed4e6665b43e6)

2 years agoopenssh: update to OpenSSH v8.7p1
Ed Maste [Wed, 8 Sep 2021 01:05:51 +0000 (21:05 -0400)]
openssh: update to OpenSSH v8.7p1

Some notable changes, from upstream's release notes:

- sshd(8): Remove support for obsolete "host/port" syntax.
- ssh(1): When prompting whether to record a new host key, accept the key
  fingerprint as a synonym for "yes".
- ssh-keygen(1): when acting as a CA and signing certificates with an RSA
  key, default to using the rsa-sha2-512 signature algorithm.
- ssh(1), sshd(8), ssh-keygen(1): this release removes the "ssh-rsa"
  (RSA/SHA1) algorithm from those accepted for certificate signatures.
- ssh-sk-helper(8): this is a new binary. It is used by the FIDO/U2F
  support to provide address-space isolation for token middleware
  libraries (including the internal one).
- ssh(1): this release enables UpdateHostkeys by default subject to some
  conservative preconditions.
- scp(1): this release changes the behaviour of remote to remote copies
  (e.g. "scp host-a:/path host-b:") to transfer through the local host
  by default.
- scp(1): experimental support for transfers using the SFTP protocol as
  a replacement for the venerable SCP/RCP protocol that it has
  traditionally used.

Additional integration work is needed to support FIDO/U2F in the base
system.

Deprecation Notice
------------------

OpenSSH will disable the ssh-rsa signature scheme by default in the
next release.

Reviewed by: imp
MFC after: 1 month
Relnotes: Yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29985

(cherry picked from commit 19261079b74319502c6ffa1249920079f0f69a72)
(cherry picked from commit f448c3ed4ae1281861913a56377f9d93d49f8e8e)
(cherry picked from commit 1f290c707a19d1695c303e6c8ead9cc414ccc6dc)
(cherry picked from commit 0f9bafdfc325779e4ecc5154d5bb06c752297138)
(cherry picked from commit adb56e58e8db84d8087ebe3d3e7def0074cb5a90)
(cherry picked from commit 576b58108c1723c85e4dd00355e29bfe301dab11)
(cherry picked from commit 1c99af1ebe61cbaf633792941640dcd254acf921)
(cherry picked from commit 87152f34054921632016bc5eb4ab9f836fbaa522)
(cherry picked from commit 172fa4aa7577915bf5ace5783251821d3774dc05)

2 years agoBelatedly track private lib renaming for OptionalObsoleteFiles.inc
Ed Maste [Sat, 9 Oct 2021 00:15:43 +0000 (20:15 -0400)]
Belatedly track private lib renaming for OptionalObsoleteFiles.inc

Reviewed by: kevans
Fixes: 5551c573554e ("Rework PRIVATELIB")
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D32384

(cherry picked from commit 032448cd2c52161aa03fd4ee5bf243d78d61b53e)

2 years agoOptionalObsoleteFiles.inc: remove MK_CXX rule for usr/bin/c++
Ed Maste [Wed, 1 Dec 2021 21:49:16 +0000 (16:49 -0500)]
OptionalObsoleteFiles.inc: remove MK_CXX rule for usr/bin/c++

In fact MK_CXX does not control whether /usr/bin/c++ is built -- it is
installed as a link to Clang (which is always a C/C++ compiler), and it
already exists in OptionalObsoleteFiles under MK_TOOLCHAIN.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit c3f345ae3c0fac0684f83cff72ae23da18468777)

2 years agoOptionalObsoleteFiles: move /usr/bin/CC to MK_TOOLCHAIN section
Ed Maste [Wed, 1 Dec 2021 21:38:10 +0000 (16:38 -0500)]
OptionalObsoleteFiles: move /usr/bin/CC to MK_TOOLCHAIN section

/usr/bin/CC is installed by usr.bin/clang/clang/Makefile, as with
/usr/bin/cc, /usr/bin/cpp, etc., and is not controlled by MK_CXX.
Move it to the same section as those tools.

(It may be that these should all be under
MK_TOOLCHAIN == no || MK_CLANG_IS_CC == no, but that seems like
unnecessary complexity.)

Sponsored by: The FreeBSD Foundation

(cherry picked from commit f7ea22e2115329b7a4f2c6620e59e644f509a4ca)

2 years agoOptionalObsoleteFiles: remove GCC remnants
Ed Maste [Tue, 30 Nov 2021 18:39:21 +0000 (13:39 -0500)]
OptionalObsoleteFiles: remove GCC remnants

g++ and cc1plus were GCC components that are already removed
unconditionally in ObsoleteFiles.inc.

Reported by: jhb (in review D33108)
Fixes: 57f804675e65 ("remove GCC 4.2.1 build infrastructure")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 1b9344add475179e4ee6b13f25def6f44799a929)

2 years agoRemove 'All Rights Reserved' from xlocale FreeBSD Foundation copyrights
Ed Maste [Thu, 16 Dec 2021 19:28:19 +0000 (14:28 -0500)]
Remove 'All Rights Reserved' from xlocale FreeBSD Foundation copyrights

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 301d1de6bae222fb695a7401a66f1a22339e5038)

2 years agogeom: Add HiFive boot partitions
Ed Maste [Tue, 12 Oct 2021 18:51:24 +0000 (14:51 -0400)]
geom: Add HiFive boot partitions

As documented in the HiFive Unmatched Software Reference Manual.

Reviewed by: imp, mhorne
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34010

(cherry picked from commit 9c296a2105734c6928b4e4a9d75d6a17ff9b9bab)

2 years agogpart.8: minor tidying
Ed Maste [Wed, 26 Jan 2022 15:53:31 +0000 (10:53 -0500)]
gpart.8: minor tidying

Reported by: igor(1)

(cherry picked from commit 3524dead8129cb72e0a89ae93f29506b853b5d16)

2 years agoCirrus-CI: add some timing info on pkg install failure
Ed Maste [Wed, 2 Jun 2021 17:08:29 +0000 (13:08 -0400)]
Cirrus-CI: add some timing info on pkg install failure

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 77013d11e6483b970af25e13c9b892075742f7e5)

2 years agozfs: Remove zfs-images submodule
Ed Maste [Mon, 14 Jun 2021 13:31:39 +0000 (09:31 -0400)]
zfs: Remove zfs-images submodule

This can cause issues like 'No url found for submodule path' in
downstream or derived projects making use of submodules.

Reviewed by: imp

(cherry picked from commit 79e6eb5c018d44ee59c5b9b10755d116c860c366)

2 years agoce: remove long-obsolete FreeBSD version compatibility
Ed Maste [Thu, 25 Mar 2021 02:48:50 +0000 (22:48 -0400)]
ce: remove long-obsolete FreeBSD version compatibility

Mechanical change via unifdef.

(cherry picked from commit f9839a42ee5d67c885023ca74e797b5aec50bf59)
(cherry picked from commit f48c35fa1ea8e37812b315bd0dee17c88155de26)

2 years agorsu: add KASSERT to document maximum mbuf size in rsu_tx_start
Ed Maste [Mon, 22 Mar 2021 18:34:31 +0000 (14:34 -0400)]
rsu: add KASSERT to document maximum mbuf size in rsu_tx_start

PR: 254479
Reviewed by: markj
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 453d8a7ee2fc862f3a5e98185d57c8ad05cbc047)

2 years agoRemove unused GNUCXX option descriptions
Ed Maste [Sat, 30 Jan 2021 17:43:42 +0000 (12:43 -0500)]
Remove unused GNUCXX option descriptions

Missed from 57f804675e65

Reported by: arhchardson in D27974
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 69557375226a4ab26eadd47007c1230ce5ce9077)

2 years agoelfctl: update man page example for 'no' prefix
Ed Maste [Sat, 5 Feb 2022 02:02:44 +0000 (21:02 -0500)]
elfctl: update man page example for 'no' prefix

Reported by: Mark Millard on freebsd-current@
Fixes: c763f99d11fd ("elfctl: prefix disable flags with "no"")
MFC after: 1 week
Sponsored by: The FreeBSD Foundation

(cherry picked from commit dbc7364b1840ef3f36994952d085add5d161775d)

2 years agoFix too small sscanf output buffers in kbdmap
Dimitry Andric [Sun, 6 Feb 2022 15:25:11 +0000 (16:25 +0100)]
Fix too small sscanf output buffers in kbdmap

This fixes the following warnings from clang 14:

usr.sbin/kbdmap/kbdmap.c:241:16: error: 'sscanf' may overflow; destination buffer in argument 5 has size 20, but the corresponding specifier may require size 21 [-Werror,-Wfortify-source]
                            &a, &b, buf);
                                    ^
usr.sbin/kbdmap/kbdmap.c:615:8: error: 'sscanf' may overflow; destination buffer in argument 3 has size 64, but the corresponding specifier may require size 65 [-Werror,-Wfortify-source]
                            keym, lng, desc);
                            ^
usr.sbin/kbdmap/kbdmap.c:615:14: error: 'sscanf' may overflow; destination buffer in argument 4 has size 64, but the corresponding specifier may require size 65 [-Werror,-Wfortify-source]
                            keym, lng, desc);
                                  ^
usr.sbin/kbdmap/kbdmap.c:615:19: error: 'sscanf' may overflow; destination buffer in argument 5 has size 256, but the corresponding specifier may require size 257 [-Werror,-Wfortify-source]
                            keym, lng, desc);
                                       ^

In each case, the buffer being sscanf'd into is one byte too small.

MFC after:  3 days

(cherry picked from commit e17fede8ff4629b5ff640ed660940b04c70da0b6)

2 years agoFix too small hostname buffer in bootparamd
Dimitry Andric [Sun, 6 Feb 2022 14:25:22 +0000 (15:25 +0100)]
Fix too small hostname buffer in bootparamd

This fixes the following warning from clang 14:

usr.sbin/bootparamd/bootparamd/bootparamd.c:204:32: error: 'fscanf' may
overflow; destination buffer in argument 3 has size 255, but the
corresponding specifier may require size 256 [-Werror,-Wfortify-source]

The MAX_MACHINE_NAME macro indicates the maximum number of bytes in a
machine name, but it does not include the NUL terminator required for
scanf.

MFC after:  3 days

(cherry picked from commit d310bf3867b4168e57365196c3a31797c0538097)

2 years agoExplicitly include semaphore.h for struct _sem in fusefs setattr test
Dimitry Andric [Sun, 6 Feb 2022 16:07:16 +0000 (17:07 +0100)]
Explicitly include semaphore.h for struct _sem in fusefs setattr test

In libc++'s __threading_support header the semaphore.h header was
implicitly included, but from version 14 onwards, this is no longer the
case, resulting in compile errors:

tests/sys/fs/fusefs/setattr.cc:740:8: error: variable has incomplete type 'sem_t' (aka '_sem')
        sem_t sem;
              ^
tests/sys/fs/fusefs/utils.hh:33:8: note: forward declaration of '_sem'
struct _sem;
       ^

MFC after: 3 days

(cherry picked from commit c9cabf9aa6feb542776333fe5e915a3464f89e3c)

2 years agoar: Avoid overwriting the stdout file stream pointer
Mark Johnston [Thu, 27 Jan 2022 22:10:17 +0000 (17:10 -0500)]
ar: Avoid overwriting the stdout file stream pointer

This doesn't work with musl, which defines stdout as FILE * const.
Instead, explicitly pass the desired output stream to ar_read_archive().

No functional change intended.

Reviewed by: emaste
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34064

(cherry picked from commit 41e6398f9bc1bba4ed872118e742096d692fdfec)

2 years agoar: diff reduction against ELF Tool Chain
Ed Maste [Wed, 4 Aug 2021 13:54:17 +0000 (09:54 -0400)]
ar: diff reduction against ELF Tool Chain

- Drop exit status from bsdar_errc.  ELF Tool Chain always returns
  EXIT_FAILURE in bsdar_errc.

- Remove ar_mode_* wrappers and call ar_read_archive / ar_write_archive
  directly.

Obtained from: ELF Tool Chain
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31496

(cherry picked from commit d20e9e02db3dde383c3de1ce8cec3a8c35b3eee6)
(cherry picked from commit c5bf58add0d523fc6e6546f3fc10d0c8b972e8e7)
(cherry picked from commit 086f09087713e3af0a28d296a2372071b72211ef)
(cherry picked from commit 57aaefdceccdd590f81af4b274c7a3ee61ae62f1)
(cherry picked from commit 866c807472619371adcb2a0409a9287748a52654)