Commit Graph

271725 Commits

Author SHA1 Message Date
Cy Schubert
c6806434e7 rc.d/ntp: Ensure ntpd.leap-seconds.list is readable by ntpd
When a use sets umask in login.conf(5) to 027 or 077 a subsequently
fetched /var/db/ntpd.leap-seconds.list will inherit the permissions
allowed by the umask, resulting in a file that may not be readable
ntpd running under the ntp account. This patch adds a umask command
to preempt the umask in login.conf(5) prior to fetching a new copy
of the leap-seconds file.

PR:		261298
Reported by:	Martin Waschbusch <martin@waschbuesch.de>
MFC after:	3 days
2022-01-18 06:21:00 -08:00
Randall Stewart
aac52f94ea tcp: Warning cleanup from new compiler.
The clang compiler recently got an update that generates warnings of unused
variables where they were set, and then never used. This revision goes through
the tcp stack and cleans all of those up.

Reviewed by: Michael Tuexen, Gleb Smirnoff
Sponsored by: Netflix Inc.
Differential Revision:
2022-01-18 07:41:18 -05:00
Roger Pau Monné
e0516c7553 x86/apic: remove apic_ops
All supported Xen instances by FreeBSD provide a local APIC
implementation, so there's no need to replace the native local APIC
implementation anymore.

Leave just the ipi_vectored hook in order to be able to override it
with an implementation based on event channels if the underlying local
APIC is not virtualized by hardware. Note the hook cannot use ifuncs,
because at the point where ifuncs are resolved the kernel doesn't yet
know whether it will benefit from using the optimization.

Sponsored by: Citrix Systems R&D
Reviewed by: kib
Differential revision: https://reviews.freebsd.org/D33917
2022-01-18 10:19:04 +01:00
Roger Pau Monné
2450da6776 x86/xen: use x{2}APIC if virtualized by hardware
Instead of using event channels or hypercalls to deal with IPIs and
NMIs.

Using a hardware virtualized APIC should be faster than using any PV
interface, since the VM exit can be avoided.

Xen exposes whether the domain is using hardware assisted x{2}APIC
emulation in a CPUID bit.

Sponsored by: Citrix Systems R&D
2022-01-18 10:18:22 +01:00
Xin LI
cc68614da8 MFV f83ac37f1e: libbsdxml (expat) 2.4.3. 2022-01-17 16:34:41 -08:00
Mark Johnston
5072251428 cryptosoft: Avoid referencing end-of-buffer cursors
Once a crypto cursor has reached the end of its buffer, it is invalid to
call crypto_cursor_segment() for at least some crypto buffer types.
Reorganize loops to avoid this.

Fixes:	cfb7b942be ("cryptosoft: Use multi-block encrypt/decrypt for non-AEAD ciphers.")
Fixes:	a221a8f4a0 ("cryptosoft: Use multi-block encrypt/decrypt for AES-GCM.")
Fixes:	f8580fcaa1 ("cryptosoft: Use multi-block encrypt/decrypt for AES-CCM.")
Fixes:	5022c68732 ("cryptosoft: Use multi-block encrypt/decrypt for ChaCha20-Poly1305.")
Reported and tested by:	madpilot
Discussed with:	jhb
Sponsored by:	The FreeBSD Foundation
2022-01-17 19:01:24 -05:00
Mark Johnston
2188152717 security.7: Minor fixes for ASLR sysctl descriptions
Reviewed by:	debdrup, danfe, emaste
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33908
2022-01-17 16:12:43 -05:00
Mark Johnston
6393594b03 copyin tests: Use the KERN_PROC_VM_LAYOUT sysctl to fetch layout info
... rather than using the KERN_PROC_PS_STRINGS value to derive the top
of the user address space.

Reviewed by:	kib
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33708
2022-01-17 16:12:43 -05:00
Mark Johnston
3ce04aca49 proc: Add a sysctl to fetch virtual address space layout info
This provides information about fixed regions of the target process'
user memory map.

Reviewed by:	kib
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33708
2022-01-17 16:12:43 -05:00
Mark Johnston
1811c1e957 exec: Reimplement stack address randomization
The approach taken by the stack gap implementation was to insert a
random gap between the top of the fixed stack mapping and the true top
of the main process stack.  This approach was chosen so as to avoid
randomizing the previously fixed address of certain process metadata
stored at the top of the stack, but had some shortcomings.  In
particular, mlockall(2) calls would wire the gap, bloating the process'
memory usage, and RLIMIT_STACK included the size of the gap so small
(< several MB) limits could not be used.

There is little value in storing each process' ps_strings at a fixed
location, as only very old programs hard-code this address; consumers
were converted decades ago to use a sysctl-based interface for this
purpose.  Thus, this change re-implements stack address randomization by
simply breaking the convention of storing ps_strings at a fixed
location, and randomizing the location of the entire stack mapping.
This implementation is simpler and avoids the problems mentioned above,
while being unlikely to break compatibility anywhere the default ASLR
settings are used.

The kern.elfN.aslr.stack_gap sysctl is renamed to kern.elfN.aslr.stack,
and is re-enabled by default.

PR:		260303
Reviewed by:	kib
Discussed with:	emaste, mw
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 16:12:36 -05:00
Mark Johnston
758d98debe exec: Remove the stack gap implementation
ASLR stack randomization will reappear in a forthcoming commit.  Rather
than inserting a random gap into the stack mapping, the entire stack
mapping itself will be randomized in the same way that other mappings
are when ASLR is enabled.

No functional change intended, as the stack gap implementation is
currently disabled by default.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 16:11:54 -05:00
Mark Johnston
706f4a81a8 exec: Introduce the PROC_PS_STRINGS() macro
Rather than fetching the ps_strings address directly from a process'
sysentvec, use this macro.  With stack address randomization the
ps_strings address is no longer fixed.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 16:11:54 -05:00
Mark Johnston
5a8413e779 setrlimit: Remove special handling for RLIMIT_STACK with a stack gap
This will not be required with a forthcoming reimplementation of ASLR
stack randomization.  Moreover, this change was not sufficient to enable
the use of a stack size limit smaller than the stack gap itself.

PR:		260303
Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 11:42:13 -05:00
Mark Johnston
3fc21fdd5f sysent: Add a sv_psstringssz field to struct sysentvec
The size of the ps_strings structure varies between ABIs, so this is
useful for computing the address of the ps_strings structure relative to
the top of the stack when stack address randomization is enabled.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 11:42:07 -05:00
Mark Johnston
1544f5add8 Revert "kern_exec: Add kern.stacktop sysctl."
The current ASLR stack gap feature will be removed, and with that the
need for the kern.stacktop sysctl is gone.  All consumers have been
removed.

This reverts commit a97d697122.

Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 11:41:58 -05:00
Mark Johnston
f75b1ff6e5 Revert "libthr: Use kern.stacktop for thread stack calculation."
The current ASLR stack gap feature will be removed, and with that the
need for this change, and the kern.stactop sysctl, is gone.  Moreover,
the approach taken in this revision does not provide compatibility for
old copies of libthr.so, and the revision should have also updated
__libc_map_stacks_exec().

This reverts commit 78df56ccfc.

Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 11:41:49 -05:00
Mark Johnston
dc7526170d posixshm: Report output buffer truncation from kern.ipc.posix_shm_list
PR:		240573
Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33912
2022-01-17 08:35:19 -05:00
Roger Pau Monné
ad15eeeaba x86/xen: fallback when VCPUOP_send_nmi is not available
It has been reported that on some AWS instances VCPUOP_send_nmi
returns -38 (ENOSYS). The hypercall is only available for HVM guests
in Xen 4.7 and newer. Add a fallback to use the native NMI sending
procedure when VCPUOP_send_nmi is not available, so that the NMI is
not lost.

Reported and Tested by: avg
MFC after: 1 week
Fixes: b2802351c1 ('xen: fix dispatching of NMIs')
Sponsored by: Citrix Systems R&D
2022-01-17 11:06:40 +01:00
Alexander V. Chernikov
779fd05344 ifconfig: improve vlan options parsing
PR:	261136
Reported by:	Daniel O'Connor
MFC after:	2 weeks
2022-01-17 09:35:15 +00:00
Alexander V. Chernikov
b1f7154cb1 gitignore: ignore vim swap files & .rej/.orig
Reviewed by:	cem, avg
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D33794
2022-01-17 09:35:15 +00:00
Alexander V. Chernikov
1f70a85b4c linux: add sysctl to pass untranslated interface names
Reviewed by:	kib
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D33792
2022-01-17 09:35:15 +00:00
Alexander V. Chernikov
96c524d8b2 linux: fix linux_recvmsg() MSG_PEEK flag handling
Reviewed by:	kib
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D33790
2022-01-17 09:35:15 +00:00
Edward Tomasz Napierala
b896bdb86d linux: Make compat.linux.preserve_vstatus default to 1
From a user point of view, this makes ^T work out of the box.

Reviewed By:	debdrup (man page)
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D33842
2022-01-17 08:45:01 +00:00
Xin LI
f83ac37f1e Vendor import of expat 2.4.3. 2022-01-16 18:55:26 -08:00
Bjoern A. Zeeb
c3db9d4a14 net80211: ieee80211_dump_node() cosmetics
Printing %p does not need the 0x prefix and while here mark the
ieee80211_node_table argument unused given we do not need it in the
current incarnation of the function.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-01-17 00:01:46 +00:00
Marko Zec
e7abe200c2 fib_algo: shift / mask by constants in dxr_lookup()
Since trie configuration remains invariant during each DXR instance
lifetime, instead of shifting and masking lookup keys by values
computed at runtime, compile upfront several dxr_lookup()
configurations with hardcoded shift / mask constants, and choose the
apropriate lookup function version after each DXR instance rebuild.

In synthetic tests this yields small but measurable (5-10%) lookup
throughput improvement, depending on FIB size and  prefix patterns.

MFC after:	3 days
2022-01-17 00:13:47 +01:00
Bjoern A. Zeeb
d7ce88aafc LinuxKPI: 802.11 correct enum ieee80211_channel_flags
enum ieee80211_channel_flags are used as bit fields and not as 1..n.
Correct the values using BIT(n).

This is also hoped to fix problems with 7260 cards which come up and
panic due to an empty channel list as all channels are set disabled [1].
It will hopefully also fix the one or other oddity.

Reported by:	ambrisko, Mike Tancsa (mike sentex.net) [1]
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-01-16 22:30:38 +00:00
Daniel Gerzo
c8f8299a23 - fix typo
Reported by: Glenn Tam
2022-01-16 18:45:18 +01:00
Ed Maste
2e9bc9d144 libc: correct SPDX tag on strstr.c
It was obtained from musl, and is MIT licensed.

MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2022-01-16 11:56:28 -05:00
Ed Maste
c6750f07b4 libc: fix misleading comment in strstr
Obtained from:	musl c53e9b239418
2022-01-16 11:52:29 -05:00
Kristof Provost
4ca4193760 pf tests: Provoke failure in pf_ioctl_addrule
MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-01-16 09:04:59 +01:00
Kristof Provost
e5ca5e801d pf: ensure we don't destroy an uninitialised lock
The new lock introduced in 5f5e32f1b3 needs to be initialised early so
that it can be safely destroyed if we error out.

Reported-by: syzbot+d76113e9a4ae0c0fcac2@syzkaller.appspotmail.com
MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-01-16 09:04:57 +01:00
Jessica Clarke
340cebe990 etdump: Fix the file name included in the could not open error message
If only one file is passed, this reads the terminating NULL and so
prints (null). If multiple files are passed then this always prints the
second file, which may or may not exist (and will be particularly
confusing if it does exist since the output will include the dump of the
second file).

MFC after:	1 week
2022-01-16 06:55:39 +00:00
Peter Holm
90c5fd4875 stress2: Added a regression test 2022-01-16 07:48:55 +01:00
Peter Holm
5691cbec52 stress2: Added one more unionfs test 2022-01-16 07:33:45 +01:00
Alexander Motin
e76c010899 Fix inverse sleep logic in buf_daemon().
Before commit 3cec5c77d6 buf_daemon() went to longer 1s sleep if
numdirtybuffers <= lodirtybuffers.  After that commit new condition
!BIT_EMPTY(BUF_DOMAINS, &bdlodirty) got opposite -- true when one
or more more domains is above lodirtybuffers.  As result, on freshly
booted system with no dirty buffers buf_daemon() wakes up 10 times
per second and probably only 1 time per second when there is actual
work to do.

MFC after:	1 week
Reviewed by:	kib, markj
Tested by:	pho
Differential revision:	https://reviews.freebsd.org/D33890
2022-01-15 19:32:36 -05:00
Stefan Eßer
10af8e45a8 fread.c: fix undefined behavior
A case of undefined behavior in __fread() has been detected by UBSAN
and reported by Mark Millard:

/usr/main-src/lib/libc/stdio/fread.c:133:10: runtime error: applying
zero offset to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior in
/usr/main-src/lib/libc/stdio/fread.c:133:10

While being benign (the NULL pointer is later passed to memcpy() with
a length argument of 0), this issue causes in the order of 600 Kyua
test cases to fail on systems running a world built with WITH_UBSAN
and WITH_ASAN.

The undefined behavior can be prevented by skipping operations that
have no effect for r == 0. Mark Millard has suggested to only skip
this code segment if fp->_p == NULL, but I have verified that for the
case of r == 0 no further argument checking is performed on the
addresses passed to memcpy() and thus no bugs are hidden from the
sanitizers due to the simpler condition chosen.

Reported by:	Mark Millard (marklmi@yahoo.com)
Tested by:	Mark Millard (marklmi@yahoo.com)
Differential Revision:	https://reviews.freebsd.org/D33903
MFC after:	2 weeks
2022-01-16 00:43:56 +01:00
Bjoern A. Zeeb
c8dafefaee LinuxKPI: 802.11 Refine/add DTIM/TSF handling
Correct data types related to delivery traffic indication map (DTIM)/
timing synchronization function (TSF) and implement/refine their
handling.  This information is used/needed by iwlwifi to set a station
as associated.  This will hopefully avoid more "no beacon heard"
time event failures.

The recording of the Linux specific sync_device_ts is done in the
receive path for now in case we do have the right information
available.  I need to investigate as to how-much it may make sense
to also migrate it into net80211 in the future depending on the
usage in other drivers (or how we did handle this in the past in
natively ported versions, e.g. iwm).

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-01-15 22:22:30 +00:00
Bjoern A. Zeeb
f3229b62a1 LinuxKPI: 802.11 handle connection loss differently
Rather than just bouncing back to SCAN bounce to INIT on connection
loss.  This is should be refined in the future as the comment already
indicates but we need to tie two different worlds together.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-01-15 22:18:58 +00:00
Jessica Clarke
4e3a43905e ofw_pci: Fix incorrectly sized softc causing pci(4) out-of-bounds reads
We do not include sys/rman.h and so machine/resource.h ends up not being
included by the time pci_private.h is included. This means PCI_RES_BUS
is never defined, and so the sc_bus member of pci_softc is not present
when compiling ofw_pci, resulting in the wrong softc size being passed
to DEFINE_CLASS_1 and thus any attempts by pci(4) to access that member
are out-of-bounds reads or writes.

This is pretty fragile; arguably pci_private.h should be including
sys/rman.h, but this is the minimal needed change to fix the bug whilst
maintaining the status quo.

Found by:	CHERI
Reported by:	andrew
2022-01-15 19:03:53 +00:00
Peter Holm
3266a0c5d5 stress2: Added a new unionfs test scenario 2022-01-15 10:21:29 +01:00
Colin Percival
de1292c6ff 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
2022-01-14 17:30:17 -08:00
Colin Percival
4a432614f6 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
2022-01-14 17:30:17 -08:00
Colin Percival
fd980feb57 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
2022-01-14 17:30:17 -08:00
Navdeep Parhar
a727d9531a cxgbe(4): Fix bad races between sysctl and driver detach.
The default sysctl context setup by newbus for a device is eventually
freed by device_sysctl_fini, which runs after the device driver's detach
routine.  sysctl nodes associated with this context must not use any
resources (like driver locks, hardware access, counters, etc.) that are
released by driver detach.

There are a lot of sysctl nodes like this in cxgbe(4) and the fix is to
hang them off a context that is explicitly freed by the driver before it
releases any resource that might be used by a sysctl.

This fixes panics when running "sysctl dev.t6nex dev.cc" in a tight loop
and loading/unloading the driver in parallel.

Reported by:	Suhas Lokesha
MFC after:	1 week
Sponsored by:	Chelsio Communications
2022-01-14 16:44:57 -08:00
Ed Maste
301b2b02df snd_hda: restore pin patch for headphones on Lenovo X1 7th Gen
Fixes:		ef790cc740 ("hdaa: update pin patch configurations")
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33900
2022-01-14 19:23:15 -05:00
Warner Losh
4762aa57ad ata_xpt: Rename probe_softc to aprobe_softc
Since both scsi_xpt and ata_xpt use the same name for the softc, this
can lead to problems in gdb. Avoid the issue by renaming the ata
probe_softc to aprobe_softc as has been done for the aprobe in
0f280cbd0a. This was overlooked at the time.

Sponsored by:		Netflix
MFC After:		2 weeks
2022-01-14 17:21:09 -07:00
Simon J. Gerraty
bacb140f31 Ignore calcru: runtime went backwards for vm_guest
VM's have little control over CPU speed, don't make matters worse
by constantly spaming console.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D33902
2022-01-14 16:07:43 -08:00
Alexander Motin
a9a2cdaf3c cam: Optimize write protection MODE SENSE in da(4).
Before this change on every open da(4) driver read all mode pages to
use only one bit.  It was done so to not depend on the list of pages
supported by the disk.  But I've found that at least for SATL of LSI/
Broadcom HBAs with WD HDDs Power Condition mode page reading may take
significant amount of time, much more than any other mode page, that
visibly increased disk retaste time by GEOM.

Address that by using data returned by the first MODE SENSE request
to limit the following ones to only one (the first for now) mode page.

With the change simultaneous retaste of 39 SATA disks takes about 2.5s
instead of more than 4s before, and I no longer see "dareprobe" status
on GEOM event thread.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.
2022-01-14 18:24:52 -05:00
Eric van Gyzen
d7f944a046 Allow downstream projects to easily add private and internal libs
Allow projects based on the FreeBSD tree to append to _PRIVATELIBS
and _INTERNALLIBS by simply maintaining their own lists of
LOCAL_PRIVATELIBS and LOCAL_INTERNALLIBS, respectively.

Reviewed by:	bdrewery
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D33901
2022-01-14 10:19:19 -06:00