Commit Graph

4704 Commits

Author SHA1 Message Date
Szabolcs Nagy
dda21f10a7 netinet/in.h: add INADDR_DUMMY from linux v5.13
see

  linux commit 321827477360934dc040e9d3c626bf1de6c3ab3c
  icmp: don't send out ICMP messages with a source address of 0.0.0.0

"RFC7600 reserves a dummy address to be used as a source for ICMP
messages (192.0.0.8/32), so let's teach the kernel to substitute that
address as a last resort if the regular source address selection procedure
fails."
2022-03-08 17:21:26 -05:00
Szabolcs Nagy
ee05b11b67 bits/syscall.h: add landlock syscalls from linux v5.13
see

  linux commit a49f4f81cb48925e8d7cbd9e59068f516e984144
  arch: Wire up Landlock syscalls

  linuxcommit 17ae69aba89dbfa2139b7f8024b757ab3cc42f59
  Merge tag 'landlock_v34' of ... jmorris/linux-security

Landlock provides for unprivileged application sandboxing. The goal of
Landlock is to enable to restrict ambient rights (e.g. global filesystem
access) for a set of processes. Landlock is inspired by seccomp-bpf but
instead of filtering syscalls and their raw arguments, a Landlock rule
can restrict the use of kernel objects like file hierarchies, according
to the kernel semantic.
2022-03-08 17:21:14 -05:00
Szabolcs Nagy
1ee8109ea0 netinet/tcp.h: add tcp_zerocopy_receive fields from linux v5.12
see

  linux commit 7eeba1706eba6def15f6cb2fc7b3c3b9a2651edc
  tcp: Add receive timestamp support for receive zerocopy.

  linux commit 3c5a2fd042d0bfac71a2dfb99515723d318df47b
  tcp: Sanitize CMSG flags and reserved args in tcp_zerocopy_receive.
2022-03-08 17:19:56 -05:00
Szabolcs Nagy
bc89c31112 netinet/tcp.h: add TCP_NLA_* values up to linux v5.12
TCP_NLA_EDT was new in v5.9, see

  linux commit 48040793fa6003d211f021c6ad273477bcd90d91
  tcp: add earliest departure time to SCM_TIMESTAMPING_OPT_STATS

TCP_NLA_TTL is new in v5.12, see

  linux commit e7ed11ee945438b737e2ae2370e35591e16ec371
  tcp: add TTL to SCM_TIMESTAMPING_OPT_STATS
2022-03-08 17:19:54 -05:00
Szabolcs Nagy
9ffd145479 s390x: add ptrace requests from linux v5.12
PTRACE_OLDSETOPTIONS is old, but it was missing, PTRACE_SYSEMU and
PTRACE_SYSEMU_SINGLESTEP are new, see

  linux commit 56e62a73702836017564eaacd5212e4d0fa1c01d
  s390: convert to generic entry
2022-03-08 17:19:52 -05:00
Szabolcs Nagy
f7d3db5bfc bits/syscall.h: add mount_setattr from linux v5.12
new syscall to change the properties of a mount or a mount tree using
file descriptors which the new mount api is based on, see

  linux commit 2a1867219c7b27f928e2545782b86daaf9ad50bd
  fs: add mount_setattr()
2022-03-08 17:19:51 -05:00
Szabolcs Nagy
e99c425827 signal.h: add new sa_flags from linux v5.11
see

  linux commit a54f0dfda754c5cecc89a14dab68a3edc1e497b5
  signal: define the SA_UNSUPPORTED bit in sa_flags

  linux commit 6ac05e832a9e96f9b1c42a8917cdd317d7b6c8fa
  signal: define the SA_EXPOSE_TAGBITS bit in sa_flags

Note: SA_ is in the posix reserved namespace so these linux specific flags
can be exposed when compiling for posix.
2022-03-08 17:19:49 -05:00
Szabolcs Nagy
993cccce13 signal.h: add SYS_USER_DISPATCH si_code value from linux v5.11
see

  linux commit 1d7637d89cfce54a4f4a41c2325288c2f47470e8
  signal: Expose SYS_USER_DISPATCH si_code type
2022-03-08 17:19:48 -05:00
Szabolcs Nagy
3dcbd89690 signal.h: add si_code values for SIGSYS
unlike other si_code defines, SYS_ is not in the posix reserved namespace
which is likely the reason why SYS_SECCOMP was previously missing (was new
in linux v3.5).
2022-03-08 17:19:46 -05:00
Szabolcs Nagy
30c8a1456a netinet/tcp.h: add tcp zerocopy related changes from linux v5.11
see

  linux commit 18fb76ed53865c1b5d5f0157b1b825704590beb5
  net-zerocopy: Copy straggler unaligned data for TCP Rx. zerocopy.

  linux commit 94ab9eb9b234ddf23af04a4bc7e8db68e67b8778
  net-zerocopy: Defer vm zap unless actually needed.
2022-03-08 17:19:44 -05:00
Szabolcs Nagy
b54f481fbc netinet/if_ether.h: add ETH_P_CFM from linux v5.11
see

  linux commit fbaedb4129838252570410c65abb2036b5505cbd
  bridge: uapi: cfm: Added EtherType used by the CFM protocol.
2022-03-08 17:19:43 -05:00
Szabolcs Nagy
c5ecaca743 sys/socket.h: add new SO_ socket options from linux v5.11
see

  linux commit 7fd3253a7de6a317a0683f83739479fb880bffc8
  net: Introduce preferred busy-polling

  linux commit 7c951cafc0cb2e575f1d58677b95ac387ac0a5bd
  net: Add SO_BUSY_POLL_BUDGET socket option
2022-03-08 17:19:40 -05:00
Szabolcs Nagy
f35b99b387 sys/prctl.h: add PR_SET_SYSCALL_USER_DISPATCH from linux v5.11
see

  linux commit 1446e1df9eb183fdf81c3f0715402f1d7595d4cb
  kernel: Implement selective syscall userspace redirection

  linux commit 36a6c843fd0d8e02506681577e96dabd203dd8e8
  entry: Use different define for selector variable in SUD

redirect syscalls to a userspace handler via SIGSYS, except for a specific
range of code. can be toggled via a memory write to a selector variable.
mainly for wine.
2022-03-08 17:19:38 -05:00
Szabolcs Nagy
b21f3ded78 bits/syscall.h: add epoll_pwait2 from linux v5.11
see

  linux commit b0a0c2615f6f199a656ed8549d7dce625d77aa77
  epoll: wire up syscall epoll_pwait2

  linux commit 58169a52ebc9a733aeb5bea857bc5daa71a301bb
  epoll: add syscall epoll_pwait2

epoll_wait with struct timespec timeout instead of int. no time32 variant.
2022-03-08 17:19:36 -05:00
Alexey Kodanev
3aba2150d0 nice: return EPERM instead of EACCES
To comply with POSIX, change errno from EACCES to EPERM
when the caller did not have the required privilege.
2022-03-08 17:15:14 -05:00
jvoisin
74a28a8af2 protect stack canary from leak via read-as-string by zeroing second byte
This reduces entropy of the canary from 64-bit to 56-bit in exchange
for mitigating non-terminated C string overflows by setting the second
byte of the canary to nul, so that off-by-one write overflow with a
nul byte can still be detected.

Idea from GrapheneOS bionic commit 7024d880b51f03a796ff8832f1298f2f1531fd7b
2022-03-08 16:52:25 -05:00
Szabolcs Nagy
7c0c7a75ec math: avoid runtime conversions of floating-point constants
gcc-12 with -frounding-mode will do inexact constant conversions at
runtime according to the runtime rounding mode.

in the math library we want constants to be rounding mode independent
so this patch fixes cases where new runtime conversions happen with
gcc-12.

fortunately this only affects two minor cases, the fix uses global
initializers where rounding mode does not apply.

after the patch the same amount of conversions happen with gcc-12 as
with gcc-11.
2022-03-08 16:27:15 -05:00
Rich Felker
f8bdc30482 fix spurious failures by fgetws when buffer ends with partial character
commit a90d9da1d1 made fgetws look for
changes to errno by fgetwc to detect encoding errors, since ISO C did
not allow the implementation to set the stream's error flag in this
case, and the fgetwc interface did not admit any other way to detect
the error. however, the possibility of fgetwc setting errno to EILSEQ
in the success path was overlooked, and in fact this can happen if the
buffer ends with a partial character, causing mbtowc to be called with
only part of the character available.

since that change was made, the C standard was amended to specify that
fgetwc set the stream error flag on encoding errors, and commit
511d70738b made it do so. thus, there is
no longer any need for fgetws to poke at errno to handle encoding
errors.

this commit reverts commit a90d9da1d1
and thereby fixes the problem.
2022-02-20 20:21:06 -05:00
pelco
5690668a1b add missing strerror text for key management 2022-02-19 19:42:21 -05:00
Rich Felker
3b7b415557 fix out-of-bound read processing time zone data with distant-past dates
this bug goes back to commit 1cc81f5cb0
where zoneinfo file support was first added. in scan_trans, which
searches for the appropriate local time/dst rule in effect at a given
time, times prior to the second transition time caused the -1 slot of
the index to be read to determine the previous rule in effect. this
memory was always valid (part of another zoneinfo table in the mapped
file) but the byte value read was then used to index another table,
possibly going outside the bounds of the mmap. most of the time, the
result was limited to misinterpretation of the rule in effect at that
time (pre-1900s), but it could produce a crash if adjacent memory was
not readable.

the root cause of the problem, however, was that the logic for this
code path was all wrong. as documented in the comment, times before
the first transition should be treated as using the lowest-numbered
non-dst rule, or rule 0 if no non-dst rules exist. if the argument is
in units of local time, however, the rule prior to the first
transition is needed to determine if it falls before or after it, and
that's where the -1 index was wrongly used.

instead, use the documented logic to find out what rule would be in
effect before the first transition, and apply it as the offset if the
argument was given in local time.

the new code has not been heavily tested, but no longer performs
potentially out-of-bounds accesses, and successfully handles the 1883
transition from local mean time to central standard time in the test
case the error was reported for.
2022-02-09 17:48:43 -05:00
Rich Felker
75b3412f3d fix potentially wrong-sign zero in cproj functions at infinity
these are specified to use the sign of the imaginary part of the input
as the sign of zero in the result, but wrongly copied the sign of the
real part.
2022-01-18 17:31:46 -05:00
Rich Felker
52f0deb969 make fseek detect and produce an error for invalid whence arguments
this is a POSIX requirement. we previously relied on the underlying fd
(or other backend) seek operation to produce the error, but since
linux lseek now supports other seek modes (SEEK_DATA and SEEK_HOLE)
which do not interact well with stdio buffering, this is insufficient.
instead, explicitly check whence before performing any operations.
2022-01-09 00:33:56 -05:00
Érico Nogueira
cbacd638e3 add SEEK_DATA and SEEK_HOLE to unistd.h
these are linux specific constants. glibc exposes them behind
_GNU_SOURCE, but, since SEEK_* is reserved for the implementation, we
can simply define them. furthermore, since they can't be used with
fseek() and other functions that deal with FILE, we don't add them to
stdio.h.
2022-01-09 00:31:05 -05:00
Wesley Wiser
c4d4028dde fix failure to use add-cfi scripts on asm when building out-of-tree
use $srcdir in configure test for add-cfi script.
2022-01-07 13:30:46 -05:00
Rich Felker
775bde6b5c fix wcwidth of hangul combining (vowel/final) letters
these characters combine onto a base character (initial) and therefore
need to have width 0. the original binary-search implementation of
wcwidth handled them correctly, but a regression was introduced in
commit 1b0ce9af6d by generating the new
tables from unicode without noticing that the classification logic in
use (unicode character category Mn/Me/Cf) was insufficient to catch
these characters.
2021-12-27 20:08:31 -05:00
Rich Felker
8d404733e1 fix mismatched signatures for strtod_l family
strtod_l, strtof_l, and strtold_l originally existed only as
glibc-ABI-compat symbols. as noted in the commit which added them,
17a60f9d32, making them aliases for the
non-_l functions was a hack and not appropriate if they ever became
public API.

unfortunately, commit 35eb1a1a9b did
make them public without undoing the hack. fix that now by moving the
the _l functions to their own file as wrappers that just throw away
the locale_t argument.
2021-12-09 15:35:13 -05:00
Ismael Luceno
98e688a9da define NULL as nullptr when used in C++11 or later
This should be safer for casting and more compatible with existing code
bases that wrongly assume it must be defined as a pointer.
2021-11-29 17:45:21 -05:00
Rich Felker
8274aaaaa1 fix hwcap access in powerpc-sf setjmp/longjmp
commit 7be59733d7 introduced the
hwcap-based branches to support the SPE FPU, but wrongly coded them as
bitwise tests on the computed address of __hwcap, not a value loaded
from that address. replace the add with indexed load to fix it.
2021-11-29 17:41:43 -05:00
Rich Felker
3733c831f2 fix struct layout mismatch in sound ioctl time32 fallback conversion
the snd_pcm_mmap_control struct used with SNDRV_PCM_IOCTL_SYNC_PTR was
mistakenly defined in the kernel uapi with "before u32" padding both
before and after the first u32 member. our conversion between the
modern struct and the legacy time32 struct was written without
awareness of that mistake, and assumed the time64 version of the
struct was the intended form with padding to match the layout on
64-bit archs. as a result, the struct was not converted correctly when
running on old kernels, with audio glitches as the likely result.

this was discovered thanks to a related bug in the kernel, whereby
32-bit userspace running on a 64-bit kernel also suffered from the
types mismatching. the mistaken layout is now the ABI and can't be
changed -- or at least making a new ioctl to change it would just
result in a worse situation.

our conversion here is changed to treat the snd_pcm_mmap_control
substruct as two separate substructs at locations dependent on
endianness (since the displacement depends on endianness), using the
existing conversion framework.
2021-10-19 16:07:14 -04:00
Érico Nogueira
b76f37fd56 add qsort_r and make qsort a wrapper around it
we make qsort a wrapper by providing a wrapper_cmp function that uses
the extra argument as a function pointer. should be optimized to a tail
call on most architectures, as long as it's built with
-fomit-frame-pointer, so the performance impact should be minimal.

to keep the git history clean, for now qsort_r is implemented in qsort.c
and qsort is implemented in qsort_nr.c.  qsort.c also received a few
trivial cleanups, including replacing (*cmp)() calls with cmp().
qsort_nr.c contains only wrapper_cmp and qsort as a qsort_r wrapper
itself.
2021-09-23 20:09:22 -04:00
Rich Felker
7be59733d7 add SPE FPU support to powerpc-sf
When the soft-float ABI for PowerPC was added in commit
5a92dd95c7, with Freescale cpus using
the alternative SPE FPU as the main use case, it was noted that we
could probably support hard float on them, but that it would involve
determining some difficult ABI constraints. This commit is the
completion of that work.

The Power-Arch-32 ABI supplement defines the ABI profiles, and indeed
ATR-SPE is built on ATR-SOFT-FLOAT. But setjmp/longjmp compatibility
are problematic for the same reason they're problematic on ARM, where
optional float-related parts of the register file are "call-saved if
present". This requires testing __hwcap, which is now done.

In keeping with the existing powerpc-sf subarch definition, which did
not have fenv, the fenv macros are not defined for SPE and the SPEFSCR
control register is left (and assumed to start in) the default mode.
2021-09-23 19:11:46 -04:00
Rich Felker
e3e7189c11 fix undefined behavior in getdelim via null pointer arithmetic and memcpy
both passing a null pointer to memcpy with length 0, and adding 0 to a
null pointer, are undefined. in some sense this is 'benign' UB, but
having it precludes use of tooling that strictly traps on UB. there
may be better ways to fix it, but conditioning the operations which
are intended to be no-ops in the k==0 case on k being nonzero is a
simple and safe solution.
2021-09-11 21:21:43 -04:00
Rich Felker
b713b8b2e4 fix excessively slow TLS performance on some mips models
commit 6d99ad91e8 introduced this
regression as part of a larger change, based on an incorrect
assumption that rdhwr being part of the mips r2 ISA level meant that
the TLS register, known in the mips documentation as UserLocal, was
unconditionally present on chips providing this ISA level and would
not need trap-and-emulate. this turns out to be false.

based on research by Stanislav Kljuhhin and Abilio Marques, who
reported the problem as a performance regression on certain routers
using OpenWRT vs older uclibc-based versions, it turns out the mips
manuals document the UserLocal register as a feature that might or
might not be implemented or enabled, reflected by a cpu capability bit
in the CONFIG3 register, and that Linux checks for this and has to
explicitly enable it on models that have it.

thus, it's indeed possible that r2+ chips can lack the feature,
bringing us back to the situation where Linux only has a fast
trap-and-emulate path for the case where the destination register is
$3. so, always read the thread pointer through $3. this may incur a
gratuitous move to the desired final register on chips where it's not
needed, but it really doesn't matter.
2021-08-12 18:07:44 -04:00
Érico Nogueira
3eed6a6f0a fix error checking in pthread_getname_np
len is unsigned and can never be smaller than 0. though unlikely, an
error in read() would have lead to an out of bounds write to name.

Reported-by: Michael Forney <mforney@mforney.org>
2021-08-06 11:26:15 -04:00
Rich Felker
3f701faace fix libc-internal signal blocking on mips archs
due to historical reasons, the mips signal set has 128 bits rather
than 64 like on every other arch. this was special-cased correctly, at
least for 32-bit mips, at one time, but was inadvertently broken in
commit 7c440977db, and seems never to
have been right on mips64/n32.

as consequenct of this bug, applications making use of high realtime
signal numbers on mips may have been able to execute application code
in contexts where doing so was unsafe.
2021-07-29 23:24:58 -04:00
Rich Felker
0fbd7d6683 fix broken struct shmid_ds on powerpc (32-bit)
the kernel structure has padding of the shm_segsz member up to 64
bits, as well as 2 unused longs at the end. somehow that was
overlooked when the powerpc port was added, and it has been broken
ever since; applications compiled with the wrong definition do not
correctly see the shm_segsz, shm_cpid, and shm_lpid members.

fixing the definition just by adding the missing padding would break
the ABI size of the structure as well as the position of the time64
shm_atime and shm_dtime members we added at the end. instead, just
move one of the unused padding members from the original end (before
time64) of the structure to the position of the missing padding. this
preserves size and preserves correct behavior of any compiled code
that was already working. programs affected by the wrong definition
need to be recompiled with the correct one.
2021-07-06 21:12:02 -04:00
Szabolcs Nagy
4f3d346bff math: fix fmaf not to depend on FE_TOWARDZERO 2021-07-06 00:29:57 -04:00
Rich Felker
937822abb6 fix TZ parsing logic for identifying POSIX-form strings
previously, the contents of the TZ variable were considered a
candidate for a file/path name only if they began with a colon or
contained a slash before any comma. the latter was very sloppy logic
to avoid treating any valid POSIX TZ string as a file name, but it
also triggered on values that are not valid POSIX TZ strings,
including 3-letter timezone names without any offset.

instead, only treat the TZ variable as POSIX form if it begins with a
nonzero standard time name followed by +, -, or a digit.

also, special case GMT and UTC to always be treated as POSIX form
(with implicit zero offset) so that a stray file by the same name
cannot break software that depends on setting TZ=GMT or TZ=UTC.
2021-06-23 17:30:10 -04:00
Khem Raj
1f0c7cb1cc riscv: rename __NR_fstatat __NR_newfstatat
on riscv64 this syscall is called __NR_newfstatat
this helps the name match kernel UAPI for external
programs
2021-06-05 11:47:16 -04:00
Michael Forney
d8cb888db9 remove return with expression in void function 2021-04-27 19:31:48 -04:00
Érico Nogueira
b7a130e0b9 remove unnecessary cast for map_library return
the function already returns (void *)
2021-04-20 15:40:27 -04:00
Érico Rolim
bd3b9c4ca5 add pthread_getname_np function
based on the pthread_setname_np implementation
2021-04-20 15:34:30 -04:00
Rich Felker
e1a51185ce fix popen not to leak pipes from one child to another
POSIX places an obscure requirement on popen which is like a limited
version of close-on-exec:

    "The popen() function shall ensure that any streams from previous
    popen() calls that remain open in the parent process are closed in
    the new child process."

if the POSIX-future 'e' mode flag is passed, producing a pipe FILE
with FD_CLOEXEC on the underlying pipe, this requirement is
automatically satisfied. however, for applications which use multiple
concurrent popen pipes but don't request close-on-exec, fd leaks from
earlier popen calls to later ones could produce deadlock situations
where processes are waiting for a pipe EOF that will never happen.

to fix this, iterate through all open FILEs and add close actions for
those obtained from popen. this requires holding a lock on the open
file list across the posix_spawn call so that additional popen FILEs
are not created after the list is traversed. note that it's still
possible for another popen call to start and create its pipe while the
lock is held, but such pipes are created with O_CLOEXEC and only drop
close-on-exec status (when 'e' flag is omitted) under control of the
lock.
2021-04-20 14:55:10 -04:00
Rich Felker
e74acd59a5 remove spurious lock in popen
the newly allocated FILE * has not yet leaked to the application and
is only visible to stdio internals until popen returns. since we do
not change any fields of the structure observed by libc internals,
only the pipe_pid member, locking is not necessary.
2021-04-20 14:52:08 -04:00
Érico Nogueira
9a40e842df define __STDC_UTF_{16,32}__ macros
these macros are used to indicate that the implementation uses,
respectively, utf-16 and utf-32 encoding for char16_t and char32_t.
2021-04-19 09:49:20 -04:00
Rich Felker
aad50fcd79 fix regression in dl_iterate_phdr reporting of modules with no TLS
__tls_get_addr should not be called with an invalid TLS module id of
0. in practice it probably "works", returning the DTV length as if it
were a pointer, and the callback should probably not inspect
dlpi_tls_data in this case, but it's likely that some real-world
callbacks use a check on dlpi_tls_data being non-null, rather than on
dlpi_tls_modid being nonzero, to conclude that the module has TLS.
2021-04-16 10:20:46 -04:00
Joakim Sindholt
0ea78a6421 nscd: fall back gracefully on kernels without AF_UNIX support 2021-04-16 10:17:42 -04:00
Dominic Chen
95a540e176 mallocng/aligned_alloc: check for malloc failure
With mallocng, calling posix_memalign() or aligned_alloc() will
SIGSEGV if the internal malloc() call returns NULL. This does not
occur with oldmalloc, which explicitly checks for allocation failure.
2021-04-16 10:17:25 -04:00
Rich Felker
2c00f95c1a make epoll_[p]wait a cancellation point
this is a Linux-specific function and not covered by POSIX's
requirements for which interfaces are cancellation points, but glibc
makes it one and existing software relies on it being one.

at some point a review for similar functions that should be made
cancellation points should be done.
2021-04-03 21:16:41 -04:00
Rich Felker
521b4d27a0 fix dl_iterate_phdr dlpi_tls_data reporting to match spec
dl_iterate_phdr was wrongly reporting the address of the DSO's PT_TLS
image rather than the calling thread's instance of the TLS. the man
page, which is essentially normative for a nonstandard function of
this sort, clearly specifies the latter. it does not clarify where
exactly within/relative-to the image the pointer should point, but the
reasonable thing to do is match the ABI's DTP offset, and this seems
to be what other implementations do.
2021-03-26 13:35:41 -04:00