Commit graph

9321 commits

Author SHA1 Message Date
Konstantin Belousov
824cca5934 openat(2): add O_EMPTY_PATH
(cherry picked from commit 5e7cdf1817)
2021-05-19 06:13:14 +03:00
Dmitry Wagin
2886c93d1b libc: Some enhancements to syslog(3)
- Defined MAXLINE constant (8192 octets by default instead 2048) for
  centralized limit setting up. It sets maximum number of characters of
  the syslog message. RFC5424 doesn't limit maximum size of the message.
  Named after MAXLINE in syslogd(8).
- Fixed size of fmt_cpy buffer up to MAXLINE for rendering formatted
  (%m) messages.
- Introduced autoexpansion of sending socket buffer up to MAXLINE.

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

(cherry picked from commit 9bd7345212)
2021-05-14 09:56:46 -04:00
Alex Richardson
fc19e3cb4f libc/string/memset.c: Use unsigned long for stores
While most 64-bit architectures have an assembly implementation of this
file, RISC-V does not. As we now store 8 bytes instead of 4 it should speed
up RISC-V.

Reviewed By:	kib
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D29536

(cherry picked from commit ab147542b7)
2021-05-11 09:39:27 +01:00
Alex Richardson
0e1e71400a libc/string/bcopy.c: Use intptr_t as the copy type
While most 64-bit architectures have an assembly implementation of this
file RISC-V does not. As we now copy 8 bytes instead of 4 it should speed
up RISC-V. Using intptr_t instead of int also allows using this file for
CHERI pure-capability code since trying to copy pointers using integer
loads/stores will invalidate pointers.

Reviewed By:	kib
Obtained from:	CheriBSD (partially)
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D29535

(cherry picked from commit 0b4ad01d91)
2021-05-11 09:39:26 +01:00
Konstantin Belousov
51af250608 Add ptrace(PT_COREDUMP)
(cherry picked from commit 87a64872cd)
2021-05-10 04:03:06 +03:00
Piotr Pawel Stefaniak
c69775749f getdirentries.2: remove unnecessary space
(cherry picked from commit 1fdd6934d5)
2021-05-05 13:04:58 +02:00
Konstantin Belousov
46ec1227e7 connectat(2): clarify that the s argument is socket
(cherry picked from commit 07f229d20c)
2021-05-03 04:26:50 +03:00
Konstantin Belousov
f1d1021fde O_PATH: allow vnode kevent filter on such files
(cherry picked from commit bbf7a4e878)
2021-04-23 14:14:10 +03:00
Konstantin Belousov
7a24523086 Make files opened with O_PATH to not block non-forced unmount
(cherry picked from commit a5970a529c)
2021-04-23 14:14:10 +03:00
Konstantin Belousov
b0c1b3827e open(2): Implement O_PATH
(cherry picked from commit 8d9ed174f3)
2021-04-23 14:14:10 +03:00
Konstantin Belousov
73a642c479 Add AT_EMPTY_PATH for several *at(2) syscalls
(cherry picked from commit 509124b626)
2021-04-23 14:14:10 +03:00
Konstantin Belousov
8bffc9b492 link(2): correct descriptor name in AT_RESOLVE_BENEATH description
(cherry picked from commit c78e124535)
2021-04-23 14:14:09 +03:00
Konstantin Belousov
17ef58221c libc dl_iterate_phdr(): dlpi_tls_data is wrong
(cherry picked from commit dbd2053026)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
4959d4f3ea libc: implement __tls_get_addr() for static binaries
(cherry picked from commit ca46b5698e)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
41331ef7f6 libc: add _get_tp() private function
(cherry picked from commit 06d8a116bd)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
166b390bc5 libc: include rtld.h into static implementations of rtld interface
(cherry picked from commit 7f7489eba3)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
083df155ef libc: constify dummy error message string for dlfcn
(cherry picked from commit 93c14c55ec)
2021-04-23 14:14:07 +03:00
Konstantin Belousov
c3f97dd75a rtld dl_iterate_phdr(): dlpi_tls_data is wrong
(cherry picked from commit d36d681615)
2021-04-23 14:14:06 +03:00
Andrew Walker
8845eea6e2 Fix leak in libc NFSv4 ACL flags parsing
Free memory allocated by strdup() in parse_flags_verbose().

Submitted by:	Andrew Walker <walker.aj325_gmail.com>
Reported by:	valgrind
Reviewed by:	allanjude, freqlabs, rpokala
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D29871

(cherry picked from commit dd559118ab)
2021-04-23 06:41:23 -04:00
Alex Richardson
770517d41a s_scalbn.c: Add missing float.h include
This caused LDBL_MANT_DIG to not be defined and therefore the scalbnl
alias was not being emitted for double==long double platforms.

Fixes:		760b2ffc ("Update scalbn* functions to the musl versions")
Reported by:	Jenkins

(cherry picked from commit f5542795b9)
2021-04-22 10:42:28 +01:00
Alex Richardson
85e5714ec7 Also use the musl scalbn code for ldexp()
Instead of copying the code as 00646ca204
did, include the implementation with the function name re-defined.

(cherry picked from commit aac21e66f9)
2021-04-22 10:42:19 +01:00
Michael Reifenberger
70a2e9a3d4 Improve size readability.
Preserve more space for swap devise names.
Prevent line overflow with long devise name.
Don't draw a bar when swap is not used at all.
Simplify and optimize code.
Change the label to end at end of 100%.
PR:		251655
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D27496

(cherry picked from commit 8d06c3e7a4)
2021-04-21 21:11:36 +02:00
Alex Richardson
9012e6f027 Revert "lib/libc/net/nsdispatch.c: Fix missing unlock and add locking annotations"
This commit should not have introduced any functional changes, but
apparently it did. This appears to have broken LDAP setups.
Reverting for now. Will reland once I have fixed the breakage.

This reverts commit 3496971e61.
Reported By:	Александр Недоцуков, brd

(cherry picked from commit 738314e445)
2021-04-19 09:52:55 +01:00
Mark Johnston
e712521e35 libc: Fix the WITH_HESIOD build
Reported by:	Daniel Braniss <danny@cs.huji.ac.il>

(cherry picked from commit 3b666932d4)
2021-04-12 08:22:53 -04:00
Mateusz Guzik
c16fc9eae3 amd64: import asm strlen into libc
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D28845

(cherry picked from commit 7f06b217c5)
2021-04-10 13:54:12 +00:00
Alex Richardson
c5cde5af4b resolv_test: Fix racy exit check, remove mutexes, and reduce output
Instead of polling nleft[i] (without appropriate memory barriers!) and
using sleep() to detect the exit just call pthread_join() on all threads.

Also replace the use of a mutex that guarding the increments with atomic
fetch_add. This should reduce the runtime of this test on SMP systems.

Finally, remove all the debug printfs unless DEBUG_OUTPUT is set in
the environment.

Test Plan:	still fails sometimes on qemu (but maybe less often?)
Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D29390

(cherry picked from commit 85425bdc5a)
2021-04-10 14:01:05 +01:00
Alex Richardson
3496971e61 lib/libc/net/nsdispatch.c: Fix missing unlock and add locking annotations
The error cases (goto fin) of _nsdispatch were missing the unlock.

This change also drops the checks for __isthreaded since the pthread stubs
are already no-ops if threads are not being used. Dropping those conditionals
allows clang's thread safety analysis to deal with the file and also makes
the code a bit more readable. While touching the file also add a few more
assertions in debug mode that the right locks are held.

Reviewed By:	markj
Differential Revision: https://reviews.freebsd.org/D29372

(cherry picked from commit 5245bf7b92)
2021-04-10 14:01:05 +01:00
Alex Richardson
54d6cf9ec8 Allow using sanitizers for ssp tests with out-of-tree compiler
With an out-of-tree Clang, we can use the -resource-dir flag when linking
to point it at the runtime libraries from the current SYSROOT.
This moves the path to the clang-internal library directory to a separate
.mk file that can be used by Makefiles that want to find the sanitizer
libraries. I intend to re-use this .mk file for my upcoming changes that
allow building the entire base system with ASAN/UBSAN/MSAN.

Reviewed By:	dim
Differential Revision: https://reviews.freebsd.org/D28852

(cherry picked from commit fe525d3f91)
2021-04-10 14:01:04 +01:00
Leandro Lupori
1805ce6945 powerpc64: enforce natural alignment in bcopy
POWER architecture CPUs (Book-S) require natural alignment for
cache-inhibited storage accesses. Since we can't know the caching model
for a page ahead of time, always enforce natural alignment in bcopy.
This fixes a SIGBUS when calling the function with misaligned pointers
on POWER7.

Submitted by:		Bruno Larsen <bruno.larsen@eldorado.org.br>
Reviewed by:		luporl, bdragon (IRC)
MFC after:		1 week
Sponsored by:		Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D28776

(cherry picked from commit 2f56128403)
2021-04-06 08:28:26 -03:00
Leandro Lupori
e21b6ce854 [PowerPC64] Port optimized strcpy to PPC64LE
Submitted by:           Bruno Larsen <bruno.larsen@eldorado.org.br>
Reviewed by:            luporl, bdragon (IRC)
MFC after:              1 week
Sponsored by:           Eldorado Research Institute (eldorado.org.br)
Differential Revision:  https://reviews.freebsd.org/D29067

(cherry picked from commit 9f50aa45be)
2021-04-06 08:26:30 -03:00
Konstantin Belousov
fb698c2c6d amd64 fabs(3): move signbit to .rodata
(cherry picked from commit f548033818)
(cherry picked from commit 6d3f54fd09)
(cherry picked from commit d218c6f6af)
2021-04-06 03:47:34 +03:00
Konstantin Belousov
3a014191d7 libc/<arch>/sys/cerror.S: fix typo
(cherry picked from commit 4c2e9c35fb)
2021-04-06 03:47:34 +03:00
Alex Richardson
8dc9d6a7b0 libc/qsort: Don't allow interposing recursive calls
This causes problems when using ASAN with a runtime older than 12.0 since
the intercept does not expect qsort() to call itself using an interposable
function call. This results in infinite recursion and stack exhaustion
when a binary compiled with -fsanitize=address calls qsort.
See also https://bugs.llvm.org/show_bug.cgi?id=46832 and
https://reviews.llvm.org/D84509 (ASAN runtime patch).

To prevent this problem, this patch uses a static helper function
for the actual qsort() implementation. This prevents interposition and
allows for direct calls. As a nice side-effect, we can also move the
qsort_s checks to the top-level function and out of the recursive calls.

Reviewed By:	kib
Differential Revision: https://reviews.freebsd.org/D28133

(cherry picked from commit cbcfe28f9d)
2021-03-17 09:46:58 +00:00
Alex Richardson
d37fb0e378 AArch64: Don't set flush-subnormals-to-zero flag on startup
This flag has been set on startup since 65618fdda0.
However, This causes some of the math-related tests to fail as they report
zero instead of a tiny number. This fixes at least
/usr/tests/lib/msun/ldexp_test and possibly others.
Additionally, setting this flag prevents printf() from printing subnormal
numbers in decimal form.
See also https://www.openwall.com/lists/musl/2021/02/26/1

PR:		253847
Reviewed By:	mmel
Differential Revision: https://reviews.freebsd.org/D28938

(cherry picked from commit 0e4ff0acbe)
2021-03-17 09:45:56 +00:00
Dimitry Andric
27e68baf24 Build lib/msun tests with compiler builtins disabled
This forces the compiler to emit calls to libm functions, instead of
possibly substituting pre-calculated results at compile time, which
should help to actually test those functions.

Reviewed by:	emaste, arichardson, ngie
Differential Revision: https://reviews.freebsd.org/D28577

(cherry picked from commit cf97d2a1da)

riscv: Add a soft-float implementation of fabs()

We could just use a C implementation using __builtin_fabs(), but using
this assembly version guarantees that there is no additional prolog/epilog
code. Additionally, clang generates worse code for masking off the top bit
than GCC: https://bugs.llvm.org/show_bug.cgi?id=49377.

This fixes the RISCV64 softfloat world build after cf97d2a1da. That commit
added -fno-builtin to the msun tests which resulted in the first references to
fabs (previously the compiler inlined all calls).

Reviewed By:	dim
Reported by:	mjg
Differential Revision: https://reviews.freebsd.org/D28994

(cherry picked from commit 524b018d20)

riscv: Fix whitespace issues in fabs added in 524b018d20

(cherry picked from commit 066dab17e7)
2021-03-09 21:17:10 +01:00
Brandon Bergren
a79735386c [PowerPC64] Fix multiple issues in fpsetmask().
Building R exposed a problem in fpsetmask() whereby we were not properly
clamping the provided mask to the valid range.

R initilizes the mask by calling fpsetmask(~0) on FreeBSD. Since we
recently enabled precise exceptions, this was causing an immediate
SIGFPE because we were attempting to set invalid bits in the fpscr.

Properly limit the range of bits that can be set via fpsetmask().

While here, use the correct fp_except_t type instead of fp_rnd_t.

Reported by:	pkubaj (in IRC)
Sponsored by:	Tag1 Consulting, Inc.

(cherry picked from commit dd95b39235)
2021-03-08 12:40:11 -06:00
Brandon Bergren
8b96d6ac04 [PowerPC] [PowerPCSPE] Fix multiple issues in fpsetmask().
Building R on powerpc64 exposed a problem in fpsetmask() whereby we
were not properly clamping the provided mask to the valid range.

This same issue affects powerpc and powerpcspe.

Properly limit the range of bits that can be set via fpsetmask().

While here, use the correct fp_except_t type instead of fp_rnd_t.

Reported by:	pkubaj, jhibbits (in IRC)
Sponsored by:	Tag1 Consulting, Inc.

(cherry picked from commit 384ee7cc6e)
2021-03-08 12:39:33 -06:00
Konstantin Belousov
6da53183f9 open(2): Remove O_BENEATH and AT_BENEATH
(cherry picked from commit 20e91ca36a)
2021-03-04 21:10:44 +02:00
Konstantin Belousov
efc5f3d454 fhlink(2): the syscalls do not take flag
(cherry picked from commit 600756afb5)
2021-03-04 21:10:39 +02:00
Kyle Evans
c4ccb6d1be jail: allow root to implicitly widen its cpuset to attach
The default behavior for attaching processes to jails is that the jail's
cpuset augments the attaching processes, so that it cannot be used to
escalate a user's ability to take advantage of more CPUs than the
administrator wanted them to.

This is problematic when root needs to manage jails that have disjoint
sets with whatever process is attaching, as this would otherwise result
in a deadlock. Therefore, if we did not have an appropriate common
subset of cpus/domains for our new policy, we now allow the process to
simply take on the jail set *if* it has the privilege to widen its mask
anyways.

With the new logic, root can still usefully cpuset a process that
attaches to a jail with the desire of maintaining the set it was given
pre-attachment while still retaining the ability to manage child jails
without jumping through hoops.

A test has been added to demonstrate the issue; cpuset of a process
down to just the first CPU and attempting to attach to a jail without
access to any of the same CPUs previously resulted in EDEADLK and now
results in taking on the jail's mask for privileged users.

PR:		253724

(cherry picked from commit 60c4ec806d)
2021-03-03 20:04:10 -06:00
Edward Tomasz Napierala
a3576b6207 libc: fix buffer overrun in getrpcport(3)
Reviewed By:	markj
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D27332

(cherry picked from commit 5299d64b2b)
2021-03-02 18:43:26 +00:00
Konstantin Belousov
73dc6674e0 Remove __NO_TLS.
MFC note: this plus the merge of two preliminary removal of __NO_TLS
definitions for mips and risc-v break ABI.  It was decided that doing
ABI break on tier 2 platforms at this stage of 13.0 release process is
better than drag on __NO_TLS presence for the 13.x branch lifetime.

(cherry picked from commit 3ae8d83d04)
2021-03-02 02:49:42 +02:00
Rick Macklem
b96e66349e getdirentries.2: fix for NFS mounts
It was reported that getdirentries(2) was
returning dirents with d_off set to 0 for an NFS
mount.

This is believed to be correct behaviour at
this time (it may change for some NFS mounts
in the future), but is inconsistent with what the
getdirentries(2) man page says.

This patch fixes the man page.

This is a content change.

PR:	253428

(cherry picked from commit a0698341cd)
2021-03-01 13:00:38 -08:00
Guangyuan Yang
12c2780888 pwrite(2): add a BUGS section
Add a BUGS section about using pwrite(2) when O_APPEND is set on the fd.

Submitted by:	Ka Ho Ng <khng300@gmail.com>
Reviewed by:	gbe, yuripv
Differential Revision:	https://reviews.freebsd.org/D28372

(cherry picked from commit 504e64af32)
2021-02-25 06:57:35 +00:00
Jamie Gritton
5dbb407145 MFC jail: Change both root and working directories in jail_attach(2)
jail_attach(2) performs an internal chroot operation, leaving it up to
the calling process to assure the working directory is inside the jail.

Add a matching internal chdir operation to the jail's root.  Also
ignore kern.chroot_allow_open_directories, and always disallow the
operation if there are any directory descriptors open.

Reported by:    mjg
Approved by:    markj, kib

(cherry picked from commit d4380c0cdd)
2021-02-21 21:49:40 -08:00
Konstantin Belousov
f94e8beadb usleep(3): replace 'process' with 'calling thread'
PR:	253395

(cherry picked from commit 4956af2a8f)
2021-02-14 02:45:49 +02:00
Mateusz Guzik
88a580ebee amd64: move memcmp checks upfront
This is a tradeoff which saves jumps for smaller sizes while making
the 8-16 range slower (roughly in line with the other cases).

Tested with glibc test suite.

For example size 3 (most common with vfs namecache) (ops/s):
before:	407086026
after:	461391995

The regressed range of 8-16 (with 8 as example):
before:	540850489
after:	461671032

(cherry picked from commit f1be262ec1)
2021-02-04 17:59:10 +00:00
Mateusz Guzik
068f2402d2 amd64: add a note about simd to libc memset, memmove and memcmp
(cherry picked from commit 0db6aef407)
2021-02-04 17:59:05 +00:00
Mateusz Guzik
8a680912a1 Revert "Reimplement strlen"
This reverts commit 710e45c4b8.

It breaks for some corner cases on big endian ppc64.
Given the stage of the release process it is best to revert for now.

Reported by:	jhibbits

(cherry picked from commit 33f0540b13)
2021-02-03 19:39:49 +00:00
Mateusz Guzik
71b4605138 Drop temporary compat in setproctitle
(cherry picked from commit 46f168bc66)
2021-02-01 12:39:19 +00:00