]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix underallocation of abort_msg_s struct (CVE-2025-0395)
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Tue, 21 Jan 2025 21:11:06 +0000 (16:11 -0500)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 22 Jan 2025 16:08:33 +0000 (17:08 +0100)
Include the space needed to store the length of the message itself, in
addition to the message string.  This resolves BZ #32582.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
(cherry picked from commit 68ee0f704cb81e9ad0a78c644a83e1e9cd2ee578)

NEWS
assert/assert.c
sysdeps/posix/libc_fatal.c

diff --git a/NEWS b/NEWS
index 9d7190763ae5ec139708f7513808852d26b69b12..7db914394b072b1e7dc722d0b14483635727d404 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,10 @@ The following CVEs were fixed in this release:
     nscd: netgroup cache assumes NSS callback uses in-buffer strings
     (CVE-2024-33602)
 
+  GLIBC-SA-2025-0001:
+    assert: Buffer overflow when printing assertion failure message
+    (CVE-2025-0395)
+
 The following bugs are resolved with this release:
 
   [19622] network: Support aliasing with struct sockaddr
@@ -94,6 +98,7 @@ The following bugs are resolved with this release:
   [32137] libio: Attempt wide backup free only for non-legacy code
   [32231] elf: Change ldconfig auxcache magic number
   [32470] x86: Avoid integer truncation with large cache sizes
+  [32582] Fix underallocation of abort_msg_s struct (CVE-2025-0395)
 \f
 Version 2.39
 
index c29629f5f68921a01d5259d733e2f03167ca5553..b6e37d694cf4b779eceb829c9354143d686dd269 100644 (file)
@@ -18,6 +18,7 @@
 #include <assert.h>
 #include <atomic.h>
 #include <ldsodefs.h>
+#include <libc-pointer-arith.h>
 #include <libintl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -65,7 +66,8 @@ __assert_fail_base (const char *fmt, const char *assertion, const char *file,
       (void) __fxprintf (NULL, "%s", str);
       (void) fflush (stderr);
 
-      total = (total + 1 + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
+      total = ALIGN_UP (total + sizeof (struct abort_msg_s) + 1,
+                       GLRO(dl_pagesize));
       struct abort_msg_s *buf = __mmap (NULL, total, PROT_READ | PROT_WRITE,
                                        MAP_ANON | MAP_PRIVATE, -1, 0);
       if (__glibc_likely (buf != MAP_FAILED))
index f9e3425e04496a26117a9ae4a8936d5adfc37544..089c47b04b8af049413531731e8b6329c0020a93 100644 (file)
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <ldsodefs.h>
+#include <libc-pointer-arith.h>
 #include <paths.h>
 #include <stdarg.h>
 #include <stdbool.h>
@@ -105,7 +106,8 @@ __libc_message_impl (const char *fmt, ...)
     {
       WRITEV_FOR_FATAL (fd, iov, iovcnt, total);
 
-      total = (total + 1 + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
+      total = ALIGN_UP (total + sizeof (struct abort_msg_s) + 1,
+                       GLRO(dl_pagesize));
       struct abort_msg_s *buf = __mmap (NULL, total,
                                        PROT_READ | PROT_WRITE,
                                        MAP_ANON | MAP_PRIVATE, -1, 0);