commit 68ee0f704cb81e9ad0a78c644a83e1e9cd2ee578 Author: Siddhesh Poyarekar Date: Tue Jan 21 16:11:06 2025 -0500 Fix underallocation of abort_msg_s struct (CVE-2025-0395) 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 Reviewed: Adhemerval Zanella diff --git a/assert/assert.c b/assert/assert.c index 989126c7e5b6b265..d14bb76b1fb43f57 100644 --- a/assert/assert.c +++ b/assert/assert.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,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)) diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index 1feacfbeba765035..7929f1601d4a89c9 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -123,7 +124,8 @@ __libc_message (const char *fmt, ...) WRITEV_FOR_FATAL (fd, iov, nlist, 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);