glibc/sysdeps
Siddhesh Poyarekar bcdde07537 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>
(cherry picked from commit 23e0e8f5f1)
2022-01-24 16:46:06 +01:00
..
aarch64 aarch64: Fix the list of tested IFUNC variants [BZ #26818] 2021-01-25 16:15:54 +00:00
alpha Update alpha libm-test-ulps 2021-01-28 14:05:14 -03:00
arc ARC: nofpu: Regenerate ulps 2021-01-17 16:39:45 -08:00
arm Update arm libm-test-ulps. 2021-01-18 20:22:51 +00:00
csky Update C-SKY libm-test-ulps 2021-01-23 19:00:00 +00:00
generic dlfcn: Failures after dlmopen should not terminate process [BZ #15271] 2021-06-09 17:15:00 +02:00
gnu
hppa Update hppa libm-test-ulps 2021-01-18 14:23:10 +00:00
htl
hurd
i386 configure: Check for static PIE support 2021-01-21 15:54:50 +00:00
ia64 Update ia64 libm-test-ulps 2021-01-28 14:05:15 -03:00
ieee754 math: Add BZ#18980 fix back on dbl-64 cosh 2021-01-11 16:56:33 -03:00
m68k
mach Revert "linux: Move {f}xstat{at} to compat symbols" for static build 2021-01-21 14:11:53 -03:00
microblaze
mips Update MIPS libm-test-ulps. 2021-01-18 21:36:00 +00:00
nios2 Update Nios II libm-test-ulps. 2021-04-01 20:14:50 +00:00
nptl nptl: Remove private futex optimization [BZ #27304] 2021-03-16 10:30:41 +01:00
posix getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999) 2022-01-24 16:46:06 +01:00
powerpc powerpc: Fix unrecognized instruction errors with recent binutils 2022-01-18 23:07:17 +01:00
pthread nptl: Do not set signal mask on second setjmp return [BZ #28607] 2021-11-24 10:01:01 +01:00
riscv RISC-V: Update rv64 ULPs 2021-09-01 23:52:37 +02:00
s390 s390: Use long branches across object boundaries (jgh instead of jh) 2021-11-10 15:22:51 +01:00
sh sh: Update libm-tests-ulps 2021-01-28 14:05:14 -03:00
sparc Update sparc libm-test-ulps 2021-01-28 14:05:14 -03:00
unix getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999) 2022-01-24 16:46:06 +01:00
wordsize-32
wordsize-64
x86 x86: use default cache size if it cannot be determined [BZ #28784] 2022-01-17 19:49:44 +01:00
x86_64 x86_64: Remove unneeded static PIE check for undefined weak diagnostic 2021-07-08 21:37:32 -07:00