From 08f9e80b3f2c4f78e643768ebd9697c32363367a Mon Sep 17 00:00:00 2001 From: Chris Morin Date: Wed, 20 Mar 2019 01:34:23 -0700 Subject: [PATCH] journal-file: handle SIGBUS on offlining thread The thread launched in journal_file_set_offline() accesses a memory mapped file, so it needs to handle SIGBUS. Leave SIGBUS unblocked on the offlining thread so that it uses the same handler as the main thread. The result of triggering SIGBUS in a thread where it's blocked is undefined in Linux. The tested implementations were observed to cause the default handler to run, taking down the whole journald process. We can leave SIGBUS unblocked in multiple threads since it's handler is thread-safe. If SIGBUS is sent to the journald process asynchronously (i.e. with kill, sigqueue, or raise), either thread handling it will result in the same behavior: it will install the default handler and reraise the signal, killing the process. Fixes: #12042 --- src/journal/journal-file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index e0f06a21bb..6a2e80e3c8 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -239,6 +239,9 @@ int journal_file_set_offline(JournalFile *f, bool wait) { int k; assert_se(sigfillset(&ss) >= 0); + /* Don't block SIGBUS since the offlining thread accesses a memory mapped file. + * Asynchronous SIGBUS signals can safely be handled by either thread. */ + assert_se(sigdelset(&ss, SIGBUS) >= 0); r = pthread_sigmask(SIG_BLOCK, &ss, &saved_ss); if (r > 0) -- 2.25.1