glibc:siddhesh/realpath-and-getcwd

Last commit made on 2022-01-19
Get this branch:
git clone -b siddhesh/realpath-and-getcwd https://git.launchpad.net/glibc

Branch merges

Branch information

Name:
siddhesh/realpath-and-getcwd
Repository:
lp:glibc

Recent commits

5af2369... by Siddhesh Poyarekar <email address hidden>

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.

Signed-off-by: Qualys Security Advisory <email address hidden>
Signed-off-by: Siddhesh Poyarekar <email address hidden>

c9c20ec... by Siddhesh Poyarekar <email address hidden>

realpath: Set errno to ENAMETOOLONG for result larger than PATH_MAX [BZ #28770]

realpath returns an allocated string when the result exceeds PATH_MAX,
which is unexpected when its second argument is not NULL. This results
in the second argument (resolved) being uninitialized and also results
in a memory leak since the caller expects resolved to be the same as the
returned value.

Return NULL and set errno to ENAMETOOLONG if the result exceeds
PATH_MAX. This fixes [BZ #28770], which is CVE-2021-3998.

Reviewed-by: Adhemerval Zanella <email address hidden>
Signed-off-by: Siddhesh Poyarekar <email address hidden>

cf6b5f9... by Siddhesh Poyarekar <email address hidden>

support: Add helpers to create paths longer than PATH_MAX

Add new helpers support_create_and_chdir_toolong_temp_directory and
support_chdir_toolong_temp_directory to create and descend into
directory trees longer than PATH_MAX.

Signed-off-by: Siddhesh Poyarekar <email address hidden>

c903634... by Florian Weimer

elf: Move _dl_setup_hash to its own file

And compile it with the early CFLAGS. _dl_setup_hash is called
very early for the ld.so link map, so it should be compiled
differently.

Reviewed-by: Stefan Liebler <email address hidden>
Tested-by: Stefan Liebler <email address hidden>

f8b765b... by Samuel thibault

htl: Fix build error in annexc

We were getting

../scripts/evaluate-test.sh posix/annexc $? true false > /usr/src/glibc-upstream/build/posix/annexc.test-result
In file included from ../include/pthread.h:1,
                 from <stdin>:1:
../sysdeps/htl/include/pthread.h:7:62: error: missing binary operator before token "("
    7 | # if defined __USE_EXTERN_INLINES && defined _LIBC && !IS_IN (libsupport)
      | ^

3a5aeba... by Adhemerval Zanella

elf: Reinstate tst-audit17

9926f6e2eeb3 ("elf: Skip tst-auditlogmod-* if the linker doesn't support
--depaudit [BZ #28 151]") dropped the test by mistake.

c242fcc... by Aurelien Jarno <email address hidden>

x86: use default cache size if it cannot be determined [BZ #28784]

In some cases (e.g QEMU, non-Intel/AMD CPU) the cache information can
not be retrieved and the corresponding values are set to 0.

Commit 2d651eb9265d ("x86: Move x86 processor cache info to
cpu_features") changed the behaviour in such case by defining the
__x86_shared_cache_size and __x86_data_cache_size variables to 0 instead
of using the default values. This cause an issue with the i686 SSE2
optimized bzero/routine which assumes that the cache size is at least
128 bytes, and otherwise tries to zero/set the whole address space minus
128 bytes.

Fix that by restoring the original code to only update
__x86_shared_cache_size and __x86_data_cache_size variables if the
corresponding cache sizes are not zero.

Fixes bug 28784
Fixes commit 2d651eb9265d

Reviewed-by: H.J. Lu <email address hidden>

9702a41... by Samuel thibault

rt/tst-mqueue*: Return UNSUPPORTED when mq_open fails with ENOSYS

Rather than returning 0 or a failure.

5f3a7eb... by Adhemerval Zanella

Linux: Add epoll_pwait2 (BZ #27359)

It is similar to epoll_wait, with the difference the timeout has
nanosecond resoluting by using struct timespec instead of int.

Although Linux interface only provides 64 bit time_t support, old
32 bit interface is also provided (so keep in sync with current
practice and to no force opt-in on 64 bit time_t).

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Florian Weimer <email address hidden>

ded3aeb... by "H.J. Lu" <email address hidden>

Properly handle --disable-default-pie [BZ #28780]

When --disable-default-pie is used, all glibc programs and the testsuite
should be built as position dependent executables (non-PIE), regardless
if the build compiler supports PIE or static PIE.

When --disable-default-pie is used, don't build static PIE by default.

This fixes BZ #28780.

Reviewed-by: Siddhesh Poyarekar <email address hidden>