Commit graph

21702 commits

Author SHA1 Message Date
Eric van Gyzen
ec68cb077b sendfile_test: fix copy-paste bug
Require the newly opened file descriptor to be good, instead of
re-requiring the one that was required three lines earlier.
Thankfully, opening /dev/null is really unlikely to fail.

Reported by:	Coverity
MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit a8fea07c30)
2022-03-02 15:56:31 -06:00
Eric van Gyzen
d895236443 libprocstat kstack: fix race with thread creation
When collecting kernel stacks for a target process, if the process
adds a thread between the two calls to sysctl, ignore the additional
threads.  Previously, procstat would print only a useless error
message.  Now, it prints a consistent snapshot of the stacks.
We know that snapshot is already stale, but it could still be stale
even with a more complex fix to reallocate and retry, so such a fix
is hardly worth the effort.

Reported by:	Daniel.Mitchell@emc.com
MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit 427f12f150)
2022-03-02 15:56:30 -06:00
Glen Barber
9134a39850 13.1: update stable/13 to -PRERELEASE to start the release cycle
Approved by:	re (implicit)
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-02-23 23:21:49 -05:00
Martin Matuska
bfa5e5858f libarchive: import changes from upstream
Libarchive 3.6.0

New features:
PR #1614: tar: new option "--no-read-sparse"
PR #1503: RAR reader: filter support
PR #1585: RAR5 reader: self-extracting archive support

New features (not used in FreeBSD base):
PR #1567: tar: threads support for zstd (#1567)
PR #1518: ZIP reader: zstd decompression support

Security Fixes:
PR #1491, #1492, #1493, CVE-2021-36976:
   fix invalid memory access and out of bounds read in RAR5 reader
PR #1566, #1618, CVE-2021-31566:
   extended fix for following symlinks when processing the fixup list

Other notable bugfixes and improvements:
PR #1620: tar: respect "--ignore-zeros" in c, r and u modes
PR #1625: reduced size of application binaries

Relnotes:	yes

(cherry picked from commit 833a452e9f)
2022-02-23 08:56:34 +01:00
Konstantin Belousov
4cae9d803a Remove PT_GET_SC_ARGS_ALL
Reimplement bdf0f24bb1 by checking for the caller' ABI in
the implementation of PT_GET_SC_ARGS, and copying out everything if
it is Linuxolator.

Also fix a minor information leak: if PT_GET_SC_ARGS_ALL is done on the
thread reused after other process, it allows to read some number of that
thread last syscall arguments. Clear td_sa.args in thread_alloc().

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D31968

(cherry picked from commit f575573ca5)
2022-02-21 13:34:16 +00:00
Edward Tomasz Napierala
8371bf67d6 linux: implement PTRACE_GET_SYSCALL_INFO
This is one of the pieces required to make modern (ie Focal)
strace(1) work.

Reviewed By:	jhb (earlier version)
Sponsored by:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D28212

(cherry picked from commit bdf0f24bb1)
2022-02-21 13:23:50 +00:00
John Baldwin
d378ddab79 libthr: Disable stack unwinding on ARM.
When a thread exits, _Unwind_ForcedUnwind() is used to walk up stack
frames executing pending cleanups pushed by pthread_cleanup_push().
The cleanups are popped by thread_unwind_stop() which is passed as a
callback function to _Unwind_ForcedUnwind().

LLVM's libunwind uses a different function type for the callback on
32-bit ARM relative to all other platforms.  The previous unwind.h
header (as well as the unwind.h from libcxxrt) use the non-ARM type on
all platforms, so this has likely been broken on 32-bit arm since it
switched to using LLVM's libunwind.

For now, just disable stack unwinding on 32-bit arm to unbreak the
build until a proper fix is tested.

(cherry picked from commit bbf4df1722)
2022-02-20 13:29:59 +01:00
John Baldwin
b2127b6f1a Install unwind.h into /usr/include
Install headers from LLVM's libunwind in place of the headers from
libcxxrt and allow C applications to use the library.

As part of this, remove include/unwind.h and switch libthr over to
using the installed unwind.h.

Reviewed by:	dim, emaste
MFC after:	10 days
Differential Revision: https://reviews.freebsd.org/D34065

(cherry picked from commit c00d345665)
2022-02-20 13:29:44 +01:00
John Baldwin
3d6285b4dd Use uintptr_t for return type of _Unwind_GetCFA.
This matches the type in other unwind headers.

Reviewed by:	dim, emaste
Differential Revision:	https://reviews.freebsd.org/D34050

(cherry picked from commit 3a502289d3)
2022-02-20 13:29:05 +01:00
John Baldwin
ad16681721 Use an unsigned 64-bit integer for exception class.
This matches the type in other unwind headers (LLVM libunwind,
libcxxrt, glibc).

NB: include/unwind.h is not installed but is only used by libthr

Reviewed by:	imp, dim, emaste
Differential Revision:	https://reviews.freebsd.org/D34049

(cherry picked from commit b84693501a)
2022-02-20 13:28:58 +01:00
Kristof Provost
c428292cb3 libpfctl: fix pfctl_kill_states()
735748f30a changed the output of the states so that the creator id
endianness would be consistent. This means that we need to convert the
host endianness creatorid back to big-endian before we give it to the
kernel.

MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 6f47a72d8e)
2022-02-18 11:14:59 +01:00
Kristof Provost
63220460d0 libpfctl: fix creatorid endianness
We provide the hostid (which is the state creatorid) to the kernel as a
big endian number (see pfctl/pfctl.c pfctl_set_hostid()), so convert it
back to system endianness when we get it from the kernel.

This avoids a confusing mismatch between the value the user configures
and the value displayed in the state.

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

(cherry picked from commit 735748f30a)
2022-02-18 11:14:58 +01:00
Bora Özarslan
503ac069aa libkvm: fix kvm_walk_pages
Correct bitmap operations in _kvm_bitmap_next.

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

(cherry picked from commit 08055452cb)
2022-02-16 20:18:32 -05:00
Andriy Gapon
e32acf95ea cam_get_device: resolve path links before parsing device name
The CAM subsystem uses bus:taget:lun tuple to address peripherals.  But
for convenience many userland programs such as camcontrol accept devices
names such as da0.  There is a libcam function, cam_open_device, to
support that.  It first calls cam_get_device() to parse the device name
as a driver name and a unit (and handle some special device name
prefixes) and then uses cam_lookup_pass() to find a matching pass
device.

This change extends cam_get_device() to apply realpath(3) to the device
name before parsing it.  This will allow to use tools such as camcontrol
and smartctl with symbolic links that could be friendlier (more
distinguished) names for devices.

Relnotes:	maybe

(cherry picked from commit 1abf1e8c6b)
2022-02-16 09:52:53 +02:00
Konstantin Belousov
d0199f27c0 libc binuptime(): use the right function to get the most significant bit index
PR:	261781

(cherry picked from commit a1f9326607)
2022-02-15 02:36:51 +02:00
Mateusz Piotrowski
8152b699d7 strftime.3: Fix a typo and use St for standards
MFC after:	1 week

(cherry picked from commit 4073917408)
2022-02-14 18:05:07 +01:00
Dimitry Andric
284434f7a6 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 5f2aca8394)
2022-02-11 17:42:30 +01:00
Kyle Evans
7393eedb03 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 773fa8cd13)
(cherry picked from commit c9afc7680f)
2022-02-10 14:21:59 -06:00
Ed Maste
c437ff145c 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 7b1e19ad78)
(cherry picked from commit 93942379cc)
2022-02-09 16:24:54 -05:00
Ed Maste
e610bb4a85 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 2e85df652c)
2022-02-09 16:24:32 -05:00
Ed Maste
317a38ab65 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 19261079b7)
(cherry picked from commit f448c3ed4a)
(cherry picked from commit 1f290c707a)
(cherry picked from commit 0f9bafdfc3)
(cherry picked from commit adb56e58e8)
(cherry picked from commit 576b58108c)
(cherry picked from commit 1c99af1ebe)
(cherry picked from commit 87152f3405)
(cherry picked from commit 172fa4aa75)
2022-02-09 14:53:11 -05:00
Ed Maste
23742427f3 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 9c296a2105)
2022-02-09 12:39:50 -05:00
Ed Maste
b481ed4832 gpart.8: minor tidying
Reported by:	igor(1)

(cherry picked from commit 3524dead81)
2022-02-09 12:39:50 -05:00
Konstantin Belousov
4a978de48b lnumeric.c: replace some space*8 by tabs
(cherry picked from commit 529575be27)
2022-02-09 02:42:46 +02:00
Konstantin Belousov
a6ba681b44 __ctype_load(): check for calloc() failure
(cherry picked from commit ef061a2e29)
2022-02-09 02:42:46 +02:00
Konstantin Belousov
0f674081c4 __numeric_load(): check for calloc() failure
(cherry picked from commit 87151b60e0)
2022-02-09 02:42:46 +02:00
Konstantin Belousov
0c60f03d83 libc/locale/lnumeric.c: minor style
(cherry picked from commit 1aa669c5f9)
2022-02-09 02:42:46 +02:00
Konstantin Belousov
23da067dd4 __monetary_load(): check for calloc() failure
(cherry picked from commit 4d3b84f67c)
2022-02-09 02:42:45 +02:00
Konstantin Belousov
c3f2e156ba libc/locale/lmonetary.c: minor style
(cherry picked from commit 0fed1e6f18)
2022-02-09 02:42:45 +02:00
Konstantin Belousov
7570b84079 __messages_load(): check for calloc() failure
(cherry picked from commit bc9ce839f9)
2022-02-09 02:42:45 +02:00
Konstantin Belousov
f6d0811884 libc/locale/lmessages.c: minor style
(cherry picked from commit 5b7e92d48f)
2022-02-09 02:42:45 +02:00
Konstantin Belousov
a0f1e4c5ca __collate_load(): check for calloc failure
(cherry picked from commit b8ad908ad9)
2022-02-09 02:42:45 +02:00
Konstantin Belousov
e6d728c97c libc/locale/collate.c: minor style
(cherry picked from commit a8be061167)
2022-02-09 02:42:45 +02:00
Konstantin Belousov
e1c53fc8e1 xlocale.c: only call init_key() when locale was successfully allocated
(cherry picked from commit 7bf532c9d4)
2022-02-09 02:42:45 +02:00
Konstantin Belousov
3e4e8d5cbf xlocale.c: check for allocation failure
PR:	261679

(cherry picked from commit b68522308d)
2022-02-09 02:42:45 +02:00
Konstantin Belousov
236a826c14 xlocale.c:init_key(): do not ignore errors from pthread_key_create()
(cherry picked from commit fcdf9d7de5)
2022-02-09 02:42:45 +02:00
Konstantin Belousov
8a8709c408 libc/locale/xlocale.c: minor style
(cherry picked from commit aaa6fa65a6)
2022-02-09 02:42:45 +02:00
Ed Maste
ef9fc5c52c csu: define STRIP_FBSDID
__FBSDID() places the provided string in the output object's .comment
section.  However, with the transition to Git $FreeBSD$ is no longer
expanded and so we emitted a literal $FreeBSD$.

$FreeBSD$ will be addressed in a holistic manner in the future, but at
least avoid embedding it into everything linked on FreeBSD (via csu).

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

(cherry picked from commit cb2d135015)
2022-02-08 15:53:31 -05:00
Ed Maste
53f18b7c20 libc: use standard LF line endings, not CRLF
(cherry picked from commit 29e54af43e)
2022-02-08 15:52:23 -05:00
Piotr Kubaj
8c56b338da riscv64: enable ASAN and UBSAN
Differential review:	https://reviews.freebsd.org/D33875
Approved by:	dim, imp

(cherry picked from commit 9fc1314266)
2022-02-08 13:26:03 +01:00
Piotr Kubaj
cb1bee9bd3 powerpc: Enable LLDB on all powerpc architectures
While LLDB on powerpc and powerpcspe builds as-is, on powerpc64 and
powerpc64le it requires adding a couple of additional source files
to build.

Differential review:	https://reviews.freebsd.org/D34043
Approved by:	dim, imp, emaste

(cherry picked from commit 0b2d2290fe)
2022-02-08 13:26:02 +01:00
Konstantin Belousov
ec2db06d0d stdio: add test for 86a16ada1e: fflush() handling of errors
PR:	76398

(cherry picked from commit 72d5dedfa6)
2022-02-01 05:29:16 +02:00
Konstantin Belousov
afa9a1f5ec __sflush(): on write error, if nothing was written, reset FILE state back
PR:	76398

(cherry picked from commit 86a16ada1e)
2022-02-01 05:29:15 +02:00
Konstantin Belousov
5775b8b392 ptrace(2): document policies affecting access to the facility
(cherry picked from commit a393644ecb)
2022-01-29 03:10:45 +02:00
Dimitry Andric
cb31d2ea4c Sort SRCS in libcxxrt's Makefile, and use += to list sources
No functional change intended.

MFC after:	3 days

(cherry picked from commit 3c3df36600)
2022-01-27 19:58:33 +01:00
Jose Luis Duran
925c54a30f file: Fix cross-compilation on Darwin/macOS
Darwin/macOS does not have pipe2(2).

Apply a similar guard as in f3d7ace4b2
after 43a5ec4eb4.

Pull Request: https://github.com/freebsd/freebsd-src/pull/574

(cherry picked from commit f5ccb3a33e)
2022-01-25 00:05:17 +00:00
Jessica Clarke
5d10ed57e6 libc: Fix "harmless" iconv one-byte overread
Checking there are still bytes left must be done before dereferencing
the pointer, not the other way round. This is harmless on traditional
architectures since the result will immediately be thrown away, and all
callers are in separate translation units so there is no potential for
optimising based on this out-of-bounds read. However, on CHERI, pointers
are bounded, and so this will trap if fed a string that does not have a
NUL within the first len bytes.

Found by:	CHERI
Reviewed by:	brooks

(cherry picked from commit 6d5297569e)
2022-01-24 23:59:47 +00:00
Jessica Clarke
ca45128899 libcrypt: Drop inclusion of libutil.h
This was rendered obsolete in 2012 by a0ee974f0b, since auth_getval
was the only reason the header was included.

MFC after:	1 week

(cherry picked from commit 7d232d647e)
2022-01-24 23:59:19 +00:00
Jessica Clarke
6318e220e3 Bootstrap libz when cross-building from non-FreeBSD
This is needed now libdwarf depends on libz.

Fixes:		dbf05458e3 ("libdwarf: Support consumption of compressed ELF sections")
MFC after:	1 week

(cherry picked from commit 8d5d329553)
2022-01-24 23:59:14 +00:00
Mark Johnston
7a38cb1e4e 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
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f75b1ff6e5)
2022-01-24 09:20:03 -05:00