musl
7 months agoriscv64/bits/ptrace.h: add PTRACE_GETFDPIC from linux v6.6 linux
Szabolcs Nagy [Sun, 5 Nov 2023 20:34:16 +0000 (20:34 +0000)]
riscv64/bits/ptrace.h: add PTRACE_GETFDPIC from linux v6.6

see

  linux commit 9549fb354ef1a451ceddfa404ae3e943c5c803d0
  riscv: support the elf-fdpic binfmt loader

7 months agoaarch64/bits/hwcap.h: add HWCAP2_HBC from linux v6.6
Szabolcs Nagy [Sun, 5 Nov 2023 20:15:18 +0000 (20:15 +0000)]
aarch64/bits/hwcap.h: add HWCAP2_HBC from linux v6.6

see

  linux commit 7f86d128e437990fd08d9e66ae7c1571666cff8a
  arm64: add HWCAP for FEAT_HBC (hinted conditional branches)

7 months agox86_64/bits/mman.h: add SHADOW_STACK_SET_TOKEN from linux v6.6
Szabolcs Nagy [Sun, 5 Nov 2023 20:40:27 +0000 (20:40 +0000)]
x86_64/bits/mman.h: add SHADOW_STACK_SET_TOKEN from linux v6.6

used by the map_shadow_stack syscall, see

  linux commit c35559f94ebc3e3bc82e56e07161bb5986cd9761
  x86/shstk: Introduce map_shadow_stack syscall

7 months agox86_64/bits/mman.h: add MAP_ABOVE4G from linux v6.6
Szabolcs Nagy [Sun, 5 Nov 2023 20:25:34 +0000 (20:25 +0000)]
x86_64/bits/mman.h: add MAP_ABOVE4G from linux v6.6

shadow stacks are mapped above 4G to make them unavailable when the
cpu is executing in 32bit mode, see

  linux commit 29f890d1050fc099fd578d9db844d6c0375902b6
  x86/mm: Introduce MAP_ABOVE4G

7 months agox86_64/bits/syscall.h: add map_shadow_stack syscall from linux v6.6
Szabolcs Nagy [Sun, 5 Nov 2023 20:22:17 +0000 (20:22 +0000)]
x86_64/bits/syscall.h: add map_shadow_stack syscall from linux v6.6

x86_64 only syscall for now, see

  linux commit c35559f94ebc3e3bc82e56e07161bb5986cd9761
  x86/shstk: Introduce map_shadow_stack syscall

7 months agobits/syscall.h: add fchmodat2 syscall from linux v6.6
Szabolcs Nagy [Sun, 5 Nov 2023 20:07:24 +0000 (20:07 +0000)]
bits/syscall.h: add fchmodat2 syscall from linux v6.6

see

  linux commit 78252deb023cf0879256fcfbafe37022c390762b
  arch: Register fchmodat2, usually as syscall 452

  linux commit 09da082b07bbae1c11d9560c8502800039aebcea
  fs: Add fchmodat2()

7 months agoelf.h: add note types from linux v6.6
Szabolcs Nagy [Sun, 5 Nov 2023 20:10:56 +0000 (20:10 +0000)]
elf.h: add note types from linux v6.6

see

  linux commit 9300f00439743c4a34d735e1a27118eb68a1504e
  RISC-V: Add ptrace support for vectors

  linux commit 2fab02b25ae7cf5f714ab456b03d9a3fe5ae98c9
  x86: Add PTRACE interface for shadow stack

7 months agosignal.h: add SEGV_CPERR from linux v6.6
Szabolcs Nagy [Sun, 5 Nov 2023 18:20:05 +0000 (18:20 +0000)]
signal.h: add SEGV_CPERR from linux v6.6

triggered when control-flow transfer violates shadow stack or indirect
branch tracking constraints (on x86), see

  linux commit a5f6c2ace9974adf92ce65dacca8126d90adabfe
  x86/shstk: Add user control-protection fault handler

7 months agoaarch64/bits/hwcap.h: add HWCAP2_MOPS from linux v6.5
Szabolcs Nagy [Tue, 19 Sep 2023 19:30:13 +0000 (19:30 +0000)]
aarch64/bits/hwcap.h: add HWCAP2_MOPS from linux v6.5

see

  linux commit b7564127ffcb1a26854d7515a0918d775e663639
  arm64: mops: detect and enable FEAT_MOPS

7 months agoaarch64/bits/signal.h: add sigcontext extensions from linux v6.3
Szabolcs Nagy [Tue, 19 Sep 2023 19:25:40 +0000 (19:25 +0000)]
aarch64/bits/signal.h: add sigcontext extensions from linux v6.3

new register state for SME2 arch extension, see

  linux commit 39e54499280f373d03ab7ffe681ca9d53a9089c9
  arm64/signal: Include TPIDR2 in the signal context

  linux commit ee072cf708048c0d718a88159ae7985dd96d316f
  arm64/sme: Implement signal handling for ZT

7 months agoaarch64/bits/hwcap.h: add HWCAP2_* flags from linux v6.3
Szabolcs Nagy [Tue, 19 Sep 2023 19:16:32 +0000 (19:16 +0000)]
aarch64/bits/hwcap.h: add HWCAP2_* flags from linux v6.3

see

  linux commit 7d5d8601e4577c918fdb5fa922c634a73557ac0f
  arm64/sme: Add hwcaps for SME 2 and 2.1 features

7 months agoelf.h: add NT_PPC_* from linux v6.5
Szabolcs Nagy [Tue, 19 Sep 2023 19:04:16 +0000 (19:04 +0000)]
elf.h: add NT_PPC_* from linux v6.5

NT_PPC_PKEY is linux v4.16, but was missing see

  linux commit c5cc1f4df6b16646f8fae7aab523c1820bf916e8
  powerpc/ptrace: Add memory protection key regset

NT_PPC_DEXCR and NT_PPC_HASHKEYR are new note types to expose new regs
to ptrace and core dumps, see

  linux commit 97228ca375c78bfd960767dcd4919c981add306f
  powerpc/ptrace: Expose HASHKEYR register to ptrace

  linux commit 884ad5c52da253e5d38f947cd8d1d9412a47429c
  powerpc/ptrace: Expose DEXCR and HDEXCR registers to ptrace

7 months agosys/prctl.h: add PR_RISCV_V_* from linux v6.5
Szabolcs Nagy [Tue, 19 Sep 2023 18:59:19 +0000 (18:59 +0000)]
sys/prctl.h: add PR_RISCV_V_* from linux v6.5

for controlling the riscv vector unit, see

  linux commit 1fd96a3e9d5d4febe1a8486590ad52c048d1be77
  riscv: Add prctl controls for userspace vector management

7 months agobits/syscall.h: add cachestat syscall from linux v6.5
Szabolcs Nagy [Sun, 17 Sep 2023 17:40:55 +0000 (17:40 +0000)]
bits/syscall.h: add cachestat syscall from linux v6.5

see

  linux commit cf264e1329fb0307e044f7675849f9f38b44c11a
  cachestat: implement cachestat syscall

7 months agofcntl.h: add AT_HANDLE_FID from linux v6.5
Szabolcs Nagy [Wed, 30 Aug 2023 18:25:22 +0000 (18:25 +0000)]
fcntl.h: add AT_HANDLE_FID from linux v6.5

name_to_handle_at flag when the returned handle is only used to compare
file identity, not usable for open_by_handle_at, see

  linux commit 96b2b072ee62be8ae68c8ecf14854c4d0505a8f8
  exportfs: allow exporting non-decodeable file handles to userspace

7 months agosys/socket.h: add SO_{PEER,PASS}PIDFD from linux v6.5
Szabolcs Nagy [Mon, 28 Aug 2023 11:22:48 +0000 (11:22 +0000)]
sys/socket.h: add SO_{PEER,PASS}PIDFD from linux v6.5

analogous to SCM_CREDENTIALS cmsg and SO_PEERCRED, but with pidfd, see

  linux commit 5e2ff6704a275be009be8979af17c52361b79b89
  scm: add SO_PASSPIDFD and SCM_PIDFD

  linux commit 7b26952a91cf65ff1cc867a2382a8964d8c0ee7d
  net: core: add getsockopt SO_PEERPIDFD

7 months agosys/socket.h: add SCM_SECURITY from linux v2.6.17
Szabolcs Nagy [Mon, 28 Aug 2023 11:33:53 +0000 (11:33 +0000)]
sys/socket.h: add SCM_SECURITY from linux v2.6.17

to retrieve context of an IPSec security association for a socket, see

  linux commit 2c7946a7bf45ae86736ab3b43d0085e43947945c
  [SECURITY]: TCP/UDP getpeersec

7 months agoor1k signal.h: add fpcsr field to mcontext_t from linux v6.4.5
Szabolcs Nagy [Sun, 30 Jul 2023 14:48:37 +0000 (14:48 +0000)]
or1k signal.h: add fpcsr field to mcontext_t from linux v6.4.5

the oldmask field was never used and got repurposed for fenv state, see

  linux commit dceaafd668812115037fc13a1893d068b7b880f5
  openrisc: Union fpcsr and oldmask in sigcontext to unbreak userspace ABI

linux v6.4 broke the mcontext_t abi but it got fixed for v6.4.5.

7 months agoriscv64 syscall.h: add __NR_riscv_hwprobe from linux v6.4
Szabolcs Nagy [Tue, 27 Jun 2023 19:23:52 +0000 (19:23 +0000)]
riscv64 syscall.h: add __NR_riscv_hwprobe from linux v6.4

see

  linux commit ea3de9ce8aa280c5175c835bd3e94a3a9b814b74
  RISC-V: Add a syscall for HW probing

extended HWCAP functionality.

7 months agos390x syscall.h: add __NR_memfd_secret from linux v6.4
Szabolcs Nagy [Tue, 27 Jun 2023 19:17:38 +0000 (19:17 +0000)]
s390x syscall.h: add __NR_memfd_secret from linux v6.4

see

  linux commit 7608f70adcb1ea6957d7b9e1d5bd53584178fbbc
  s390: wire up memfd_secret system call

7 months agosys/ptrace.h: add PTRACE_*_SYSCALL_USER_DISPATCH_CONFIG from linux v6.4
Szabolcs Nagy [Tue, 27 Jun 2023 19:00:35 +0000 (19:00 +0000)]
sys/ptrace.h: add PTRACE_*_SYSCALL_USER_DISPATCH_CONFIG from linux v6.4

see

  linux commit 3f67987cdc09778e75098f9f5168832f8f8e1f1c
  ptrace: Provide set/get interface for syscall user dispatch

so CRIU can restore syscall user dispatch configuration.

7 months agosys/prctl.h: add PR_{GET,SET}_MEMORY_MERGE from linux v6.4
Szabolcs Nagy [Tue, 27 Jun 2023 18:47:44 +0000 (18:47 +0000)]
sys/prctl.h: add PR_{GET,SET}_MEMORY_MERGE from linux v6.4

see

  linux commit d7597f59d1d33e9efbffa7060deb9ee5bd119e62
  mm: add new api to enable ksm per process

to enable kernel spame-page merging for a process.

7 months agosys/prctl.h: add PR_GET_AUXV from linux v6.4
Szabolcs Nagy [Tue, 27 Jun 2023 18:44:27 +0000 (18:44 +0000)]
sys/prctl.h: add PR_GET_AUXV from linux v6.4

see

  linux commit ddc65971bb677aa9f6a4c21f76d3133e106f88eb
  prctl: add PR_GET_AUXV to copy auxv to userspace

7 months agonetinet/in.h: add IP_PROTOCOL from linux v6.4
Szabolcs Nagy [Tue, 27 Jun 2023 18:32:01 +0000 (18:32 +0000)]
netinet/in.h: add IP_PROTOCOL from linux v6.4

see

  linux commit 3632679d9e4f879f49949bb5b050e0de553e4739
  ipv{4,6}/raw: fix output xfrm lookup wrt protocol

7 months agoelf.h: add AT_RSEQ_* from linux v6.3
Szabolcs Nagy [Tue, 9 May 2023 20:09:43 +0000 (20:09 +0000)]
elf.h: add AT_RSEQ_* from linux v6.3

see

  linux commit 317c8194e6aeb8b3b573ad139fc2a0635856498e
  rseq: Introduce feature size and alignment ELF auxiliary vector entries

per-thread rseq area size and alignment.

7 months agoelf.h: add NT_* from linux v6.3
Szabolcs Nagy [Tue, 9 May 2023 20:05:32 +0000 (20:05 +0000)]
elf.h: add NT_* from linux v6.3

see

  linux commit f90b529bcbe57c66da2b6a0d3c7c81e8567af63d
  arm64/sme: Implement ZT0 ptrace support

  linux commit 1a69f7a161a78aead07cd4b811d796950e892fa4
  LoongArch: ptrace: Expose hardware breakpoints to debuggers

7 months agosys/fanotify.h: add FAN_INFO from linux v6.3
Szabolcs Nagy [Tue, 9 May 2023 19:56:39 +0000 (19:56 +0000)]
sys/fanotify.h: add FAN_INFO from linux v6.3

see

  linux commit 70529a199574c15a40f46b14256633b02ba10ca2
  fanotify: define struct members to hold response decision context

7 months agonetinet/in.h: add IP_LOCAL_PORT_RANGE from linux v6.3
Szabolcs Nagy [Tue, 9 May 2023 19:38:02 +0000 (19:38 +0000)]
netinet/in.h: add IP_LOCAL_PORT_RANGE from linux v6.3

see

  linux commit 91d0b78c5177f3e42a4d8738af8ac19c3a90d002
  inet: Add IP_LOCAL_PORT_RANGE socket option

for partitioning the port range between hosts when sharing a single
public IP address (NAT alternative).

7 months agosys/membarrier.h: add MEMBARRIER_CMD_GET_REGISTRATIONS from linux v6.3
Szabolcs Nagy [Tue, 9 May 2023 19:34:17 +0000 (19:34 +0000)]
sys/membarrier.h: add MEMBARRIER_CMD_GET_REGISTRATIONS from linux v6.3

see

  linux commit 544a4f2ecd45f9d6ed78d207583f39130ad40349
  sched/membarrier: Introduce MEMBARRIER_CMD_GET_REGISTRATIONS

to query previous registrations.

7 months agofcntl.h: add F_SEAL_EXEC from linux v6.3
Szabolcs Nagy [Tue, 9 May 2023 19:26:42 +0000 (19:26 +0000)]
fcntl.h: add F_SEAL_EXEC from linux v6.3

see

  linux commit 6fd7353829cafc4067aad9eea0dc95da67e7df16
  mm/memfd: add F_SEAL_EXEC

prevents further modification of the exec mode bits.

7 months agosys/mman.h: add MFD_NOEXEC_SEAL and MFD_EXEC from linux v6.3
Szabolcs Nagy [Tue, 9 May 2023 19:19:38 +0000 (19:19 +0000)]
sys/mman.h: add MFD_NOEXEC_SEAL and MFD_EXEC from linux v6.3

see

  linux commit 105ff5339f498af74e60d7662c8f1c4d21f1342d
  mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC

for controlling the executable mode bit at memfd_create.

7 months agosys/prctl.h: add PR_*_MDWE from linux v6.3
Szabolcs Nagy [Tue, 9 May 2023 19:03:25 +0000 (19:03 +0000)]
sys/prctl.h: add PR_*_MDWE from linux v6.3

see

  linux commit b507808ebce23561d4ff8c2aa1fb949fe402bc61
  mm: implement memory-deny-write-execute as a prctl

like seccomp filtering mprotect(PROT_EXEC|*), but if the mapping is
already PROT_EXEC then allows mprotect(PROT_EXEC|PROT_READ).

7 months agoarm/bits/hwcap.h: add HWCAP values from linux v6.2
Szabolcs Nagy [Sun, 26 Mar 2023 10:29:32 +0000 (10:29 +0000)]
arm/bits/hwcap.h: add HWCAP values from linux v6.2

see

  linux commit fea53546be574f2e357fa53f4a582788b20f283c
  ARM: 9274/1: Add hwcap for Speculative Store Bypassing Safe

  linux commit 3bda6d88489769fba5672dc66debdc1f5516c5fe
  ARM: 9273/1: Add hwcap for Speculation Barrier(SB)

  linux commit 956ca3a4eb81c1b8cc3226af3083847544dcb098
  ARM: 9272/1: vfp: Add hwcap for FEAT_AA32I8MM

  linux commit 23b6d4ad6e7a3028dd88aff7e2b0e5a81da8565e
  ARM: 9271/1: vfp: Add hwcap for FEAT_AA32BF16

  linux commit ce4835497c20991574fde492ab37ec666563d3e4
  ARM: 9270/1: vfp: Add hwcap for FEAT_FHM

  linux commit 62ea0d873af3ef0a7e8387b67241ad43e3d377e1
  ARM: 9269/1: vfp: Add hwcap for FEAT_DotProd

  linux commit c00a19c8b143db31d660ee965e6a6f782ef090ff
  ARM: 9268/1: vfp: Add hwcap FPHP and ASIMDHP for FEAT_FP16

Not adding HWCAP_ARM_ variants as glibc did not add those either.

7 months agoaarch64/bits/hwcap.h: add HWCAP2 flags from linux v6.2
Szabolcs Nagy [Sun, 26 Mar 2023 10:24:32 +0000 (10:24 +0000)]
aarch64/bits/hwcap.h: add HWCAP2 flags from linux v6.2

see

  linux commit d12aada8dfb030f7df8ec0bb0ce4bb01a2ab3944
  arm64/hwcap: Add support for SVE 2.1

  linux commit 939e4649d4fd54b622d08cd57100828df7a82074
  arm64/hwcap: Add support for FEAT_RPRFM

  linux commit 95aa6860d60881e8f08956e02199f7d65c9cbf7b
  arm64/hwcap: Add support for FEAT_CSSC

7 months agonetinet/tcp.h: add tcp_info fields from linux v6.2
Szabolcs Nagy [Sun, 26 Mar 2023 09:49:48 +0000 (09:49 +0000)]
netinet/tcp.h: add tcp_info fields from linux v6.2

see

  linux commit 71fc704768f601ed3fa36310822a5e03f310f781
  tcp: add rcv_wnd and plb_rehash to TCP_INFO

7 months agonetinet/tcp.h: add TCP_NLA_REHASH from linux v6.2
Szabolcs Nagy [Sun, 26 Mar 2023 09:52:51 +0000 (09:52 +0000)]
netinet/tcp.h: add TCP_NLA_REHASH from linux v6.2

nlattr type to query PLB and timeout triggered rehash attempts via
SCM_TIMESTAMPING_OPT_STATS, see

  linux commit 29c1c44646aec5d5134f2365259a84becc1ee7d3
  tcp: add u32 counter in tcp_sock and an SNMP counter for PLB

7 months agoaarch64/bits/hwcap.h: add HWCAP2_SVE_EBF16 from linux v6.1
Szabolcs Nagy [Sat, 17 Dec 2022 00:10:39 +0000 (00:10 +0000)]
aarch64/bits/hwcap.h: add HWCAP2_SVE_EBF16 from linux v6.1

see

  linux commit 81ff692ad924da2233381bedff90c5c1f5c31368
  arm64/sysreg: Add hwcap for SVE EBF16

7 months agosys/mman.h: add MADV_COLLAPSE from linux v6.1
Szabolcs Nagy [Fri, 16 Dec 2022 23:49:39 +0000 (23:49 +0000)]
sys/mman.h: add MADV_COLLAPSE from linux v6.1

see

  linux commit 7d8faaf155454f8798ec56404faca29a82689c77
  mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse

To synchronously convert a memory range from using native to hugepages.
Useful for malloc implementations that work with hugepage sized chunks
but may release native page sized bits with MADV_DONTNEED, then later
want to ensure hugepage is used again.

7 months agonetinet/if_ether.h: add ETH_P_CANXL from linux v6.1
Szabolcs Nagy [Fri, 16 Dec 2022 23:46:58 +0000 (23:46 +0000)]
netinet/if_ether.h: add ETH_P_CANXL from linux v6.1

see

  linux commit fb08cba12b52cba4366e858932307649dc5304e2
  can: canxl: update CAN infrastructure for CAN XL frames

7 months agonetinet/in.h: add IPPROTO_L2TP from linux v6.1
Szabolcs Nagy [Fri, 16 Dec 2022 23:41:15 +0000 (23:41 +0000)]
netinet/in.h: add IPPROTO_L2TP from linux v6.1

see

  linux commit 65b32f801bfbc54dc98144a6ec26082b59d131ee
  uapi: move IPPROTO_L2TP to in.h

7 months agoaarch64/bits/hwcap.h: add HWCAP2_EBF16 from linux v6.0
Szabolcs Nagy [Fri, 7 Oct 2022 18:55:54 +0000 (18:55 +0000)]
aarch64/bits/hwcap.h: add HWCAP2_EBF16 from linux v6.0

see

  linux commit a6a468f50d6a1fa20bcd023f286713d243f5025d
  arm64/hwcap: Support FEAT_EBF16

7 months agobits/termios.h: add ADDRB from linux v6.0
Szabolcs Nagy [Fri, 7 Oct 2022 18:53:31 +0000 (18:53 +0000)]
bits/termios.h: add ADDRB from linux v6.0

see

  linux commit 4f768e94774c58c9f7f54ebd38dadf172970046a
  serial: Support for RS-485 multipoint addresses

7 months agoelf.h: add NT_S390_PV_CPU_DATA from linux v6.0
Szabolcs Nagy [Fri, 7 Oct 2022 18:39:17 +0000 (18:39 +0000)]
elf.h: add NT_S390_PV_CPU_DATA from linux v6.0

see

  linux commit a0c0c44e9aa2b5da876467083c359b368f3ce95e
  s390: add ELF note type for encrypted CPU state of a PV VCPU

7 months agonetinet/if_ether.h: add ETH_P_DSA_A5PSW from linux v6.0
Szabolcs Nagy [Fri, 7 Oct 2022 18:28:23 +0000 (18:28 +0000)]
netinet/if_ether.h: add ETH_P_DSA_A5PSW from linux v6.0

see

  linux commit a08d6a6dc82036cbd889fe3d53f9c69dc13436eb
  net: dsa: add Renesas RZ/N1 switch tag driver

7 months agopowerpc64: bits/signal.h: bump MINSIGSTKSZ as in linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 13:49:09 +0000 (13:49 +0000)]
powerpc64: bits/signal.h: bump MINSIGSTKSZ as in linux v5.19

linux increased the MINSIGSTKSZ above the value in musl, so we bump
the value to avoid sigaltstack failure. SIGSTKSZ is updated to have
the same overhead on top of MINSIGSTKSZ as before.

  linux commit 2f82ec19757f58549467db568c56e7dfff8af283
  powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ

7 months agom68k: bits/ptrace.h: add fdpic macros from linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 13:43:09 +0000 (13:43 +0000)]
m68k: bits/ptrace.h: add fdpic macros from linux v5.19

see

  linux commit 67b660b1f7e5611108e05ca97bd387e141fc61b6
  m68knommu: add definitions to support elf_fdpic program loader

7 months agoaarch64: bits/signal.h: add SME definitions from linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 13:31:36 +0000 (13:31 +0000)]
aarch64: bits/signal.h: add SME definitions from linux v5.19

With the SME arch extension SVE register state can be in streaming
mode and there is a new ZA register state. see

  linux commit 85ed24dad2904f7c141911d91b7807ab02694b5e
  arm64/sme: Implement streaming SVE signal handling

  linux commit 39782210eb7e87634d96cacb6ece370bc59d74ba
  arm64/sme: Implement ZA signal handling

7 months agoaarch64: bits/hwcap.h: add HWCAP2 flags from linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 13:13:40 +0000 (13:13 +0000)]
aarch64: bits/hwcap.h: add HWCAP2 flags from linux v5.19

see

  linux commit 5e64b862c4823ab53aac028042abd918c2f27041
  arm64/sme: Basic enumeration support

  linux commit 69bb02ebc38ace438c9cd7c5315cfe43862b51fe
  arm64: Add HWCAP advertising FEAT_WFXT

7 months agoioctl.h: add N_CAN327 from linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 13:10:47 +0000 (13:10 +0000)]
ioctl.h: add N_CAN327 from linux v5.19

see

  linux commit ec5ad331680c96ef3dd30dc297b206988023b9e1
  tty: Add N_CAN327 line discipline ID for ELM327 based CAN driver

7 months agoprctl.h: add PR_SME_* from linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 13:04:32 +0000 (13:04 +0000)]
prctl.h: add PR_SME_* from linux v5.19

see

  linux commit 9e4ab6c89109472082616f8d2f6ada7deaffe161
  arm64/sme: Implement vector length configuration prctl()s

7 months agoelf.h: add NT_ARM_{SSVE,ZA} from linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 12:41:01 +0000 (12:41 +0000)]
elf.h: add NT_ARM_{SSVE,ZA} from linux v5.19

see

  linux commit e12310a0d30f260b26297bc8d7c95769489af038
  arm64/sme: Implement ptrace support for streaming mode SVE registers

  linux commit 776b4a1cf36411e96972455ca72906b722b80ea1
  arm64/sme: Add ptrace support for ZA

7 months agoelf.h: add NT_LOONGARCH_* from linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 12:37:24 +0000 (12:37 +0000)]
elf.h: add NT_LOONGARCH_* from linux v5.19

see

  linux commit 08145b087e4481458f6075f3af58021a3cf8a940
  LoongArch: Add ELF-related definitions

7 months agoelf.h: add EM_LOONGARCH from linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 12:29:55 +0000 (12:29 +0000)]
elf.h: add EM_LOONGARCH from linux v5.19

see

  linux commit 08145b087e4481458f6075f3af58021a3cf8a940
  LoongArch: Add ELF-related definitions

7 months agosys/socket.h: add SO_RCVMARK from linux v5.19
Szabolcs Nagy [Fri, 26 Aug 2022 12:16:21 +0000 (12:16 +0000)]
sys/socket.h: add SO_RCVMARK from linux v5.19

see

  linux commit 6fd1d51cfa253b5ee7dae18d7cf1df830e9b6137
  net: SO_RCVMARK socket option for SO_MARK with recvmsg()

7 months agoaarch64: add HWCAP2_MTE3 from linux v5.18
Szabolcs Nagy [Sat, 18 Jun 2022 10:51:58 +0000 (10:51 +0000)]
aarch64: add HWCAP2_MTE3 from linux v5.18

see

  linux commit d082a0255fcb8fcb4bd8257df111f2caa67086bc
  arm64/mte: Add hwcap for asymmetric mode

7 months agosys/ioctl.h: add N_DEVELOPMENT ldisc number from linux v5.18
Szabolcs Nagy [Sat, 18 Jun 2022 10:48:09 +0000 (10:48 +0000)]
sys/ioctl.h: add N_DEVELOPMENT ldisc number from linux v5.18

see

  linux commit c2faf737abfb10f88f2d2612d573e9edc3c42c37
  tty: Reserve ldisc 29 for development purposes

7 months agonetinet/if_ether.h: add new ETH_P_ protocol ids from linux v5.18
Szabolcs Nagy [Sat, 18 Jun 2022 10:44:02 +0000 (10:44 +0000)]
netinet/if_ether.h: add new ETH_P_ protocol ids from linux v5.18

see

  linux commit cd73cda742fbe1f33ed7306c7a01aa64f4e6ebd5
  if_ether.h: add EtherCAT Ethertype

  linux commit dd0ca255f3d27a1bb43d8e9529fb3645f9a341a3
  if_ether.h: add PROFINET Ethertype

7 months agoelf.h: add PT_AARCH64_MEMTAG_MTE from linux v5.18
Szabolcs Nagy [Sat, 18 Jun 2022 10:37:42 +0000 (10:37 +0000)]
elf.h: add PT_AARCH64_MEMTAG_MTE from linux v5.18

for memory tags in core dumps, see

  linux commit c35fe2a68f29a0bda15ae994154cacaae5f69791
  elf: Fix the arm64 MTE ELF segment name and value

  linux commit 761b9b366cec0c81a1cd80930f00611d86521d1b
  elf: Introduce the ARM MTE ELF segment type

7 months agosys/socket.h: add SO_TXREHASH from linux v5.18
Szabolcs Nagy [Sat, 18 Jun 2022 10:19:18 +0000 (10:19 +0000)]
sys/socket.h: add SO_TXREHASH from linux v5.18

see

  linux commit 26859240e4ee701e0379f08634957adaff67e43a
  txhash: Add socket option to control TX hash rethink behavior

7 months agosys/mman.h: add MADV_DONTNEED_LOCKED from linux v5.18
Szabolcs Nagy [Sat, 18 Jun 2022 10:10:49 +0000 (10:10 +0000)]
sys/mman.h: add MADV_DONTNEED_LOCKED from linux v5.18

affects mlocked pages too, see

  linux commit 9457056ac426e5ed0671356509c8dcce69f8dee0
  mm: madvise: MADV_DONTNEED_LOCKED

7 months agoaarch64: bits/hwcap.h: add HWCAP2_AFP and HWCAP2_RPRES from linux v5.17
Szabolcs Nagy [Tue, 29 Mar 2022 20:50:12 +0000 (20:50 +0000)]
aarch64: bits/hwcap.h: add HWCAP2_AFP and HWCAP2_RPRES from linux v5.17

see

  linux commit 5c13f042e73200b50573ace63e1a6b94e2917616
  arm64: cpufeature: add HWCAP for FEAT_AFP

  linux commit 1175011a7d0030d49dc9c10bde36f08f26d0a8ee
  arm64: cpufeature: add HWCAP for FEAT_RPRES

7 months agosys/ioctl.h: add N_MCTP from linux v5.17
Szabolcs Nagy [Tue, 29 Mar 2022 20:47:19 +0000 (20:47 +0000)]
sys/ioctl.h: add N_MCTP from linux v5.17

see

  linux commit a0c2ccd9b5ad0a9e838158404e041b5a8ff762dd
  mctp: Add MCTP-over-serial transport binding

7 months agosys/prctl.h: add PR_SET_VMA_ANON_NAME from linux v5.17
Szabolcs Nagy [Tue, 29 Mar 2022 20:37:15 +0000 (20:37 +0000)]
sys/prctl.h: add PR_SET_VMA_ANON_NAME from linux v5.17

allows setting a name for anonymous VMAs that is displayed in
/proc/pid/maps and /proc/pid/smaps, see

  linux commit 9a10064f5625d5572c3626c1516e0bebc6c9fe9b
  mm: add a field to store names for private anonymous memory

7 months agobits/syscall.h: add set_mempolicy_home_node from linux v5.17
Szabolcs Nagy [Tue, 29 Mar 2022 20:30:46 +0000 (20:30 +0000)]
bits/syscall.h: add set_mempolicy_home_node from linux v5.17

syscall for numa systems, see

  linux commit c6018b4b254971863bd0ad36bb5e7d0fa0f0ddb0
  mm/mempolicy: add set_mempolicy_home_node syscall

  linux commit 21b084fdf2a49ca1634e8e360e9ab6f9ff0dee11
  mm/mempolicy: wire up syscall set_mempolicy_home_node

7 months agoaarch64: bits/hwcap.h: add HWCAP2_ECV from linux v5.16
Szabolcs Nagy [Tue, 29 Mar 2022 20:09:28 +0000 (20:09 +0000)]
aarch64: bits/hwcap.h: add HWCAP2_ECV from linux v5.16

see

  linux commit fee29f008aa3f2aff01117f28b57b1145d92cb9b
  arm64: Add HWCAP for self-synchronising virtual counter

7 months agosys/prctl.h: add PR_SCHED_CORE_SCOPE_* from linux v5.16
Szabolcs Nagy [Tue, 29 Mar 2022 20:04:28 +0000 (20:04 +0000)]
sys/prctl.h: add PR_SCHED_CORE_SCOPE_* from linux v5.16

macros for core-scheduling api, see

  linux commit 61bc346ce64a3864ac55f5d18bdc1572cda4fb18
  uapi/linux/prctl: provide macro definitions for the PR_SCHED_CORE type argument

7 months agosys/socket.h: add SO_RESERVE_MEM from linux v5.16
Szabolcs Nagy [Tue, 29 Mar 2022 19:42:28 +0000 (19:42 +0000)]
sys/socket.h: add SO_RESERVE_MEM from linux v5.16

to reserve memory for the socket, see

  linux commit 2bb2f5fb21b0486ff69b7b4a1fe03a760527d133
  net: add new socket option SO_RESERVE_MEM

7 months agonetinet/if_ether.h: add ETH_P_REALTEK from linux v5.16
Szabolcs Nagy [Tue, 29 Mar 2022 19:56:56 +0000 (19:56 +0000)]
netinet/if_ether.h: add ETH_P_REALTEK from linux v5.16

see

  linux commit 7bbbbfaa7a1b0b03890f25fba5f28bb8c7ef145a
  ether: add EtherType for proprietary Realtek protocols

7 months agobits/syscall.h: add futex_waitv syscall number from linux v5.16
Szabolcs Nagy [Tue, 29 Mar 2022 19:51:57 +0000 (19:51 +0000)]
bits/syscall.h: add futex_waitv syscall number from linux v5.16

to wait on multiple futexes, see

  linux commit bf69bad38cf63d980e8a603f8d1bd1f85b5ed3d9
  futex: Implement sys_futex_waitv()

7 months agosys/prctl.h: add PR_SPEC_L1D_FLUSH from linux v5.15
Szabolcs Nagy [Sun, 19 Dec 2021 20:55:06 +0000 (20:55 +0000)]
sys/prctl.h: add PR_SPEC_L1D_FLUSH from linux v5.15

New argument for PR_{GET,SET}_SPECULATION_CTRL prctl command, see

  linux commit e893bb1bb4d2eb635eba61e5d9c5135d96855773
  x86, prctl: Hook L1D flushing in via prctl

7 months agosys/socket.h: add SO_BUF_LOCK from linux v5.15
Szabolcs Nagy [Fri, 17 Dec 2021 22:15:51 +0000 (22:15 +0000)]
sys/socket.h: add SO_BUF_LOCK from linux v5.15

sockopt for enabling automatic socket buffer adjustment, needed for
CRIU to restore socket state and avoid network performance loss.

SOCK_ is not reserved for sys/socket.h but we seem to rely on it.

see

  linux commit 04190bf8944deb7e3ac165a1a494db23aa0160a9
  sock: allow reading and changing sk_userlocks with setsockopt

7 months agosys/socket.h: add {AF,PF}_MCTP from linux v5.15
Szabolcs Nagy [Fri, 17 Dec 2021 22:10:13 +0000 (22:10 +0000)]
sys/socket.h: add {AF,PF}_MCTP from linux v5.15

see

  linux commit bc49d8169aa72295104f1558830c568efb946315
  mctp: Add MCTP base

7 months agonetinet/if_ether.h: add ETH_P_MCTP from linux v5.15
Szabolcs Nagy [Fri, 17 Dec 2021 22:03:11 +0000 (22:03 +0000)]
netinet/if_ether.h: add ETH_P_MCTP from linux v5.15

see

  linux commit 583be982d93479ea3d85091b0fd0b01201ede87d
  mctp: Add device handling and netlink interface

7 months agonet/if_arp.h: add ARPHRD_MCTP from linux v5.15
Szabolcs Nagy [Fri, 17 Dec 2021 21:57:21 +0000 (21:57 +0000)]
net/if_arp.h: add ARPHRD_MCTP from linux v5.15

see

  linux commit 4b2e69305cbbc7c32ecbd946110b505c4ff6071a
  mctp: Add initial driver infrastructure

7 months agobits/syscall.h: add __NR_process_mrelease from linux v5.15
Szabolcs Nagy [Fri, 17 Dec 2021 21:49:19 +0000 (21:49 +0000)]
bits/syscall.h: add __NR_process_mrelease from linux v5.15

see

  linux commit dce49103962840dd61423d7627748d6c558d58c5
  mm: wire up syscall process_mrelease

  linux commit 884a7e5964e06ed93c7771c0d7cf19c09a8946f1
  mm: introduce process_mrelease system call

7 months agobits/syscall.h: add __NR_memfd_secret from linux v5.14
Szabolcs Nagy [Tue, 21 Sep 2021 20:14:04 +0000 (20:14 +0000)]
bits/syscall.h: add __NR_memfd_secret from linux v5.14

see

  linux commit 7bb7f2ac24a028b20fca466b9633847b289b156a
  arch, mm: wire up memfd_secret system call where relevant

  linux commit 1507f51255c9ff07d75909a84e7c0d7f3c4b2f49
  mm: introduce memfd_secret system call to create "secret" memory areas

in linux the syscall is only wired up on aarch64, riscv64 and x86
targets.

7 months agobits/syscall.h: add __NR_quotactl_fd from linux v5.14
Szabolcs Nagy [Tue, 21 Sep 2021 20:06:24 +0000 (20:06 +0000)]
bits/syscall.h: add __NR_quotactl_fd from linux v5.14

see

  linux commit 9dfa23c8de925041b7b45637a1a80a98a22f19dd
  quota: Add mountpath based quota support

  linux commit fa8b90070a80bb1a3042b4b25af4b3ee2c4c27e1
  quota: wire up quotactl_path

  linux commit 64c2c2c62f92339b176ea24403d8db16db36f9e6
  quota: Change quotactl_path() systcall to an fd-based one

7 months agosys/prctl.h: add PR_SCHED_CORE from linux v5.14
Szabolcs Nagy [Tue, 21 Sep 2021 19:52:02 +0000 (19:52 +0000)]
sys/prctl.h: add PR_SCHED_CORE from linux v5.14

see

  linux commit 7ac592aa35a684ff1858fb9ec282886b9e3575ac
  sched: prctl() core-scheduling interface

7 months agosys/socket.h: add SO_NETNS_COOKIE from linux v5.14
Szabolcs Nagy [Tue, 21 Sep 2021 19:05:09 +0000 (19:05 +0000)]
sys/socket.h: add SO_NETNS_COOKIE from linux v5.14

see

  linux commit e8b9eab99232c4e62ada9d7976c80fd5e8118289
  net: retrieve netns cookie via getsocketopt

7 months agosys/mman.h: add MADV_POPULATE_* from linux v5.14
Szabolcs Nagy [Tue, 21 Sep 2021 19:01:22 +0000 (19:01 +0000)]
sys/mman.h: add MADV_POPULATE_* from linux v5.14

see

  linux commit 4ca9b3859dac14bbef0c27d00667bb5b10917adb
  mm/madvise: introduce MADV_POPULATE_(READ|WRITE) to prefault page tables

9 months agoglob: fix wrong return code when aborting before any matches
Rich Felker [Thu, 24 Aug 2023 16:54:51 +0000 (12:54 -0400)]
glob: fix wrong return code when aborting before any matches

when the result count was zero, glob was ignoring a possible
GLOB_ABORTED error code and returning GLOB_NOMATCH. whether this
happened could be nondeterministic and dependent on the order of
dirent enumeration, in cases where multiple matches were present and
only some produced errors.

caught by Tor's test_util_glob.

9 months agostatvfs: allocate spare for f_type
наб [Thu, 17 Aug 2023 20:05:14 +0000 (22:05 +0200)]
statvfs: allocate spare for f_type

This is the only missing part in struct statvfs. The LSB calls
[f]statfs() deprecated, and its weird types are definitely
off-putting. However, its use is required to get f_type.

Instead, allocate one of the six spares to f_type, copied directly
from struct statfs. This then becomes a small extension to the
standard interface on Linux, instead of two different interfaces, one
of which is quite odd due to being an ABI type, and there no longer is
any reason to use statfs().

The underlying kernel type is a mess, but all architectures agree on u32
(or more) for the ABI, and all filesystem magicks are 32-bit integers.

Since commit 6567db65f495cf7c11f5c1e60a3e54543d5a69bc (prior to
1.0.0), the spare slots have been zero-filled, so on all versions that
may be reasonably be encountered in the wild, applications can rely on
a nonzero f_type as indication that the new field has been filled in.

9 months agomath: fix ld80 powl(x,huge) and powl(LDBL_MAX,small)
Szabolcs Nagy [Fri, 18 Aug 2023 21:17:38 +0000 (23:17 +0200)]
math: fix ld80 powl(x,huge) and powl(LDBL_MAX,small)

powl used >= LDBL_MAX as infinity check, but LDBL_MAX is finite, so
this can cause wrong results e.g. powl(LDBL_MAX, 0.5) returned inf
or powl(2, LDBL_MAX) returned inf without raising overflow.

huge y values (close to LDBL_MAX) could cause intermediate results to
overflow (computing y * log2(x) with more than long double precision)
and e.g. powl(0.5, 0x1p16380L) or powl(10, 0x1p16380L) returned nan.
this is fixed by handling huge y early since that always overflows or
underflows.

reported by Paul Zimmermann against expl10 (which uses powl).

9 months agomath: fix ld80 acoshl(x) for x < 0
Szabolcs Nagy [Fri, 18 Aug 2023 21:16:00 +0000 (23:16 +0200)]
math: fix ld80 acoshl(x) for x < 0

acosh(x) is nan for x < 1, but x < 0 cases were not handled specially
and acoshl gave wrong result for some -0x1p32 < x < -2 values, e.g.:

acoshl(-0x1p20) returned -inf,
acoshl(-0x1.4p20) returned -0x1.db365758403aa9acp+0L,

fixed by checking the sign bit and handling it specially.

reported by Paul Zimmermann.

10 months agofix rejection of dns responses with pointers past 512 byte offset review
Rich Felker [Mon, 17 Jul 2023 22:03:38 +0000 (18:03 -0400)]
fix rejection of dns responses with pointers past 512 byte offset

the __dns_parse code used by the stub resolver traditionally included
code to reject label pointers to offsets past a 512 byte limit,
despite never processing the label contents, only stepping over them.
when commit 51d4669fb97782f6a66606da852b5afd49a08001 added support for
tcp fallback, this limit was overlooked, and as a result, it was at
least theoretically possible for some valid large answers to be
rejected on account of these offsets.

since the limit was never serving any useful purpose, just remove it.

11 months agodns stub resolver: increase buffer size to handle chained CNAMEs
Rich Felker [Wed, 5 Jul 2023 03:11:17 +0000 (23:11 -0400)]
dns stub resolver: increase buffer size to handle chained CNAMEs

in the event of chained CNAMEs, the answer to a query will contain the
entire CNAME chain, not just one CNAME record. previously, the answer
buffer size had been chosen to admit a maximal-length CNAME, but only
one. a moderate-length chain could fill the available 768 bytes
leaving no room for an actual address answering the query.

while the DNS RFCs do not specify any limit on the length of a CNAME
chain, or any reasonable behavior is the chain exceeds the entire 64k
possible message size, actual recursive servers have to impose a
limit, and a such, for all practical purposes, chains longer than this
limit are not usable. it turns out BIND has a hard-coded limit of 16,
and Unbound has a default limit of 11.

assuming the recursive server makes use of "compression" (pointers),
each maximal-length CNAME record takes at most 268 bytes, and thus any
chain up to length 16 fits in at most 4288 bytes.

this patch increases the answer buffer size to preserve the original
intent of having 512 bytes available for address answers, plus space
needed for a maximal CNAME chain, for a total of 4800 bytes. the
resulting size of 9600 bytes for two queries (A+AAAA) is still well
within what is reasonable to place in automatic storage.

12 months agoprintf core: fix gratuitous integer formatting buffer size
Rich Felker [Tue, 13 Jun 2023 00:04:22 +0000 (20:04 -0400)]
printf core: fix gratuitous integer formatting buffer size

the extra terms 3 and LDBL_MANT_DIG/4 are remnants of a proto-musl
implementation of printf where the sign/prefix and floating point
conversions were performed naively into this buffer. having them there
obscures the actual intended buffer size (sufficient to hold between 2
and 3 octal digits per byte, rounded up to 3 for simplicity) and
interferes with upcoming work to add C2x binary formats which would
otherwise be stuck having to explain a similar fix to buffer size as
part of an unrelated change.

12 months agoall printf variants: fix argument type handling for %c and %lc
Rich Felker [Mon, 12 Jun 2023 23:56:08 +0000 (19:56 -0400)]
all printf variants: fix argument type handling for %c and %lc

%c takes an argument of type int, not char, and %lc/%C takes an
argument of type wint_t (unsigned), not int.

for most cases, this makes no practical difference, but since wide
printf variants convert narrow %c format specifiers via btowc,
interpreting the promoted-to-int unsigned char value passed in as a
(signed, on most archs) char causes 255 to get collapsed to EOF and
interpreted as such by btowc.

this is only relevant in the byte-based C locale, so prior to commit
f22a9edaf8a6f2ca1d314d18b3785558279a5c03, there was no observable
distinction in behavior. for UTF-8, all bytes which might be negative
when interpreted as char are encoding errors when used with %c/btowc.

12 months agofix public clone function to be safe and usable by applications
Rich Felker [Wed, 31 May 2023 16:04:06 +0000 (12:04 -0400)]
fix public clone function to be safe and usable by applications

the clone() function has been effectively unusable since it was added,
due to producing a child process with inconsistent state. in
particular, the child process's thread structure still contains the
tid, thread list pointers, thread count, and robust list for the
parent. this will cause malfunction in interfaces that attempt to use
the tid or thread list, some of which are specified to be
async-signal-safe.

this patch attempts to make clone() consistent in a _Fork-like sense.
as in _Fork, when the parent process is multi-threaded, the child
process inherits an async-signal context where it cannot call
AS-unsafe functions, but its context is now intended to be safe for
calling AS-safe functions. making clone fork-like would also be a
future option, if it turns out that this is what makes sense to
applications, but it's not done at this time because the changes would
be more invasive.

in the case where the CLONE_VM flag is used, clone is only vfork-like,
not _Fork-like. in particular, the child will see itself as having the
parent's tid, and cannot safely call any libc functions but one of the
exec family or _exit.

handling of flags and variadic arguments is also changed so that
arguments are only consumed with flags that indicate their presence,
and so that flags which produce an inconsistent state are disallowed
(reported as EINVAL). in particular, all libc functions carry a
contract that they are only callable with ABI requirements met, which
includes having a valid thread pointer to a thread structure that's
unique within the process, and whose contents are opaque and only able
to be setup internally by the implementation. the only way for an
application to use flags that violate these requirements without
executing any libc code is to perform the syscall from
application-provided asm.

12 months agofix broken thread list unlocking after fork
Rich Felker [Thu, 1 Jun 2023 20:09:32 +0000 (16:09 -0400)]
fix broken thread list unlocking after fork

apparently Linux clears the registered exit futex address on fork.
this means that, if after forking the child process becomes
multithreaded and the original thread exits, the thread list will
never be unlocked, and future attempts to use the thread list will
deadlock.

re-register the exit futex address after _Fork in the child to ensure
that it's preserved.

12 months agombrtowc: Fix wrong return value when n > UINT_MAX
Alexey Izbyshev [Fri, 26 May 2023 16:34:14 +0000 (19:34 +0300)]
mbrtowc: Fix wrong return value when n > UINT_MAX

mbrtowc truncates n to unsigned int when storing its copy.
If n > UINT_MAX and the locale is not POSIX, the function will
return a wrong value greater than UINT_MAX on the success path.

12 months agoconfigure: replace -Os with equivalent based on -O2
Rich Felker [Sun, 21 May 2023 16:16:11 +0000 (12:16 -0400)]
configure: replace -Os with equivalent based on -O2

aside from the documented differences, which are the contents of this
patch, GCC's -Os also has hard-coded unwanted behaviors which are
impossible to override, like refusing to strength-reduce division by a
constant to multiplication, presumably because the div saves a couple
bytes of code. for this reason, getting rid of -Os and switching to an
equivalent default optimization profile based on -O2 has been a
long-term goal.

as follow-ups, it may make sense to evaluate which of these variations
from -O2 actually do anything useful, and eliminate the ones which are
not helpful or which throw away performance for insignificant size
savings. but for now, I've replicated -Os as closely as possible to
provide a baseline for such evaluation.

13 months agomove fallocate64 declaration under _LARGEFILE64_SOURCE feature test
Rich Felker [Tue, 2 May 2023 15:45:28 +0000 (11:45 -0400)]
move fallocate64 declaration under _LARGEFILE64_SOURCE feature test

overlooked in commit 25e6fee27f4a293728dd15b659170e7b9c7db9bc,
probably because the fallocate function itself is nonstandard and
already under _GNU_SOURCE.

13 months agorelease 1.2.4
Rich Felker [Tue, 2 May 2023 03:39:41 +0000 (23:39 -0400)]
release 1.2.4

13 months agofix return value of wmemcmp for extreme wchar_t values
Rich Felker [Mon, 24 Apr 2023 15:21:13 +0000 (11:21 -0400)]
fix return value of wmemcmp for extreme wchar_t values

analogous to the bug in wcscmp and wcsncmp that was fixed in commit
07616721f1fa6cb215ffbef23441cae80412484f.

13 months agofix wide printf numbered argument buffer overflow
Gabriel Ravier [Fri, 14 Apr 2023 14:55:42 +0000 (16:55 +0200)]
fix wide printf numbered argument buffer overflow

The nl_type and nl_arg arrays defined in vfwprintf may be accessed
with an index up to and including NL_ARGMAX, but they are only of size
NL_ARGMAX, meaning they may be written to or read from 1 element too
far.

14 months agowait4: fix missing rusage on x32 due to wrong success condition
Alexey Izbyshev [Mon, 6 Mar 2023 08:59:21 +0000 (11:59 +0300)]
wait4: fix missing rusage on x32 due to wrong success condition

Resource usage data is filled by the kernel only when wait4 returns
a pid, i.e. a positive value.

Commit 5850546e9669f793aab61dfc7c4f2c1ff35c4b29 introduced this bug,
possibly because of copy-pasting from getrusage.

14 months agosemtimedop: fix timespec kernel ABI mismatch for 32-bit timeouts on x32
Alexey Izbyshev [Mon, 6 Mar 2023 17:56:25 +0000 (20:56 +0300)]
semtimedop: fix timespec kernel ABI mismatch for 32-bit timeouts on x32

For time64 support, musl normally defines SYS_foo to the time32 variant
of that syscall on arches that have it, and to the time64 variant
otherwise, so that "SYS_foo == SYS_foo_time64" implies that the arch is
time64-only. However, SYS_semtimedop is an odd case: some arches define
only SYS_semtimedop_time64, yet they are not time64-only, because the
time32 variant is provided via SYS_ipc instead. For such arches,
defining SYS_semtimedop to SYS_semtimedop_time64 would break the
implication above, so commit 4bbd7baea7c8538b3fb8e30f7b022a1eee071450
doesn't do this. Commit eb2e298cdc814493a6ced8c05cf0d0f5cccc8b63
attempts to detect time64-only arches by checking that both
SYS_semtimedop and SYS_ipc are undefined, but this doesn't work for
x32, because it's a time64-only arch that does define SYS_semtimedop.
As a result, 32-bit timeouts trigger the fallback path that passes
a 32-bit timespec to the kernel while it expects a 64-bit one, so
the effective tv_sec is formed by interpreting 32-bit tv_sec and
tv_nsec as a single long long, and the effective tv_nsec is whatever
is located in the next 64 bits of the stack.

Fix this by expanding the time64-only check to include arches where
SYS_semtimedop is the time64 variant of the syscall.

14 months agogetopt: fix null pointer arithmetic ub
Alexey Izbyshev [Fri, 10 Mar 2023 17:00:31 +0000 (20:00 +0300)]
getopt: fix null pointer arithmetic ub

When an option that requires an argument is the last character of
argv[argc-1], getopt computes argv[argc] + optpos. While optpos
is always zero in this case, adding it to null pointer is still
undefined.

14 months agonftw: fix use of uninitialized struct stat
Alexey Izbyshev [Fri, 10 Mar 2023 14:00:50 +0000 (17:00 +0300)]
nftw: fix use of uninitialized struct stat

If lstat/stat fails with EACCES, st is left uninitialized, but its
st_dev/st_ino fields are then used in several places:

* for FTW_MOUNT check (in practice typically results in a false
  positive and an early return)
* for copying to the new struct history (though the struct is not used
  afterwards since we don't recurse in this case)
* for cycle detection check (could theoretically result in a false
  positive and an early return)

To avoid adding FTW_NS checks to all these places, fix this by
zero-initializing st_dev/st_ino (which can never match an existing
dentry due to zero inode being reserved in Linux), and check for FTW_NS
only when handling FTW_MOUNT since we need two valid dentries there.