]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Fix UB on _dl_early_allocate
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 18 Apr 2025 12:45:40 +0000 (09:45 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 17:21:20 +0000 (14:21 -0300)
The ubsan triggers on elf/tst-tls-allocation-failure-static-patched:

UBSAN: Undefined behaviour in ../sysdeps/unix/sysv/linux/dl-early_allocate.c:58:16 pointer index expression with base 0x0000555578792000 overflowed  to 0x8000555578792cc0

The function is called with a size larger than PTRDIFF_MAX, and
the addition than overflow.  Fix it by limiting the size up to
PTRDIFF_MAX, like all other malloc functions.

sysdeps/unix/sysv/linux/dl-early_allocate.c

index 257519b78930aa04d0a6de33ab312224084cf577..854645b1029bff25a489c1b1aad672fd71ed9bae 100644 (file)
@@ -39,6 +39,9 @@ _dl_early_allocate (size_t size)
 {
   void *result;
 
+  if (__glibc_unlikely (size > PTRDIFF_MAX))
+    return NULL;
+
   if (__curbrk != NULL)
     /* If the break has been initialized, brk must have run before,
        so just call it once more.  */