glibc/sysdeps
Siddhesh Poyarekar 23e0e8f5f1 getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999)
No valid path returned by getcwd would fit into 1 byte, so reject the
size early and return NULL with errno set to ERANGE.  This change is
prompted by CVE-2021-3999, which describes a single byte buffer
underflow and overflow when all of the following conditions are met:

- The buffer size (i.e. the second argument of getcwd) is 1 byte
- The current working directory is too long
- '/' is also mounted on the current working directory

Sequence of events:

- In sysdeps/unix/sysv/linux/getcwd.c, the syscall returns ENAMETOOLONG
  because the linux kernel checks for name length before it checks
  buffer size

- The code falls back to the generic getcwd in sysdeps/posix

- In the generic func, the buf[0] is set to '\0' on line 250

- this while loop on line 262 is bypassed:

    while (!(thisdev == rootdev && thisino == rootino))

  since the rootfs (/) is bind mounted onto the directory and the flow
  goes on to line 449, where it puts a '/' in the byte before the
  buffer.

- Finally on line 458, it moves 2 bytes (the underflowed byte and the
  '\0') to the buf[0] and buf[1], resulting in a 1 byte buffer overflow.

- buf is returned on line 469 and errno is not set.

This resolves BZ #28769.

Reviewed-by: Andreas Schwab <schwab@linux-m68k.org>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Signed-off-by: Qualys Security Advisory <qsa@qualys.com>
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2022-01-24 11:00:17 +05:30
..
aarch64 AArch64: Check for SVE in ifuncs [BZ #28744] 2022-01-06 14:36:28 +00:00
alpha Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
arc Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
arm Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
csky Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
generic elf: Fix 64 time_t support for installed statically binaries 2022-01-17 10:57:09 -03:00
gnu Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
hppa Restore ENTRY_POINT definition on hppa, ia64 (bug 28749) 2022-01-07 14:47:31 +01:00
htl htl: Fix build error in annexc 2022-01-17 23:18:27 +00:00
hurd hurd: Fix pthread_kill on exiting/ted thread 2022-01-15 15:11:54 +01:00
i386 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
ia64 Restore ENTRY_POINT definition on hppa, ia64 (bug 28749) 2022-01-07 14:47:31 +01:00
ieee754 math: Fix float conversion regressions with gcc-12 [BZ #28713] 2022-01-10 14:27:17 +00:00
m68k Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
mach htl: Fix cleaning the reply port 2022-01-22 02:17:19 +01:00
microblaze Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
mips mips: Move DT_MIPS into <ldsodefs.h> 2022-01-19 20:11:55 +01:00
nios2 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
nptl Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
or1k or1k: Build Infrastructure 2022-01-05 06:40:06 +09:00
posix getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999) 2022-01-24 11:00:17 +05:30
powerpc powerpc64le: Use <gcc-macros.h> in early HWCAP check 2022-01-14 20:17:40 +01:00
pthread Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
riscv Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
s390 s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-14 20:17:58 +01:00
sh Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
sparc Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
unix getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999) 2022-01-24 11:00:17 +05:30
wordsize-32 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
wordsize-64 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
x86 x86: Black list more Intel CPUs for TSX [BZ #27398] 2022-01-18 14:20:09 -08:00
x86_64 math: Add more inputs to atan2 accuracy tests [BZ #28765] 2022-01-14 06:00:06 -08:00