]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
3 years agoFetch the sigfastblock value in syscalls that wait for signals
Jonathan T. Looney [Fri, 12 Mar 2021 18:14:17 +0000 (18:14 +0000)]
Fetch the sigfastblock value in syscalls that wait for signals

We have seen several cases of processes which have become "stuck" in
kern_sigsuspend(). When this occurs, the kernel's td_sigblock_val
is set to 0x10 (one block outstanding) and the userspace copy of the
word is set to 0 (unblocked). Because the kernel's cached value
shows that signals are blocked, kern_sigsuspend() blocks almost all
signals, which means the process hangs indefinitely in sigsuspend().

It is not entirely clear what is causing this condition to occur.
However, it seems to make sense to add some protection against this
case by fetching the latest sigfastblock value from userspace for
syscalls which will sleep waiting for signals. Here, the change is
applied to kern_sigsuspend() and kern_sigtimedwait().

(cherry picked from commit dbec10e08808e375365fb2a2462f306e0cdfda32)

3 years agoPut bandaid for nhgrp_dump_sysctl() malloc KASSERT().
Alexander V. Chernikov [Mon, 29 Mar 2021 23:12:11 +0000 (23:12 +0000)]
Put bandaid for nhgrp_dump_sysctl() malloc KASSERT().

Recent rtsock changes widened epoch and covered nhgrp_dump_sysctl(),
  resulting in `netstat -4On` triggering with KASSERT.

(cherry picked from commit 9fa8d1582b44b4850d40699c9adb104732328b7d)

3 years agoFix nexhtop group index array scaling.
Alexander V. Chernikov [Mon, 29 Mar 2021 23:00:17 +0000 (23:00 +0000)]
Fix nexhtop group index array scaling.

The current code has the limit of 127 nexthop groups due to the
 wrongly-checked bitmask_copy() return value.

PR: 254303
Reported by: Aleks <a.ivanov at veesp.com>

(cherry picked from commit 9095dc7da4cf0c484fb1160b2180b7329b09b107)

3 years agoStop installing kernel-only crypto headers to /usr/include/crypto.
John Baldwin [Tue, 16 Mar 2021 00:00:21 +0000 (17:00 -0700)]
Stop installing kernel-only crypto headers to /usr/include/crypto.

The only user-facing header from OCF is <crypto/cryptodev.h>.

Sponsored by: Chelsio Communications

(cherry picked from commit afbee98232f41fc05fa8a5b9a8cda4c4c65ff448)
(cherry picked from commit 2fc640d5bc0a17024dc1eb996ab00af42a5c6dbd)
(cherry picked from commit 283352dd4f6a3bb2f3c7cb45ce5dca3d86f5e3f4)
(cherry picked from commit 9946b2f4e0b478de69ebd687e2132c318a4d7c21)
(cherry picked from commit 7af04dff025d98e2feff979756ecde8ef0ace390)

3 years agoxnb: Don't pass SIOC{ADD,DEL}MULTI to ifmedia_ioctl().
John Baldwin [Mon, 22 Mar 2021 16:55:49 +0000 (09:55 -0700)]
xnb: Don't pass SIOC{ADD,DEL}MULTI to ifmedia_ioctl().

ifmedia_ioctl() doesn't handle these requests, and this matches what
xn does.

Sponsored by: DARPA

(cherry picked from commit 71ba16a0a02f4a3fd56d03e908615a8b5f701ba4)

3 years agoRename linux_set_upcall_kse() to linux_set_upcall().
John Baldwin [Thu, 18 Mar 2021 19:14:34 +0000 (12:14 -0700)]
Rename linux_set_upcall_kse() to linux_set_upcall().

This matches the rename of cpu_set_upcall_kse() in
5c2cf818454375536fda522ba83cf67c50929e6b.

Sponsored by: DARPA

(cherry picked from commit 3b57ddb029daf225a8385dade491019269da82e8)

3 years agox86: Reduce code duplication in cpu_fork() and cpu_copy_thread().
John Baldwin [Thu, 18 Mar 2021 19:13:17 +0000 (12:13 -0700)]
x86: Reduce code duplication in cpu_fork() and cpu_copy_thread().

Add copy_thread() to hold shared code.

Sponsored by: Netflix

(cherry picked from commit a7883464fcc45b78e6aa01222682ae40f787a378)

3 years agoaarch64: Clear TLS registers during exec().
John Baldwin [Wed, 17 Mar 2021 20:19:04 +0000 (13:19 -0700)]
aarch64: Clear TLS registers during exec().

These are not stored in the trapframe so must be cleared explicitly.

This is similar to one of the MIPS changes in 822d2d6ac94f.

Obtained from: CheriBSD
Sponsored by: DARPA

(cherry picked from commit 0723b409150ae302eb021cbde86a5f77348a1bb4)

3 years agox86: Update some stale comments in cpu_fork() and cpu_copy_thread().
John Baldwin [Fri, 12 Mar 2021 17:48:49 +0000 (09:48 -0800)]
x86: Update some stale comments in cpu_fork() and cpu_copy_thread().

Neither of these routines allocate stacks.

Sponsored by: Netflix

(cherry picked from commit 40d593d17eb6d70ea717d6546a16794858944176)

3 years agox86: Always use clean FPU and segment base state for new kthreads.
John Baldwin [Fri, 12 Mar 2021 17:48:36 +0000 (09:48 -0800)]
x86: Always use clean FPU and segment base state for new kthreads.

Sponsored by: Netflix

(cherry picked from commit c7b021352332a2f79907d68f971849f74b73e1c6)

3 years agoSet TDP_KTHREAD before calling cpu_fork() and cpu_copy_thread().
John Baldwin [Fri, 12 Mar 2021 17:48:20 +0000 (09:48 -0800)]
Set TDP_KTHREAD before calling cpu_fork() and cpu_copy_thread().

This permits these routines to use special logic for initializing MD
kthread state.

For the kproc case, this required moving the logic to set these flags
from kproc_create() into do_fork().

Sponsored by: Netflix

(cherry picked from commit 640d54045bdbf894ae3c75cd9818c29fc2f6e5e7)

3 years agoDon't pass RFPROC to kproc_create(), it is redundant.
John Baldwin [Fri, 12 Mar 2021 17:48:10 +0000 (09:48 -0800)]
Don't pass RFPROC to kproc_create(), it is redundant.

Sponsored by: Netflix

(cherry picked from commit 5a50eb6585ef8d1a40c8086bab8639cc56f00df9)

3 years agoRemove unused wrappers around kproc_create() and kproc_exit().
John Baldwin [Fri, 12 Mar 2021 17:47:58 +0000 (09:47 -0800)]
Remove unused wrappers around kproc_create() and kproc_exit().

Sponsored by: Netflix

(cherry picked from commit 645b15e558dc102ff70a6332b1d0b0aa733fd2bb)

3 years agox86: Copy the FPU/XSAVE state from the creating thread to new threads.
John Baldwin [Fri, 12 Mar 2021 17:47:41 +0000 (09:47 -0800)]
x86: Copy the FPU/XSAVE state from the creating thread to new threads.

POSIX states that new threads created via pthread_create() should
inherit the "floating point environment" from the creating thread.

Sponsored by: Netflix

(cherry picked from commit 755efb8d8fcacc6607bc46469750d78497f89378)

3 years agoamd64: Cleanups to setting TLS registers for Linux binaries.
John Baldwin [Fri, 12 Mar 2021 17:47:31 +0000 (09:47 -0800)]
amd64: Cleanups to setting TLS registers for Linux binaries.

- Use update_pcb_bases() when updating FS or GS base addresses to
  permit use of FSBASE and GSBASE in Linux processes.  This also sets
  PCB_FULL_IRET.  linux32 was setting PCB_32BIT which should be a
  no-op (exec sets it).

- Remove write-only variables to construct unused segment descriptors
  for linux32.

Sponsored by: Netflix

(cherry picked from commit 704547ce1ca56e1123048cd152ed4e468d41d703)

3 years agoamd64: Only update fsbase/gsbase in pcb for curthread.
John Baldwin [Fri, 12 Mar 2021 17:45:18 +0000 (09:45 -0800)]
amd64: Only update fsbase/gsbase in pcb for curthread.

Before the pcb is copied to the new thread during cpu_fork() and
cpu_copy_thread(), the kernel re-reads the current register values in
case they are stale.  This is done by setting PCB_FULL_IRET in
pcb_flags.

This works fine for user threads, but the creation of kernel processes
and kernel threads do not follow the normal synchronization rules for
pcb_flags.  Specifically, new kernel processes are always forked from
thread0, not from curthread, so adjusting pcb_flags via a simple
instruction without the LOCK prefix can race with thread0 running on
another CPU.  Similarly, kthread_add() clones from the first thread in
the relevant kernel process, not from curthread.  In practice, Netflix
encountered a panic where the pcb_flags in the first kthread of the
KTLS process were trashed due to update_pcb_bases() in
cpu_copy_thread() running from thread0 to create one of the other KTLS
threads racing with the first KTLS kthread calling fpu_kern_thread()
on another CPU.  In the panicking case, the write to update pcb_flags
in fpu_kern_thread() was lost triggering an "Unregistered use of FPU
in kernel" panic when the first KTLS kthread later tried to use the
FPU.

Sponsored by: Netflix

(cherry picked from commit 92211458689b448cda52a659f9d192fef5a9dd50)

3 years agobsdinstall: Drop vestigial bsdinstall-esps cleanup
Ryan Moeller [Fri, 26 Mar 2021 18:12:18 +0000 (14:12 -0400)]
bsdinstall: Drop vestigial bsdinstall-esps cleanup

This is not needed after 0b7472b3d8d2f1e90fade5236b44fd98d8e396c2.

MFC after: 3 days
Sponsored by: iXsystems, Inc.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D29325

(cherry picked from commit b07b7aec6534052d60cffe010c0426a7ab986d85)

3 years agorpc.lockd: Unconditionally close fds as daemon
Caleb St. John [Fri, 26 Mar 2021 18:00:14 +0000 (14:00 -0400)]
rpc.lockd: Unconditionally close fds as daemon

When lockd is configured with a debug level of > 0 and foreground == 0,
the process is daemonized with a truth noclose argument to daemon().
This doesn't seem to be the desired behavior because that prevents
stdout and stderr from being closed, however, stdout and stderr aren't
used anywhere else. Furthermore, the man pages state that with a higher
debug level it will use the syslog facilities to do so.

Submitted by: Caleb St. John
Discussed with: rmacklem
MFC after: 3 days
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D29415

(cherry picked from commit badcfbacf3840a4097bb79192054481c7674e7d2)

3 years agoalign nfsdumpstate column output
Caleb St. John [Wed, 24 Mar 2021 20:33:41 +0000 (16:33 -0400)]
align nfsdumpstate column output

There are scenarios where an NFS client will mount an NFSv4 export
without specifying a callback address.

When running nfsdumpstate under this circumstance, the column output is
shifted incorrectly which places the "ClientID" value underneath the
"Clientaddr" column.

This diff is a small cosmetic change that prints a blank in the
"Clientaddr" column and ensures the data for the columns are aligned
appropriately.

Submitted by: Caleb St. John
Reviewed by: sef (previous version)
MFC after: 3 days
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D18958

(cherry picked from commit efad9c8ba3cec7f6e39b128b90afab70701fd8d9)

3 years agoHyper-V: hn: Initialize the internal field of per packet info on tx path
Wei Hu [Mon, 15 Mar 2021 10:20:52 +0000 (10:20 +0000)]
Hyper-V: hn: Initialize the internal field of per packet info on tx path

The RSC support feature introduced a bit field "rm_internal" in
struct rndis_pktinfo with total size unchanged.

The guest does not use this field in the tx path. However we need to
initialize it to zero in case older hosts which are not aware of this
field.

Fixes: a491581f ("Hyper-V: hn: Enable vSwitch RSC support")
MFC after: 2 weeks
Sponsored by: Microsoft

(cherry picked from commit 805dbff6c36a6cd84491aa53a02315fa025734cc)

3 years agoHyper-V: hn: Enable vSwitch RSC support in hn netvsc driver
Wei Hu [Fri, 12 Mar 2021 04:35:16 +0000 (04:35 +0000)]
Hyper-V: hn: Enable vSwitch RSC support in hn netvsc driver

Receive Segment Coalescing (RSC) in the vSwitch is a feature available in
Windows Server 2019 hosts and later. It reduces the per packet processing
overhead by coalescing multiple TCP segments when possible. This happens
mostly when TCP traffics are among different guests on same host.
This patch adds netvsc driver support for this feature.

The patch also updates NVS version to 6.1 as needed for RSC
enablement.

MFC after: 2 weeks
Sponsored by: Microsoft
Differential Revision: https://reviews.freebsd.org/D29075

(cherry picked from commit a491581f3f8df07cdff0236bd556895205929af4)

3 years agoHyper-V: hn: Store host hash value in flowid
Wei Hu [Wed, 24 Feb 2021 05:07:46 +0000 (05:07 +0000)]
Hyper-V: hn: Store host hash value in flowid

When rx packet contains hash value sent from host, store it in
the mbuf's flowid field so when the same mbuf is on the tx path,
the hash value can be used by the host to determine the outgoing
network queue.

MFC after: 2 weeks
Sponsored by: Microsoft

(cherry picked from commit 80f39bd95f22322152709ea5fae3a3c546044c9c)

3 years agoZero `struct weightened_nhop` fields in nhgrp_get_addition_group().
Alexander V. Chernikov [Sat, 20 Mar 2021 08:26:03 +0000 (08:26 +0000)]
Zero `struct weightened_nhop` fields in nhgrp_get_addition_group().

`struct weightened_nhop` has spare 32bit between the fields due to
 the alignment (on amd64).
Not zeroing these spare bits results in duplicating nhop groups
 in the kernel due to the way how comparison works.

(cherry picked from commit 6f43c72b472ee78e04f1ebd347ca0ae7787ee876)

3 years agoMakefile.inc1: unbreak bootstrap when kbdcontrol does not exist
Glen Barber [Wed, 24 Mar 2021 00:47:14 +0000 (20:47 -0400)]
Makefile.inc1: unbreak bootstrap when kbdcontrol does not exist

Submitted by: Evgeniy Khramtsov
Reviewed by: arichardson
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 50179c5ec7d09d7b02497caf95dca5d33f93bcd9)

3 years agoaccept_filter: Fix filter parameter handling
Mark Johnston [Thu, 25 Mar 2021 21:55:20 +0000 (17:55 -0400)]
accept_filter: Fix filter parameter handling

For filters which implement accf_create, the setsockopt(2) handler
caches the filter name in the socket, but it also incorrectly frees the
buffer containing the copy, leaving a dangling pointer.  Note that no
accept filters provided in the base system are susceptible to this, as
they don't implement accf_create.

Reported by: Alexey Kulaev <alex.qart@gmail.com>
Discussed with: emaste
Security: kernel use-after-free
MFC after: 3 days
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 653a437c04440495cd8e7712c7cf39444f26f1ee)

3 years agopf: Handle unmapped mbufs when computing checksums
Mark Johnston [Tue, 23 Mar 2021 13:38:59 +0000 (09:38 -0400)]
pf: Handle unmapped mbufs when computing checksums

PR: 254419
Reviewed by: gallatin, kp
Tested by: Igor A. Valkov <viaprog@gmail.com>
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29378

(cherry picked from commit b93a796b06ec013a75a08ac43d8acf6aa94aa970)

3 years agomountd(8): generate a syslog message when the "V4:" line is missing
Rick Macklem [Tue, 9 Mar 2021 00:08:02 +0000 (16:08 -0800)]
mountd(8): generate a syslog message when the "V4:" line is missing

Daniel reported that NFSv4 mounts were not working despite having
set "nfsv4_server_enable=YES" in /etc/rc.conf.  Mountd was logging a
message that there was no /etc/exports file.
He noted that creating a /etc/exports file with a "V4:" line in it
was needed make NFSv4 mounts work.
At least one "V4:" line in one of the exports(5) file(s) is needed to
make NFSv4 mounts work. This patch fixes mountd.c so that it logs a
message indicting that there is no "V4:" line in any exports(5)
file when NFSv4 mounts are enabled.
To avoid this message being generated erroneously, /etc/rc.d/mountd
is updated to make sure vfs.nfsd.server_max_nfsvers is properly set
before mountd(8) is started.

PR: 253901

(cherry picked from commit 09673fc0f36dd1cca74940a240a9ed0f62228084)

3 years agosecurity.7: fix typo in sysctl name
Piotr Pawel Stefaniak [Fri, 26 Mar 2021 21:24:06 +0000 (22:24 +0100)]
security.7: fix typo in sysctl name

It is machdep.syscall_ret_flush_l1d.

(cherry picked from commit 4233882f4ed36bde0ad03918d3f9a54a0cd7697a)

3 years agorelease: amd64: Fix ISO/USB hybrid image
Emmanuel Vadot [Sat, 27 Mar 2021 11:04:51 +0000 (12:04 +0100)]
release: amd64: Fix ISO/USB hybrid image

Recent mkimg changes forces to have partitions given in explicit order.
This is so we can have the first partition starting at a specific offset
and the next ones starting after without having to specify an offset.
Switch the partition in the mkisoimage.sh script so the first one created
is the isoboot one.

PR:    254490
Reported by: Michael Dexter <editor@callfortesting.org
Tested by: Vincent Milum Jr <freebsd@darkain.com>
MFC after: Right now

(cherry picked from commit 90d2f7c413f9fc4ac479fa5e91ba1de6d4ea8d45)

3 years agoelftoolchain: Support building on Arm-based Macs
Jessica Clarke [Sat, 20 Mar 2021 17:58:10 +0000 (17:58 +0000)]
elftoolchain: Support building on Arm-based Macs

Currently macOS and DragonFlyBSD get their own special case and only
handle x86. Since all the FreeBSD cases should be general enough for
macOS and DragonFlyBSD (and the x86 ones are identical to the existing
ones) we can just delete the special cases and reuse the FreeBSD ones.

Note that upstream has since removed all the architecture-specific
checks in this file, with the only code relevant to us being an
endianness check that uses the generic compiler-provided macros. Thus
this patch will not be upstreamed, and will be dropped in a future
vendor import.

(cherry picked from commit 839fdcfc0c1dba34f728813d9756515ad82ff58a)

3 years agotools/build: Improve host-symlinks failure mode
Jessica Clarke [Sat, 20 Mar 2021 13:00:34 +0000 (13:00 +0000)]
tools/build: Improve host-symlinks failure mode

Since set -e is enabled by sys.mk, if the tool cannot be found in PATH
then the entire shell command line fails, causing us to not print the
error message below and instead silently (due to the @) fail, only
getting the usual "Error code 1" print from bmake. Thus, provide a dummy
default that will never exist (the same as is used by meta2deps.sh) if
which fails so that we get the error message as intended.

(cherry picked from commit 8c9e45503fe41732f72e1a4cc9a231e63b4289ba)

3 years agobhyve: support relocating fbuf and passthru data BARs
D Scott Phillips [Thu, 18 Mar 2021 16:08:52 +0000 (00:08 +0800)]
bhyve: support relocating fbuf and passthru data BARs

We want to allow the UEFI firmware to enumerate and assign
addresses to PCI devices so we can boot from NVMe[1]. Address
assignment of PCI BARs is properly handled by the PCI emulation
code in general, but a few specific cases need additional support.
fbuf and passthru map additional objects into the guest physical
address space and so need to handle address updates. Here we add a
callback to emulated PCI devices to inform them of a BAR
configuration change. fbuf and passthru then watch for these BAR
changes and relocate the frame buffer memory segment and passthru
device mmio area respectively.

We also add new VM_MUNMAP_MEMSEG and VM_UNMAP_PPTDEV_MMIO ioctls
to vmm(4) to facilitate the unmapping needed for addres updates.

[1]: https://github.com/freebsd/uefi-edk2/pull/9/

Originally by: scottph
Sponsored by: Intel Corporation
Reviewed by: grehan
Approved by: philip (mentor)
Differential Revision: https://reviews.freebsd.org/D24066

(cherry picked from commit f8a6ec2d572758da6cfd29fcb4ecf4430463661d)

3 years agobhyve amd: Small cleanups in amdvi_dump_cmds
Ka Ho Ng [Tue, 23 Mar 2021 08:11:56 +0000 (16:11 +0800)]
bhyve amd: Small cleanups in amdvi_dump_cmds

Bump offset with MOD_INC instead in amdvi_dump_cmds.

Reviewed by: jhb
Approved by: philip (mentor)
Differential Revision: https://reviews.freebsd.org/D28862

(cherry picked from commit be97fc8dced052f824387a1ae6a0063f9dcfdc89)

3 years agoPlug nexthop group refcount leak.
Alexander V. Chernikov [Wed, 24 Mar 2021 23:51:45 +0000 (23:51 +0000)]
Plug nexthop group refcount leak.
In case with batch route delete via rib_walk_del(), when
 some paths from the multipath route gets deleted, old
 multipath group were not freed.

PR:    254496
Reported by:   Zhenlei Huang <zlei.huang@gmail.com>

(cherry picked from commit 66f138563becf12d5c21924f816d2a45c3a1ed7a)

3 years agoFix panic when destroying interface with ECMP routes.
Alexander V. Chernikov [Tue, 23 Mar 2021 22:00:04 +0000 (22:00 +0000)]
Fix panic when destroying interface with ECMP routes.

Reported by: Zhenlei Huang <zlei.huang at gmail.com>
PR: 254496

(cherry picked from commit a0308e48ec12ae37f525aa3c6d3c1a236fb55dcd)

3 years agoFix kassert panic when inserting multipath routes from multiple threads.
Alexander V. Chernikov [Sun, 21 Mar 2021 18:15:29 +0000 (18:15 +0000)]
Fix kassert panic when inserting multipath routes from multiple threads.

Reported by: Marco Zec <zec at fer.hr>

(cherry picked from commit 2476178e6b09acc8d0fe6b1fb9c1b6f2981f766e)

3 years agoOpenSSL: Regen manual pages for 1.1.1k
Jung-uk Kim [Thu, 25 Mar 2021 16:17:52 +0000 (12:17 -0400)]
OpenSSL: Regen manual pages for 1.1.1k

(cherry picked from commit 7595394130a163b7ff53d9ef3f28fcb87f629d17)

3 years agoOpenSSL: Merge OpenSSL 1.1.1k
Jung-uk Kim [Thu, 25 Mar 2021 15:45:19 +0000 (11:45 -0400)]
OpenSSL: Merge OpenSSL 1.1.1k

Merge commit '94fa08a4bcdfbb3434b025d67d014af3b18e5380'

(cherry picked from commit b6c1fdcdf5033d20c61cc77d66f58f31cc65e2ba)

3 years agoTeach DTrace that unaligned accesses are OK on aarch64, not just x86.
Robert Watson [Mon, 22 Mar 2021 01:50:00 +0000 (01:50 +0000)]
Teach DTrace that unaligned accesses are OK on aarch64, not just x86.

MFC after: 3 days
Reviewed: andrew
Differential Revision: https://reviews.freebsd.org/D29369

3 years agoTune DTrace 'aframes' for the FBT and profile providers on arm64.
Robert Watson [Sun, 21 Mar 2021 00:01:54 +0000 (00:01 +0000)]
Tune DTrace 'aframes' for the FBT and profile providers on arm64.

In both cases, too few frames were trimmed, leading to exception handling
or DTrace internals being exposed in stack traces exposed by D's stack()
primitive.

Reviewed by: emaste, andrew
Differential Revision: https://reviews.freebsd.org/D29356

(cherry picked from commit 599fb1d198ec6792ba062114d2589ca9f01a3568)

3 years agorandom(9): Restore historical [0,2^31-1] output range and related man documention.
Lawrence Stewart [Wed, 24 Mar 2021 04:25:49 +0000 (15:25 +1100)]
random(9): Restore historical [0,2^31-1] output range and related man documention.

Commit SVN r364219 / Git 8a0edc914ffd changed random(9) to be a shim around
prng32(9) and inadvertently caused random(9) to begin returning numbers in the
range [0,2^32-1] instead of [0,2^31-1], where the latter has been the documented
range for decades.

The increased output range has been identified as the source of numerous bugs in
code written against the historical output range e.g. ipfw "prob" rules and
stats(3) are known to be affected, and a non-exhaustive audit of the tree
identified other random(9) consumers which are also likely affected.

As random(9) is deprecated and slated for eventual removal in 14.0, consumers
should gradually be audited and migrated to prng(9).

Submitted by: Loic Prylli <lprylli@netflix.com>
Obtained from: Netflix
Reviewed by: cem, delphij, imp
MFC after: 1 day
MFC to: stable/13, releng/13.0
Differential Revision: https://reviews.freebsd.org/D29385

(cherry picked from commit dbbf3e3f37d67d3eae0931855f8b62b9b299b80a)

3 years agomn: bump deprecation version to 14 in man page as well
Ed Maste [Thu, 25 Mar 2021 02:37:33 +0000 (22:37 -0400)]
mn: bump deprecation version to 14 in man page as well

Fixes: 66e75d9e2ddd ("mn: report that this driver is removed in 14, not 13")
3 years agomn: report that this driver is removed in 14, not 13
Ed Maste [Thu, 25 Mar 2021 02:35:38 +0000 (22:35 -0400)]
mn: report that this driver is removed in 14, not 13

3 years agoarm64: implement COMPAT_FREEBSD32 fill/set dbregs/fpregs
Ed Maste [Wed, 17 Mar 2021 14:10:41 +0000 (10:10 -0400)]
arm64: implement COMPAT_FREEBSD32 fill/set dbregs/fpregs

On FreeBSD/arm fill_fpregs, fill_dbregs are stubs that zero the reg
struct and return success. set_fpregs and set_dbregs do nothing and
return success.

Provide the same implementation for arm64 COMPAT_FREEBSD32.

Reviewed by: andrew
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29314

(cherry picked from commit 5be27cbf16c85ce95d21db57349f61494f851821)

3 years agortsold: Fix validation of RDNSS options
Mark Johnston [Sun, 21 Mar 2021 18:18:10 +0000 (14:18 -0400)]
rtsold: Fix validation of RDNSS options

The header specifies the size of the option in multiples of eight bytes.
The option consists of an eight-byte header followed by one or more IPv6
addresses, so the option is invalid if the size is not equal to 1+2n for
some n>0.  Check this.

The bug can cause random stack data to be formatted as an IPv6 address
and passed to resolvconf(8), but a host able to trigger the bug may also
specify arbitrary addresses this way.

Reported by: Q C <cq674350529@gmail.com>
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 1af332a7d8f86b6fcc1f0f575fe5b06021b54f4c)

3 years agoMFC eeb26cf52c4c51e1571253d57684c442aa79a98d:
Cy Schubert [Wed, 17 Mar 2021 00:06:17 +0000 (17:06 -0700)]
MFC eeb26cf52c4c51e1571253d57684c442aa79a98d:

wpa: import fix for P2P provision discovery processing vulnerability

Latest version available from: https://w1.fi/security/2021-1/

Vulnerability

A vulnerability was discovered in how wpa_supplicant processes P2P
(Wi-Fi Direct) provision discovery requests. Under a corner case
condition, an invalid Provision Discovery Request frame could end up
reaching a state where the oldest peer entry needs to be removed. With
a suitably constructed invalid frame, this could result in use
(read+write) of freed memory. This can result in an attacker within
radio range of the device running P2P discovery being able to cause
unexpected behavior, including termination of the wpa_supplicant process
and potentially code execution.

Vulnerable versions/configurations

wpa_supplicant v1.0-v2.9 with CONFIG_P2P build option enabled

An attacker (or a system controlled by the attacker) needs to be within
radio range of the vulnerable system to send a set of suitably
constructed management frames that trigger the corner case to be reached
in the management of the P2P peer table.

Note: FreeBSD base does not enable P2P.
(cherry picked from commit eeb26cf52c4c51e1571253d57684c442aa79a98d)

3 years agoMFC 1acf24a044aa:
Hans Petter Selasky [Tue, 16 Mar 2021 15:06:42 +0000 (16:06 +0100)]
MFC 1acf24a044aa:
Implement pci_get_relaxed_ordering_enabled() helper function.

Discussed with: kib@
Sponsored by: Mellanox Technologies // NVIDIA Networking

(cherry picked from commit 1acf24a044aaa0391c61af4abe7e018c3bf8a37c)

3 years agonvme: Replace potentially long DELAY() with pause().
Alexander Motin [Wed, 17 Mar 2021 14:30:40 +0000 (10:30 -0400)]
nvme: Replace potentially long DELAY() with pause().

In some cases like broken hardware nvme(4) may wait minutes for
controller response before timeout.  Doing so in a tight spin loop
made whole system unresponsive.

Reviewed by: imp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29309
Sponsored by: iXsystems, Inc.

(cherry picked from commit 4fbbe523653b6d2a0186aca38224efcab941deaa)

3 years agoMFC: Fix post-start check when unbound.conf has moved.
Dag-Erling Smørgrav [Wed, 10 Mar 2021 14:18:59 +0000 (14:18 +0000)]
MFC: Fix post-start check when unbound.conf has moved.

On behalf of: des
Reported by: phk@
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 409388cfac49a312034e9397c870e3f81ff90734)

3 years agoMFC: Fix local-unbound setup for some IPv6 deployments.
Dag-Erling Smørgrav [Wed, 10 Mar 2021 14:01:38 +0000 (14:01 +0000)]
MFC: Fix local-unbound setup for some IPv6 deployments.

On behalf of: des
PR: 250984

(cherry picked from commit e5f02c140bf1e519a95bd6331382e8a2a1b6219f)

3 years agonetmap: fix issues in nm_os_extmem_create()
Vincenzo Maffione [Sat, 20 Mar 2021 17:15:50 +0000 (17:15 +0000)]
netmap: fix issues in nm_os_extmem_create()

- Call vm_object_reference() before vm_map_lookup_done().
- Use vm_mmap_to_errno() to convert vm_map_* return values to errno.
- Fix memory leak of e->obj.

Reported by: markj
Reviewed by: markj
MFC after: 1 week

(cherry picked from commit ee7ffaa2e6e08b63efb4673610875d40964d5058)

3 years agoFix scripted installs on EFI systems after default mounting of the ESP.
Nathan Whitehorn [Tue, 23 Mar 2021 13:19:42 +0000 (09:19 -0400)]
Fix scripted installs on EFI systems after default mounting of the ESP.

Because the ESP mount point (/boot/efi) is in mtree, tar will attempt to
extract a directory at that point post-mount when the system is installed.
Normally, this is fine, since tar can happily set whatever properties it
wants. For FAT32 file systems, however, like the ESP, tar will attempt to
set mtime on the root directory, which FAT does not support, and tar will
interpret this as a fatal error, breaking the install (see
https://github.com/libarchive/libarchive/issues/1516). This issue would
also break scripted installs on bare-metal POWER8, POWER9, and PS3
systems, as well as some ARM systems.

This patch solves the problem in two ways:
- If stdout is a TTY, use the distextract stage instead of tar, as in
  interactive installs. distextract solves this problem internally and
  provides a nicer UI to boot, but requires a TTY.
- If stdout is not a TTY, use tar but, as a stopgap for 13.0, exclude
  boot/efi from tarball extraction and then add it by hand. This is a
  hack, and better solutions (as in the libarchive ticket above) will
  obsolete it, but it solves the most common case, leaving only
  unattended TTY-less installs on a few tier-2 platforms broken.

In addition, fix a bug with fstab generation uncovered once the tar issue
is fixed that umount(8) can depend on the ordering of lines in fstab in a
way that mount(8) does not. The partition editor now writes out fstab in
mount order, making sure umount (run at the end of scripted, but not
interactive, installs) succeeds.

PR: 254395
Approved by: re (gjb)
Reviewed by: gjb, imp
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D29380

(cherry picked from commit c2f16c595eb51c6e0cb6ece3f6f078d738019059)

3 years agopf: pool/kpool conversion code
Kristof Provost [Thu, 11 Mar 2021 10:37:05 +0000 (11:37 +0100)]
pf: pool/kpool conversion code

stuct pf_pool and struct pf_kpool are different. We should not simply
bcopy() them.

Happily it turns out that their differences were all pointers, and the
userspace provided pointers were overwritten by the kernel, so this did
actually work correctly, but we should fix it anyway.

Reviewed by: glebius
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29216

(cherry picked from commit 15b82e00a1640d1b9a1d720c95f65e580be30187)

3 years agopchtherm: fix a wrong bit and a wrong register use
Michal Vanco [Fri, 5 Mar 2021 08:55:30 +0000 (10:55 +0200)]
pchtherm: fix a wrong bit and a wrong register use

Probably just copy-paste errors that slipped in.

(cherry picked from commit 5084dde5f087264cf9a826569d1152c65d88a0fe)

PR: 253915
Reported by: Michal Vanco <michal.vanco@gmail.com>

3 years agoMFC dfb33cb0ef48:
Hans Petter Selasky [Wed, 10 Mar 2021 12:26:09 +0000 (13:26 +0100)]
MFC dfb33cb0ef48:
Allocating the LinuxKPI current structure from a software interrupt thread
must be done using the M_NOWAIT flag after 1ae20f7c70ea .

Sponsored by: Mellanox Technologies // NVIDIA Networking

(cherry picked from commit dfb33cb0ef48084da84072244e8ca486dfcf3a96)

3 years agoMFC d1cbe7908986:
Hans Petter Selasky [Wed, 10 Mar 2021 09:50:01 +0000 (10:50 +0100)]
MFC d1cbe7908986:
Allocating the LinuxKPI current structure from an interrupt thread must be
done using the M_NOWAIT flag after 1ae20f7c70ea .

Sponsored by: Mellanox Technologies // NVIDIA Networking

(cherry picked from commit d1cbe79089868226625c12ef49f51214d79aa427)

3 years agoMFC 6eb60f5b7f7d:
Hans Petter Selasky [Wed, 10 Mar 2021 11:21:01 +0000 (12:21 +0100)]
MFC 6eb60f5b7f7d:
Use the word "LinuxKPI" instead of "Linux compatibility", to not confuse with
user-space Linux compatibility support. No functional change.

Sponsored by: Mellanox Technologies // NVIDIA Networking

(cherry picked from commit 6eb60f5b7f7df1a59de139260aebfa0aa5f6d79e)

3 years agoMFC ebe5cf355dca:
Hans Petter Selasky [Fri, 5 Mar 2021 11:44:06 +0000 (12:44 +0100)]
MFC ebe5cf355dca:
Implement basic support for allocating memory from a specific numa node
in the LinuxKPI.

Differential Revision: https://reviews.freebsd.org/D29077
Reviewed by: markj@ and kib@
Sponsored by: Mellanox Technologies // NVIDIA Networking

(cherry picked from commit ebe5cf355dca1d7827a70b99a9d9c4f97f78691d)

3 years agoMFC c743a6bd4fc0:
Hans Petter Selasky [Sat, 6 Mar 2021 10:25:12 +0000 (11:25 +0100)]
MFC c743a6bd4fc0:
Implement mallocarray_domainset(9) variant of mallocarray(9).

Reviewed by: kib @
Sponsored by: Mellanox Technologies // NVIDIA Networking

(cherry picked from commit c743a6bd4fc0d1be30f9bc9996333ac0ba079563)

3 years agostand: Load INIT_ARRAY and FINI_ARRAY sections
Mark Johnston [Tue, 16 Mar 2021 19:01:41 +0000 (15:01 -0400)]
stand: Load INIT_ARRAY and FINI_ARRAY sections

This is required for preloading modules into a KASAN-configured kernel.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 7b1b5aad95df671aba3192f1669a8d96da481939)

3 years agonlmrsa: Mark deprecated for 14.
John Baldwin [Tue, 16 Mar 2021 21:34:58 +0000 (14:34 -0700)]
nlmrsa: Mark deprecated for 14.

This is the only in-tree driver for the asymmetric crypto support in
OCF that is already marked deprecated for 14.

Sponsored by: Chelsio Communications

(cherry picked from commit 096a84721670d388e432a1f7399251e4b20714f1)

3 years agoiscsi: Mark iSCSI CAM sims as non-pollable.
John Baldwin [Thu, 11 Feb 2021 21:51:20 +0000 (13:51 -0800)]
iscsi: Mark iSCSI CAM sims as non-pollable.

Previously, iscsi_poll() just panicked.  This meant if you got a panic
on a box when using the iSCSI initiator, the attempt to shutdown would
trigger a nested panic and never write out a core.  Now, CCB's sent to
iSCSI devices (such as the sychronize-cache request in dashutdown())
just fail with a timeout during a panic shutdown.

Sponsored by: Chelsio

(cherry picked from commit 47769bc5573fc5d2263f9e20cb06f6c12d0a82e7)

3 years agocam: Don't permit crashdumps on non-pollable devices.
John Baldwin [Thu, 11 Feb 2021 21:51:01 +0000 (13:51 -0800)]
cam: Don't permit crashdumps on non-pollable devices.

If a disk's SIM doesn't support polling, then it can't be used to
store crashdumps.  Leave d_dump NULL in that case so that dumpon(8)
fails gracefully rather than having dumps fail at crash time.

Sponsored by: Chelsio

(cherry picked from commit e07ac3f2fd7336e04178d116033989a6c099fec4)

3 years agocam: Permit non-pollable sims.
John Baldwin [Thu, 11 Feb 2021 21:49:43 +0000 (13:49 -0800)]
cam: Permit non-pollable sims.

Some CAM sim drivers do not support polling (notably iscsi(4)).
Rather than using a no-op poll routine that always times out requests,
permit a SIM to set a NULL poll callback.  cam_periph_runccb() will
fail polled requests non-pollable sims immediately as if they had
timed out.

Sponsored by: Chelsio

(cherry picked from commit 447b3557a9cc5f00a301be8404339f21a9a0faa8)
(cherry picked from commit e6405c8c37335a42a187a9d2470025b57347b1b5)

3 years agoarmv8crypto: note derivation in armv8_crypto_wrap.c
Mitchell Horne [Mon, 15 Mar 2021 13:46:03 +0000 (10:46 -0300)]
armv8crypto: note derivation in armv8_crypto_wrap.c

This file inherits some boilerplate and structure from the analogous
file in aesni(4), aesni_wrap.c. Note the derivation and the copyright
holders of that file.

For example, the AES-XTS bits added in 4979620ece984 were ported from
aesni(4).

Requested by: jmg
Reviewed by: imp, gnn

(cherry picked from commit da45b462664148ff6f8adbe59847c6c06f295391)

3 years agoiflib: Make if_shared_ctx_t a pointer to const
Mark Johnston [Mon, 8 Mar 2021 17:39:06 +0000 (12:39 -0500)]
iflib: Make if_shared_ctx_t a pointer to const

This structure is shared among multiple instances of a driver, so we
should ensure that it doesn't somehow get treated as if there's a
separate instance per interface.  This is especially important for
software-only drivers like wg.

DEVICE_REGISTER() still returns a void * and so the per-driver sctx
structures are not yet defined with the const qualifier.

Reviewed by: gallatin, erj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29102

(cherry picked from commit ffe3def903a5f239c319e5fe12450659658974a5)

3 years agoofwfb: fix boot on LE
Leandro Lupori [Tue, 9 Mar 2021 15:11:58 +0000 (12:11 -0300)]
ofwfb: fix boot on LE

Some framebuffer properties obtained from the device tree were not being
properly converted to host endian.
Replace OF_getprop calls by OF_getencprop where needed to fix this.

This fixes boot on PowerPC64 LE, when using ofwfb as the system console.

Reviewed by:    bdragon
Sponsored by:   Eldorado Research Institute (eldorado.org.br)
MFC after:      1 week
Differential Revision:  https://reviews.freebsd.org/D27475

(cherry picked from commit 043577b721ec4e5c2ab7571e6c05cfd54e49473c)

3 years agoInclude ccompile.h after opt_global.h.
Alexander Motin [Mon, 15 Mar 2021 17:48:50 +0000 (13:48 -0400)]
Include ccompile.h after opt_global.h.

This restores INVARIANTS enabling ZFS_DEBUG when built as module.

Discussed with: freqlabs
MFC after: 1 week

(cherry picked from commit 8ea35c45d5206ad57945ba160484f04450c88b75)

3 years agogenet: Fix problem with forwarding some TCP/IPv6 packets
Mike Karels [Thu, 18 Mar 2021 00:19:24 +0000 (19:19 -0500)]
genet: Fix problem with forwarding some TCP/IPv6 packets

TCP/IPv6 packets to be forwarded can be laid out with only the Ethernet
header in the first mbuf, and these packets are lost.  There was a
previous hack to pullup ICMPv6 packets with such a layout for the
same reason.  Generalize, and pullup any IPv6 packets with only the
Ethernet header in the first mbuf.  Possibly this should also include
IPv4, but that situation has not been observed to fail.

PR: 254060
Reported by: denis at h3q.com
MFC after: 3 days

(cherry picked from commit 2bdcf6237744b2d9d9707d623660d33931daeb52)

3 years agoVendor import of bc 3.3.4
Stefan Eßer [Fri, 19 Mar 2021 08:39:56 +0000 (09:39 +0100)]
Vendor import of bc 3.3.4

This update performs an implicit flush of the output when a script
calls read() in case a prompt is to be displayed in line-buffered
output mode.

(cherry picked from commit 893ecb52db5ed47d6c1e8698334d34e0df651612)

3 years agoMerge tcsh 6.22.03-ceccc7f
Dmitry Chagin [Sun, 14 Mar 2021 16:33:13 +0000 (19:33 +0300)]
Merge tcsh 6.22.03-ceccc7f

PR: 252663

(cherry picked from commit 5224c2a3bc95b431f729f3692f264395248d8acc)

3 years agoSpeed up geom_stats_resync in the presence of many devices
Alan Somers [Sat, 27 Feb 2021 15:59:40 +0000 (08:59 -0700)]
Speed up geom_stats_resync in the presence of many devices

The old code had a O(n) loop, where n is the size of /dev/devstat.
Multiply that by another O(n) loop in devstat_mmap for a total of
O(n^2).

This change adds DIOCGMEDIASIZE support to /dev/devstat so userland can
quickly determine the right amount of memory to map, eliminating the
O(n) loop in userland.

This change decreases the time to run "gstat -bI0.001" with 16,384 md
devices from 29.7s to 4.2s.

Also, fix a memory leak first reported as PR 203097.

Sponsored by: Axcient
Reviewed by: mav, imp
Differential Revision: https://reviews.freebsd.org/D28968

(cherry picked from commit ab63da3564e8ab0907f9d8eb565774848ffdadeb)

3 years agofortune: add a tip about gstat
Alan Somers [Fri, 26 Feb 2021 15:06:07 +0000 (08:06 -0700)]
fortune: add a tip about gstat

(cherry picked from commit 60a632f047cdb6e5314711f593a4d3b1f1d8dde9)

3 years agofusefs: set d_off during VOP_READDIR
Alan Somers [Fri, 12 Feb 2021 01:01:10 +0000 (18:01 -0700)]
fusefs: set d_off during VOP_READDIR

This allows d_off to be used with lseek to position the file so that
getdirentries(2) will return the next entry.  It is not used by
readdir(3).

PR: 253411
Reported by: John Millikin <jmillikin@gmail.com>
Reviewed by: cem
Differential Revision: https://reviews.freebsd.org/D28605

(cherry picked from commit 71befc35061b3c9d8cc07e34c5dce622c848fcdb)

3 years agopf tests: Test tos/dscp matching
Kristof Provost [Wed, 3 Mar 2021 20:15:39 +0000 (21:15 +0100)]
pf tests: Test tos/dscp matching

MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29078

(cherry picked from commit 9d3b2bcf761041bbe79da3de25f2e4142d90b46a)

3 years agopfctl: Add missing 'va' code point name
Kristof Provost [Thu, 4 Mar 2021 12:50:28 +0000 (13:50 +0100)]
pfctl: Add missing 'va' code point name

Add the 'va' (voice-admit, RFC5865) symbolic name.

Reviewed by: rgrimes, gbe (man page)
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29069

(cherry picked from commit b4e3f3c2de6e6dc614f99615e50d0d87f3367ca0)

3 years agofind(1): Refine the HISTORY within the manual page.
Gordon Bergling [Sat, 13 Mar 2021 18:28:26 +0000 (19:28 +0100)]
find(1): Refine the HISTORY within the manual page.

A simple find command appeared in Version 1 AT&T UNIX and was removed in
Version 3 AT&T UNIX. It was rewritten for Version 5 AT&T UNIX and later
be enhanced for the Programmer's Workbench (PWB). These changes were
later incorporated in AT&T UNIX v7.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D29114

(cherry picked from commit a9275d996c229a30879baa42a6d02d24663ac43b)

3 years agofind(1): Mark -not as an extensions to POSIX
Daniel Ebdrup Jensen [Tue, 23 Feb 2021 15:23:09 +0000 (16:23 +0100)]
find(1): Mark -not as an extensions to POSIX

While here, change mdoc macro from Ic to Fl.

PR: 253499
Reported by: Michael Siegel <bugcounterism at malbolge.net>

(cherry picked from commit 75e6f664c469927ca73ecd7b16a8058bc292a451)

3 years agonet80211: Fix a typo in a comment
Gordon Bergling [Sat, 13 Mar 2021 14:51:30 +0000 (15:51 +0100)]
net80211: Fix a typo in a comment

- destionation -> destination
- while here, fix some whitespace issues

(cherry picked from commit d197bf2b20e7efc6ffef520bf96d5f642e26a015)

3 years agoFix a few typos in comments
Gordon Bergling [Sat, 13 Mar 2021 15:37:28 +0000 (16:37 +0100)]
Fix a few typos in comments

- trough -> through

MFC after: 1 week

(cherry picked from commit 183502d1625fbcc3600fbe1d196758b946749569)

3 years agoarm64: Add support for bcm2838 RNG
Gordon Bergling [Sat, 6 Mar 2021 11:28:35 +0000 (12:28 +0100)]
arm64: Add support for bcm2838 RNG

The hardware random number generator of the RPi4 differs slightly
from the version found on the RPi3.

This commit extends the existing bcm2835_rng driver to function on the RPi4.

Submitted by: James Mintram <me at jamesrm dot com>
Reviewed by: markm, cem, delphij
Approved by: csprng(cem, markm)
Differential Revision: https://reviews.freebsd.org/D22493

(cherry picked from commit e797dc58bd29c5bc0873fc620fc11d5332f90e7f)

3 years agoi386: Fix a few typos
Gordon Bergling [Sat, 13 Mar 2021 15:10:01 +0000 (16:10 +0100)]
i386: Fix a few typos

- wheter -> whether
- while here, fix some whitespace issues

(cherry picked from commit 564a3ac63abe166c6174ed3a58e78859a738ee58)

3 years agopf: Fully remove interrupt events on vnet cleanup
Kristof Provost [Wed, 10 Mar 2021 21:56:11 +0000 (22:56 +0100)]
pf: Fully remove interrupt events on vnet cleanup

swi_remove() removes the software interrupt handler but does not remove
the associated interrupt event.
This is visible when creating and remove a vnet jail in `procstat -t
12`.

We can remove it manually with intr_event_destroy().

PR: 254171
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29211

(cherry picked from commit cecfaf9bede9665d6a10f1e575cd5d575450cff7)

3 years agopf: Simplify cleanup
Kristof Provost [Wed, 10 Mar 2021 14:15:16 +0000 (15:15 +0100)]
pf: Simplify cleanup

We can now counter_u64_free(NULL), so remove the checks.

MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29190

(cherry picked from commit 28dc2c954f5096ae594ed5cd7a83d66ce4bf1ded)

3 years agoDocument that uma_zfree_pcpu() allows NULL now
Kristof Provost [Thu, 11 Mar 2021 08:32:01 +0000 (09:32 +0100)]
Document that uma_zfree_pcpu() allows NULL now

While here also document that for counter_u64_free().

Reviewed by: rpokala@
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29215

(cherry picked from commit 51dc8e7f688867e73eb7edc6bc65fdc77c9d5fff)

3 years agouma: allow uma_zfree_pcu(..., NULL)
Kristof Provost [Wed, 10 Mar 2021 14:11:59 +0000 (15:11 +0100)]
uma: allow uma_zfree_pcu(..., NULL)

We already allow free(NULL) and uma_zfree(..., NULL). Make
uma_zfree_pcpu(..., NULL) work as well.
This also means that counter_u64_free(NULL) will work.

These make cleanup code simpler.

MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29189

(cherry picked from commit b8f7267d499c8ef8e70b021879d3e9e087ecc32d)

3 years agopf: Remove redundant kif != NULL checks
Kristof Provost [Wed, 10 Mar 2021 14:50:42 +0000 (15:50 +0100)]
pf: Remove redundant kif != NULL checks

pf_kkif_free() already checks for NULL, so we don't have to check before
we call it.

Reviewed by: melifaro@
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29195

(cherry picked from commit 913e7dc3e0eb7df78ec0e7ecc7dd160a316a3ac6)

3 years agoaltq: Increase maximum number of CBQ and HFSC classes
Kristof Provost [Wed, 3 Mar 2021 10:06:49 +0000 (11:06 +0100)]
altq: Increase maximum number of CBQ and HFSC classes

In some configurations we need more classes than ALTQ supports by
default.  Increase the maximum number of classes we allow.
This will only cost us a comparatively trivial amount of memory, so
there's little reason not to do so.

If ever we find we want even more we may want to consider turning these
defines into a tunable, but for now do the easy thing.

Reviewed by: donner@
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29034

(cherry picked from commit 448732b8e2d9bf4e2656a2e5a9e88cc58b88d4f4)

3 years agopf: Retrieve DSCP value from the IPv6 header
Kristof Provost [Wed, 3 Mar 2021 20:33:42 +0000 (21:33 +0100)]
pf: Retrieve DSCP value from the IPv6 header

Teach pf to read the DSCP value from the IPv6 header so that we can
match on them.

Reviewed by: donner
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29048

(cherry picked from commit f19323847ca894af8a58839f6a2a41691a8e2245)

3 years agopf: Factor out pf_krule_free()
Kristof Provost [Wed, 10 Mar 2021 10:10:04 +0000 (11:10 +0100)]
pf: Factor out pf_krule_free()

Reviewed by: melifaro@
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29194

(cherry picked from commit 5e9dae8e149ae8848f52148b665f3a0d031ca40f)

3 years agolinux: make timerfd_settime(2) set expirations count to zero
shu [Wed, 3 Feb 2021 16:51:45 +0000 (16:51 +0000)]
linux: make timerfd_settime(2) set expirations count to zero

On Linux, read(2) from a timerfd file descriptor returns an unsigned
8-byte integer (uint64_t) containing the number of expirations
that have occurred, if the timer has already expired one or more
times since its settings were last modified using timerfd_settime(),
or since the last successful read(2).  That's to say, once we do
a read or call timerfd_settime(), timer fd's expiration count should
be zero.  Some Linux applications create timerfd and add it to epoll
with LT mode, when event comes, they do timerfd_settime instead
of read to stop event source from trigger.  On FreeBSD,
timerfd_settime(2) didn't set the count to zero, which caused high
CPU utilization.

Submitted by: ankohuu_outlook.com (Shunchao Hu)
Differential Revision: https://reviews.freebsd.org/D28231

(cherry picked from commit ae71b794cbed19e5e25effc3438720ad452ab87c)

3 years agosbin/ifconfig: Get media status with libifconfig
Ryan Moeller [Sun, 28 Feb 2021 20:27:28 +0000 (20:27 +0000)]
sbin/ifconfig: Get media status with libifconfig

Code deduplication.

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D29030

(cherry picked from commit 2803fa471e77dc8f227fe00bbf075de7feb10022)

3 years agolibifconfig: Overhaul ifconfig_media_* interfaces
Ryan Moeller [Tue, 2 Mar 2021 10:29:17 +0000 (10:29 +0000)]
libifconfig: Overhaul ifconfig_media_* interfaces

Define an ifmedia_t type to use for ifmedia words.

Add ifconfig_media_lookup_* functions to lookup ifmedia words by name.

Get media options as an array of option names rather than formatting it
as a comma-delimited list into a buffer.

Sprinkle const on static the static description tables for peace of
mind.

Don't need to zero memory allocated by calloc.

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D29029

(cherry picked from commit c4ba4aa547184ab401204096cdad9def4ab37964)

3 years agozfs: bring back possibility to rewind the checkpoint from
Mariusz Zaborski [Sat, 13 Mar 2021 11:56:17 +0000 (12:56 +0100)]
zfs: bring back possibility to rewind the checkpoint from

Add parsing of the rewind options.

When I was upstreaming the change [1], I omitted the part where we
detect that the pool should be rewind. When the FreeBSD repo has
synced with the OpenZFS, this part of the code was removed.

[1] FreeBSD repo: 277f38abffc6a8160b5044128b5b2c620fbb970c
[2] OpenZFS repo: f2c027bd6a003ec5793f8716e6189c389c60f47a

Originally reviewed by: tsoome, allanjude
Originally reviewed by: kevans (ok from high-level overview)

Signed-off-by: Mariusz Zaborski <oshogbo@vexillium.org>
PR: 254152
Reported by: Zhenlei Huang <zlei.huang at gmail.com>
Obtained from: https://github.com/openzfs/zfs/pull/11730

(cherry picked from commit 653ed678c70376b15cdc42daafa7b4554570cea2)

3 years agovtnet: fix TSO for TCP/IPv6
Michael Tuexen [Thu, 18 Mar 2021 20:25:47 +0000 (21:25 +0100)]
vtnet: fix TSO for TCP/IPv6

The decision whether a TCP packet is sent over IPv4 or IPv6 was
based on ethertype, which works correctly. In D27926 the criteria
was changed to checking if the CSUM_IP_TSO flag is set in the
csum-flags and then considering it to be TCP/IPv4.
However, the TCP stack sets the flag to CSUM_TSO for IPv4 and IPv6,
where CSUM_TSO is defined as CSUM_IP_TSO|CSUM_IP6_TSO.
Therefore TCP/IPv6 packets gets mis-classified as TCP/IPv4,
which breaks TSO for TCP/IPv6.
This patch bases the check again on the ethertype.
This fix is instantly MFCed.

Approved by: re(gjb)
PR: 254366
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D29331

(cherry picked from commit d4697a6b56168876fc0ffec1a0bb1b24d25b198e)

3 years agotail: fix "tail -F" file rotation detection
Chuck Silvers [Tue, 2 Feb 2021 00:21:14 +0000 (16:21 -0800)]
tail: fix "tail -F" file rotation detection

When checking if the newly opened file is the same as the old one,
we need to fstat() the new file descriptor, not the old one again.

Reviewed by: glebius
Sponsored by: Netflix

(cherry picked from commit 7787e7eed9d2a43fb6eb66666040f1b495995a2f)

3 years agonetmap: fix memory leak in NETMAP_REQ_PORT_INFO_GET
Vincenzo Maffione [Mon, 15 Mar 2021 17:39:18 +0000 (17:39 +0000)]
netmap: fix memory leak in NETMAP_REQ_PORT_INFO_GET

The netmap_ioctl() function has a reference counting bug in case of
NETMAP_REQ_PORT_INFO_GET command. When `hdr->nr_name[0] == '\0'`,
the function does not decrease the refcount of "nmd", which is
increased by netmap_mem_find(), causing a refcount leak.

Reported by: Xiyu Yang <sherllyyang00@gmail.com>
Submitted by: Carl Smith <carl.smith@alliedtelesis.co.nz>
MFC after: 3 days
PR: 254311

(cherry picked from commit 0ab5902e8ad93d0a9341dcce386b6c571ee02173)

3 years agovfs: fix vnlru marker handling for filtered/unfiltered cases
Mateusz Guzik [Wed, 17 Mar 2021 21:33:47 +0000 (22:33 +0100)]
vfs: fix vnlru marker handling for filtered/unfiltered cases

The global list has a marker with an invariant that free vnodes are
placed somewhere past that. A caller which performs filtering (like ZFS)
can move said marker all the way to the end, across free vnodes which
don't match. Then a caller which does not perform filtering will fail to
find them. This makes vn_alloc_hard sleep for 1 second instead of
reclaiming, resulting in significant stalls.

Fix the problem by requiring an explicit marker by callers which do
filtering.

As a temporary measure extend vnlru_free to restart if it fails to
reclaim anything.

Big thanks go to the reporter for testing several iterations of the
patch.

Reported by: Yamagi <lists yamagi.org>
Tested by: Yamagi <lists yamagi.org>
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D29324

(cherry picked from commit e9272225e6bed840b00eef1c817b188c172338ee)

3 years ago base: remove if_wg(4) and associated utilities, manpage
Scott Long [Thu, 18 Mar 2021 07:07:56 +0000 (07:07 +0000)]
   base: remove if_wg(4) and associated utilities, manpage

   After length decisions, we've decided that the if_wg(4) driver and
   related work is not yet ready to live in the tree.  This driver has
   larger security implications than many, and thus will be held to
   more scrutiny than other drivers.

Requested by: secteam
Approved by: re

3 years agolink_elf_obj: Add a case missing from 5e6989ba4f26
Mark Johnston [Tue, 16 Mar 2021 19:01:41 +0000 (15:01 -0400)]
link_elf_obj: Add a case missing from 5e6989ba4f26

Fixes: 5e6989ba4f26
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 4aa157dd5b4e72b85dd07ce3c106b742ca371bca)