If the process is in a bad state, we used to print backtraces in
many cases. This is problematic because doing so could involve
a lot of work, like loading libgcc_s using the dynamic linker,
and this could itself be targeted by exploit writers. For example,
if the crashing process was forked from a long-lived process, the
addresses in the error message could be used to bypass ASLR.
Commit
ed421fca42fd9b4cab7c66e77894b8dd7ca57ed0 ("Avoid backtrace from
__stack_chk_fail [BZ #12189]"), backtraces where no longer printed
because backtrace_and_maps was always called with do_abort == 1.
Rather than fixing this logic error, this change removes the backtrace
functionality from the sources. With the prevalence of external crash
handlers, it does not appear to be particularly useful. The crash
handler may also destroy useful information for debugging.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
+2019-08-19 Florian Weimer <fweimer@redhat.com>
+
+ Do not print backtraces on fatal errors.
+ * debug/fortify_fail.c (__libc_argv): Remove declaration.
+ (__fortify_fail_abort): Remove definition.
+ (__fortify_fail): Call __libc_message directly.
+ * debug/stack_chk_fail.c (__libc_argv): Remove declaration.
+ (__stack_chk_fail): Call __fortify_fail instead of
+ __fortify_fail_abort.
+ * include/stdio.h (__fortify_fail_abort): Remove declaration.
+ * sysdeps/posix/libc_fatal.c (BEFORE_ABORT, before_abort): Remove
+ definitions.
+ (__libc_message): Do not handle do_backtrace. Do not call
+ BEFORE_ABORT.
+ (__libc_fatal): Do not pass do_backtrace to __libc_message.
+ * sysdeps/unix/sysv/linux/libc_fatal.c (BEFORE_ABORT)
+ (before_abort): Remove definitions.
+
2019-08-16 Florian Weimer <fweimer@redhat.com>
nptl: Move pthread_attr_getdetachstate implementation into libc.
<http://www.gnu.org/licenses/>. */
#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-
-
-extern char **__libc_argv attribute_hidden;
-
-void
-__attribute__ ((noreturn))
-__fortify_fail_abort (_Bool need_backtrace, const char *msg)
-{
- /* The loop is added only to keep gcc happy. Don't pass down
- __libc_argv[0] if we aren't doing backtrace since __libc_argv[0]
- may point to the corrupted stack. */
- while (1)
- __libc_message (need_backtrace ? (do_abort | do_backtrace) : do_abort,
- "*** %s ***: %s terminated\n",
- msg,
- (need_backtrace && __libc_argv[0] != NULL
- ? __libc_argv[0] : "<unknown>"));
-}
void
__attribute__ ((noreturn))
__fortify_fail (const char *msg)
{
- __fortify_fail_abort (true, msg);
+ /* The loop is added only to keep gcc happy. */
+ while (1)
+ __libc_message (do_abort, "*** %s ***: terminated\n", msg);
}
-
libc_hidden_def (__fortify_fail)
-libc_hidden_def (__fortify_fail_abort)
<http://www.gnu.org/licenses/>. */
#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-
-
-extern char **__libc_argv attribute_hidden;
void
__attribute__ ((noreturn))
__stack_chk_fail (void)
{
- __fortify_fail_abort (false, "stack smashing detected");
+ __fortify_fail ("stack smashing detected");
}
strong_alias (__stack_chk_fail, __stack_chk_fail_local)
{
do_message = 0, /* Print message. */
do_abort = 1 << 0, /* Abort. */
- do_backtrace = 1 << 1 /* Backtrace. */
};
/* Print out MESSAGE (which should end with a newline) on the error output
extern void __libc_message (enum __libc_message_action action,
const char *__fnt, ...) attribute_hidden;
extern void __fortify_fail (const char *msg) __attribute__ ((__noreturn__));
-extern void __fortify_fail_abort (_Bool, const char *msg)
- __attribute__ ((__noreturn__)) attribute_hidden;
libc_hidden_proto (__fortify_fail)
-libc_hidden_proto (__fortify_fail_abort)
/* Acquire ownership of STREAM. */
extern void __flockfile (FILE *__stream) attribute_hidden;
}
#endif
-#ifndef BEFORE_ABORT
-# define BEFORE_ABORT before_abort
-static void
-before_abort (int do_abort __attribute__ ((unused)),
- bool written __attribute__ ((unused)),
- int fd __attribute__ ((unused)))
-{
-}
-#endif
-
struct str_list
{
const char *str;
FATAL_PREPARE;
#endif
- /* Don't call __libc_secure_getenv if we aren't doing backtrace, which
- may access the corrupted stack. */
- if ((action & do_backtrace))
- {
- /* Open a descriptor for /dev/tty unless the user explicitly
- requests errors on standard error. */
- const char *on_2 = __libc_secure_getenv ("LIBC_FATAL_STDERR_");
- if (on_2 == NULL || *on_2 == '\0')
- fd = __open_nocancel (_PATH_TTY, O_RDWR | O_NOCTTY | O_NDELAY);
- }
-
if (fd == -1)
fd = STDERR_FILENO;
++nlist;
}
- bool written = false;
if (nlist > 0)
{
struct iovec *iov = alloca (nlist * sizeof (struct iovec));
list = list->next;
}
- written = WRITEV_FOR_FATAL (fd, iov, nlist, total);
+ WRITEV_FOR_FATAL (fd, iov, nlist, total);
if ((action & do_abort))
{
va_end (ap);
if ((action & do_abort))
- {
- if ((action & do_backtrace))
- BEFORE_ABORT (do_abort, written, fd);
-
- /* Kill the application. */
- abort ();
- }
+ /* Kill the application. */
+ abort ();
}
{
/* The loop is added only to keep gcc happy. */
while (1)
- __libc_message (do_abort | do_backtrace, "%s", message);
+ __libc_message (do_abort, "%s", message);
}
libc_hidden_def (__libc_fatal)
<http://www.gnu.org/licenses/>. */
#include <errno.h>
-#include <execinfo.h>
-#include <fcntl.h>
-#include <not-cancel.h>
-#include <string.h>
-#include <sys/mman.h>
#include <sys/uio.h>
static bool
}
#define WRITEV_FOR_FATAL writev_for_fatal
-static void
-backtrace_and_maps (int do_abort, bool written, int fd)
-{
- if (do_abort > 1 && written)
- {
- void *addrs[64];
-#define naddrs (sizeof (addrs) / sizeof (addrs[0]))
- int n = __backtrace (addrs, naddrs);
- if (n > 2)
- {
-#define strnsize(str) str, strlen (str)
-#define writestr(str) __write_nocancel (fd, str)
- writestr (strnsize ("======= Backtrace: =========\n"));
- __backtrace_symbols_fd (addrs + 1, n - 1, fd);
-
- writestr (strnsize ("======= Memory map: ========\n"));
- int fd2 = __open_nocancel ("/proc/self/maps", O_RDONLY);
- char buf[1024];
- ssize_t n2;
- while ((n2 = __read_nocancel (fd2, buf, sizeof (buf))) > 0)
- if (__write_nocancel (fd, buf, n2) != n2)
- break;
- __close_nocancel_nostatus (fd2);
- }
- }
-}
-#define BEFORE_ABORT backtrace_and_maps
-
#include <sysdeps/posix/libc_fatal.c>