|
|
6ca6e8 |
commit cca9684f2d7a74fc0b28bfb1859955e0e28d7b4b
|
|
|
6ca6e8 |
Author: Florian Weimer <fweimer@redhat.com>
|
|
|
6ca6e8 |
Date: Wed Aug 3 11:41:53 2022 +0200
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
stdio: Clean up __libc_message after unconditional abort
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
Since commit ec2c1fcefb200c6cb7e09553f3c6af8815013d83 ("malloc:
|
|
|
6ca6e8 |
Abort on heap corruption, without a backtrace [BZ #21754]"),
|
|
|
6ca6e8 |
__libc_message always terminates the process. Since commit
|
|
|
6ca6e8 |
a289ea09ea843ced6e5277c2f2e63c357bc7f9a3 ("Do not print backtraces
|
|
|
6ca6e8 |
on fatal glibc errors"), the backtrace facility has been removed.
|
|
|
6ca6e8 |
Therefore, remove enum __libc_message_action and the action
|
|
|
6ca6e8 |
argument of __libc_message, and mark __libc_message as _No_return.
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
diff --git a/debug/fortify_fail.c b/debug/fortify_fail.c
|
|
|
6ca6e8 |
index 9fa07af4867c2bd1..1b490d9da78b8d0d 100644
|
|
|
6ca6e8 |
--- a/debug/fortify_fail.c
|
|
|
6ca6e8 |
+++ b/debug/fortify_fail.c
|
|
|
6ca6e8 |
@@ -21,8 +21,6 @@ void
|
|
|
6ca6e8 |
__attribute__ ((noreturn))
|
|
|
6ca6e8 |
__fortify_fail (const char *msg)
|
|
|
6ca6e8 |
{
|
|
|
6ca6e8 |
- /* The loop is added only to keep gcc happy. */
|
|
|
6ca6e8 |
- while (1)
|
|
|
6ca6e8 |
- __libc_message (do_abort, "*** %s ***: terminated\n", msg);
|
|
|
6ca6e8 |
+ __libc_message ("*** %s ***: terminated\n", msg);
|
|
|
6ca6e8 |
}
|
|
|
6ca6e8 |
libc_hidden_def (__fortify_fail)
|
|
|
6ca6e8 |
diff --git a/include/stdio.h b/include/stdio.h
|
|
|
6ca6e8 |
index 23b7fd288cdaba66..3d4544575318a934 100644
|
|
|
6ca6e8 |
--- a/include/stdio.h
|
|
|
6ca6e8 |
+++ b/include/stdio.h
|
|
|
6ca6e8 |
@@ -143,18 +143,11 @@ extern int __gen_tempname (char *__tmpl, int __suffixlen, int __flags,
|
|
|
6ca6e8 |
# define __GT_DIR 1 /* create a directory */
|
|
|
6ca6e8 |
# define __GT_NOCREATE 2 /* just find a name not currently in use */
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
-enum __libc_message_action
|
|
|
6ca6e8 |
-{
|
|
|
6ca6e8 |
- do_message = 0, /* Print message. */
|
|
|
6ca6e8 |
- do_abort = 1 << 0, /* Abort. */
|
|
|
6ca6e8 |
-};
|
|
|
6ca6e8 |
-
|
|
|
6ca6e8 |
/* Print out MESSAGE (which should end with a newline) on the error output
|
|
|
6ca6e8 |
and abort. */
|
|
|
6ca6e8 |
extern void __libc_fatal (const char *__message)
|
|
|
6ca6e8 |
__attribute__ ((__noreturn__));
|
|
|
6ca6e8 |
-extern void __libc_message (enum __libc_message_action action,
|
|
|
6ca6e8 |
- const char *__fnt, ...) attribute_hidden;
|
|
|
6ca6e8 |
+_Noreturn void __libc_message (const char *__fnt, ...) attribute_hidden;
|
|
|
6ca6e8 |
extern void __fortify_fail (const char *msg) __attribute__ ((__noreturn__));
|
|
|
6ca6e8 |
libc_hidden_proto (__fortify_fail)
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
diff --git a/malloc/malloc.c b/malloc/malloc.c
|
|
|
6ca6e8 |
index d31e985ecce968fe..918e7936f1983437 100644
|
|
|
6ca6e8 |
--- a/malloc/malloc.c
|
|
|
6ca6e8 |
+++ b/malloc/malloc.c
|
|
|
6ca6e8 |
@@ -298,8 +298,7 @@ _Noreturn static void
|
|
|
6ca6e8 |
__malloc_assert (const char *assertion, const char *file, unsigned int line,
|
|
|
6ca6e8 |
const char *function)
|
|
|
6ca6e8 |
{
|
|
|
6ca6e8 |
- __libc_message (do_abort, "\
|
|
|
6ca6e8 |
-Fatal glibc error: malloc assertion failure in %s: %s\n",
|
|
|
6ca6e8 |
+ __libc_message ("Fatal glibc error: malloc assertion failure in %s: %s\n",
|
|
|
6ca6e8 |
function, assertion);
|
|
|
6ca6e8 |
__builtin_unreachable ();
|
|
|
6ca6e8 |
}
|
|
|
6ca6e8 |
@@ -5528,7 +5527,7 @@ static void
|
|
|
6ca6e8 |
malloc_printerr (const char *str)
|
|
|
6ca6e8 |
{
|
|
|
6ca6e8 |
#if IS_IN (libc)
|
|
|
6ca6e8 |
- __libc_message (do_abort, "%s\n", str);
|
|
|
6ca6e8 |
+ __libc_message ("%s\n", str);
|
|
|
6ca6e8 |
#else
|
|
|
6ca6e8 |
__libc_fatal (str);
|
|
|
6ca6e8 |
#endif
|
|
|
6ca6e8 |
diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c
|
|
|
6ca6e8 |
index 6d24bee6134856d1..1feacfbeba765035 100644
|
|
|
6ca6e8 |
--- a/sysdeps/posix/libc_fatal.c
|
|
|
6ca6e8 |
+++ b/sysdeps/posix/libc_fatal.c
|
|
|
6ca6e8 |
@@ -54,7 +54,7 @@ struct str_list
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
/* Abort with an error message. */
|
|
|
6ca6e8 |
void
|
|
|
6ca6e8 |
-__libc_message (enum __libc_message_action action, const char *fmt, ...)
|
|
|
6ca6e8 |
+__libc_message (const char *fmt, ...)
|
|
|
6ca6e8 |
{
|
|
|
6ca6e8 |
va_list ap;
|
|
|
6ca6e8 |
int fd = -1;
|
|
|
6ca6e8 |
@@ -123,36 +123,31 @@ __libc_message (enum __libc_message_action action, const char *fmt, ...)
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
WRITEV_FOR_FATAL (fd, iov, nlist, total);
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
- if ((action & do_abort))
|
|
|
6ca6e8 |
+ total = (total + 1 + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
|
|
|
6ca6e8 |
+ struct abort_msg_s *buf = __mmap (NULL, total,
|
|
|
6ca6e8 |
+ PROT_READ | PROT_WRITE,
|
|
|
6ca6e8 |
+ MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
6ca6e8 |
+ if (__glibc_likely (buf != MAP_FAILED))
|
|
|
6ca6e8 |
{
|
|
|
6ca6e8 |
- total = ((total + 1 + GLRO(dl_pagesize) - 1)
|
|
|
6ca6e8 |
- & ~(GLRO(dl_pagesize) - 1));
|
|
|
6ca6e8 |
- struct abort_msg_s *buf = __mmap (NULL, total,
|
|
|
6ca6e8 |
- PROT_READ | PROT_WRITE,
|
|
|
6ca6e8 |
- MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
6ca6e8 |
- if (__glibc_likely (buf != MAP_FAILED))
|
|
|
6ca6e8 |
- {
|
|
|
6ca6e8 |
- buf->size = total;
|
|
|
6ca6e8 |
- char *wp = buf->msg;
|
|
|
6ca6e8 |
- for (int cnt = 0; cnt < nlist; ++cnt)
|
|
|
6ca6e8 |
- wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len);
|
|
|
6ca6e8 |
- *wp = '\0';
|
|
|
6ca6e8 |
-
|
|
|
6ca6e8 |
- /* We have to free the old buffer since the application might
|
|
|
6ca6e8 |
- catch the SIGABRT signal. */
|
|
|
6ca6e8 |
- struct abort_msg_s *old = atomic_exchange_acq (&__abort_msg,
|
|
|
6ca6e8 |
- buf);
|
|
|
6ca6e8 |
- if (old != NULL)
|
|
|
6ca6e8 |
- __munmap (old, old->size);
|
|
|
6ca6e8 |
- }
|
|
|
6ca6e8 |
+ buf->size = total;
|
|
|
6ca6e8 |
+ char *wp = buf->msg;
|
|
|
6ca6e8 |
+ for (int cnt = 0; cnt < nlist; ++cnt)
|
|
|
6ca6e8 |
+ wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len);
|
|
|
6ca6e8 |
+ *wp = '\0';
|
|
|
6ca6e8 |
+
|
|
|
6ca6e8 |
+ /* We have to free the old buffer since the application might
|
|
|
6ca6e8 |
+ catch the SIGABRT signal. */
|
|
|
6ca6e8 |
+ struct abort_msg_s *old = atomic_exchange_acq (&__abort_msg,
|
|
|
6ca6e8 |
+ buf);
|
|
|
6ca6e8 |
+ if (old != NULL)
|
|
|
6ca6e8 |
+ __munmap (old, old->size);
|
|
|
6ca6e8 |
}
|
|
|
6ca6e8 |
}
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
va_end (ap);
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
- if ((action & do_abort))
|
|
|
6ca6e8 |
- /* Kill the application. */
|
|
|
6ca6e8 |
- abort ();
|
|
|
6ca6e8 |
+ /* Kill the application. */
|
|
|
6ca6e8 |
+ abort ();
|
|
|
6ca6e8 |
}
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
|
|
|
6ca6e8 |
@@ -161,6 +156,6 @@ __libc_fatal (const char *message)
|
|
|
6ca6e8 |
{
|
|
|
6ca6e8 |
/* The loop is added only to keep gcc happy. */
|
|
|
6ca6e8 |
while (1)
|
|
|
6ca6e8 |
- __libc_message (do_abort, "%s", message);
|
|
|
6ca6e8 |
+ __libc_message ("%s", message);
|
|
|
6ca6e8 |
}
|
|
|
6ca6e8 |
libc_hidden_def (__libc_fatal)
|