Blame SOURCES/0232-ccpp-unify-log-message-of-ignored-crashes.patch

a60cd7
From 6724ba03fea310439c02f97d9429b921d12275c5 Mon Sep 17 00:00:00 2001
a60cd7
From: Matej Habrnal <mhabrnal@redhat.com>
a60cd7
Date: Thu, 19 May 2016 12:10:42 +0200
a60cd7
Subject: [PATCH] ccpp: unify log message of ignored crashes
a60cd7
a60cd7
ABRT will ignore crashes in executables for which absolute path matches one of
a60cd7
specified patterns.
a60cd7
a60cd7
Example of log messages in case of ignoring crashes:
a60cd7
- Crash's path is listed in 'IgnoredPath' in CCpp.conf
a60cd7
    Process 16431 (will_segfault) of user 0 killed by SIGSEGV - ignoring
a60cd7
    (listed in 'IgnoredPaths')
a60cd7
a60cd7
- Repeating crash
a60cd7
    Process 16219 (will_segfault) of user 1000 killed by SIGSEGV -
a60cd7
    ignoring (repeated crash)
a60cd7
a60cd7
- abrt-ccpp-hook crash
a60cd7
    Process 16223 (abrt-hook-ccpp) of user 1000 killed by SIGSEGV -
a60cd7
    ignoring (avoid recursion)
a60cd7
a60cd7
- abrt crash
a60cd7
    Process 16228 (abrt_test) of user 1000 killed by SIGSEGV -
a60cd7
    ignoring ('DebugLevel' == 0)
a60cd7
a60cd7
- not supported signal
a60cd7
    Process 16229 (crash) of user 1000 killed by signal 99 - ignoring
a60cd7
    (unsupported signal)
a60cd7
a60cd7
- abrtd is not running
a60cd7
    Process 16229 (crash) of user 1000 killed by signal 99 - ignoring
a60cd7
    (abrtd is not running)
a60cd7
a60cd7
- low free space
a60cd7
    Process 16229 (crash) of user 1000 killed by signal 99 - ignoring
a60cd7
    (low free space)
a60cd7
a60cd7
- failed to parse /proc/$PID/status Uid
a60cd7
    Process 16229 (crash) of user 1000 killed by signal 99 - ignoring
a60cd7
    (Failed to parse /proc/16229/status (Uid))
a60cd7
a60cd7
- failed to parse /proc/$PID/status Gid
a60cd7
    Process 16229 (crash) of user 1000 killed by signal 99 - ignoring
a60cd7
    (Failed to parse /proc/16229/status (Gid))
a60cd7
a60cd7
- failed to get executable
a60cd7
    Process 16229 (crash) of user 1000 killed by signal 99 - ignoring
a60cd7
    (Can't read /proc/16229/exe link)
a60cd7
a60cd7
- core size limit is bogus
a60cd7
    Process 16229 (crash) of user 1000 killed by signal 99 - ignoring
a60cd7
    (RLIMIT_CORE 'foo' is bogus)
a60cd7
a60cd7
I the case the crash is not ignored the log msg is following:
a60cd7
    Process 21768 (will_segfault) of user 1000 killed by SIGSEGV -
a60cd7
    dumping core
a60cd7
a60cd7
Related to: #1337186
a60cd7
a60cd7
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
a60cd7
---
a60cd7
 src/hooks/abrt-hook-ccpp.c | 211 ++++++++++++++++++++++++++++-----------------
a60cd7
 1 file changed, 133 insertions(+), 78 deletions(-)
a60cd7
a60cd7
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
a60cd7
index 2c05c78..dc4dec6 100644
a60cd7
--- a/src/hooks/abrt-hook-ccpp.c
a60cd7
+++ b/src/hooks/abrt-hook-ccpp.c
a60cd7
@@ -695,7 +695,7 @@ static int test_configuration(bool setting_SaveFullCore, bool setting_CreateCore
a60cd7
     return 0;
a60cd7
 }
a60cd7
 
a60cd7
-static void error_msg_not_process_crash(const char *pid_str, const char *process_str,
a60cd7
+static void error_msg_process_crash(const char *pid_str, const char *process_str,
a60cd7
         long unsigned uid, int signal_no, const char *signame, const char *message, ...)
a60cd7
 {
a60cd7
     va_list p;
a60cd7
@@ -706,10 +706,10 @@ static void error_msg_not_process_crash(const char *pid_str, const char *process
a60cd7
     char *process_name = (process_str) ?  xasprintf(" (%s)", process_str) : xstrdup("");
a60cd7
 
a60cd7
     if (signame)
a60cd7
-        error_msg("Process %s (%s) of user %lu killed by SIG%s - %s", pid_str,
a60cd7
+        error_msg("Process %s%s of user %lu killed by SIG%s - %s", pid_str,
a60cd7
                         process_name, uid, signame, message_full);
a60cd7
     else
a60cd7
-        error_msg("Process %s (%s) of user %lu killed by signal %d - %s", pid_str,
a60cd7
+        error_msg("Process %s%s of user %lu killed by signal %d - %s", pid_str,
a60cd7
                         process_name, uid, signal_no, message_full);
a60cd7
 
a60cd7
     free(process_name);
a60cd7
@@ -718,6 +718,20 @@ static void error_msg_not_process_crash(const char *pid_str, const char *process
a60cd7
     return;
a60cd7
 }
a60cd7
 
a60cd7
+static void error_msg_ignore_crash(const char *pid_str, const char *process_str,
a60cd7
+        long unsigned uid, int signal_no, const char *signame, const char *message, ...)
a60cd7
+{
a60cd7
+    va_list p;
a60cd7
+    va_start(p, message);
a60cd7
+    char *message_full = xvasprintf(message, p);
a60cd7
+    va_end(p);
a60cd7
+
a60cd7
+    error_msg_process_crash(pid_str, process_str, uid, signal_no, signame, "ignoring (%s)", message_full);
a60cd7
+
a60cd7
+    free(message_full);
a60cd7
+    return;
a60cd7
+}
a60cd7
+
a60cd7
 int main(int argc, char** argv)
a60cd7
 {
a60cd7
     int err = 1;
a60cd7
@@ -798,24 +812,35 @@ int main(int argc, char** argv)
a60cd7
         }
a60cd7
     }
a60cd7
 
a60cd7
-    errno = 0;
a60cd7
     const char* signal_str = argv[1];
a60cd7
     int signal_no = xatoi_positive(signal_str);
a60cd7
     const char *signame = NULL;
a60cd7
     bool signal_is_fatal_bool = signal_is_fatal(signal_no, &signame);
a60cd7
+
a60cd7
+    const char *pid_str = argv[3];
a60cd7
+    /* xatoi_positive() handles errors */
a60cd7
+    uid_t uid = xatoi_positive(argv[4]);
a60cd7
+
a60cd7
+    errno = 0;
a60cd7
     off_t ulimit_c = strtoull(argv[2], NULL, 10);
a60cd7
+    if (errno)
a60cd7
+    {
a60cd7
+        error_msg_ignore_crash(pid_str, NULL, (long unsigned)uid, signal_no,
a60cd7
+                signame, "RLIMIT_CORE '%s' is bogus", argv[2]);
a60cd7
+        xfunc_die();
a60cd7
+    }
a60cd7
+
a60cd7
     if (ulimit_c < 0) /* unlimited? */
a60cd7
     {
a60cd7
         /* set to max possible >0 value */
a60cd7
         ulimit_c = ~((off_t)1 << (sizeof(off_t)*8-1));
a60cd7
     }
a60cd7
-    const char *pid_str = argv[3];
a60cd7
-    pid_t local_pid = xatoi_positive(argv[3]);
a60cd7
-    uid_t uid = xatoi_positive(argv[4]);
a60cd7
-    if (errno || local_pid <= 0)
a60cd7
-    {
a60cd7
-        perror_msg_and_die("PID '%s' or limit '%s' is bogus", argv[3], argv[2]);
a60cd7
-    }
a60cd7
+
a60cd7
+    const char *global_pid_str = argv[8];
a60cd7
+    pid_t pid = xatoi_positive(argv[8]);
a60cd7
+
a60cd7
+    user_pwd = get_cwd(pid); /* may be NULL on error */
a60cd7
+    log_notice("user_pwd:'%s'", user_pwd);
a60cd7
 
a60cd7
     {
a60cd7
         char *s = xmalloc_fopen_fgetline_fclose(VAR_RUN"/abrt/saved_core_pattern");
a60cd7
@@ -825,8 +850,6 @@ int main(int argc, char** argv)
a60cd7
         else
a60cd7
             free(s);
a60cd7
     }
a60cd7
-    const char *global_pid_str = argv[8];
a60cd7
-    pid_t pid = xatoi_positive(argv[8]);
a60cd7
 
a60cd7
     pid_t tid = 0;
a60cd7
     if (argv[9])
a60cd7
@@ -836,56 +859,24 @@ int main(int argc, char** argv)
a60cd7
 
a60cd7
     char path[PATH_MAX];
a60cd7
 
a60cd7
-    int src_fd_binary = -1;
a60cd7
-    char *executable = get_executable(pid, setting_SaveBinaryImage ? &src_fd_binary : NULL);
a60cd7
-    if (executable == NULL)
a60cd7
-    {
a60cd7
-        error_msg_not_process_crash(pid_str, NULL, (long unsigned)uid, signal_no,
a60cd7
-                signame, "ignoring (can't read /proc/PID/exe link)");
a60cd7
-
a60cd7
-        xfunc_die();
a60cd7
-    }
a60cd7
-
a60cd7
-    if (strstr(executable, "/abrt-hook-ccpp"))
a60cd7
-    {
a60cd7
-        error_msg_and_die("PID %lu is '%s', not dumping it to avoid recursion",
a60cd7
-                        (long)pid, executable);
a60cd7
-    }
a60cd7
-
a60cd7
-    const char *last_slash = strrchr(executable, '/');
a60cd7
-    if (is_path_ignored(setting_ignored_paths, executable))
a60cd7
-    {
a60cd7
-        error_msg_not_process_crash(pid_str, last_slash + 1, (long unsigned)uid, signal_no,
a60cd7
-                signame, "ignoring (listed in 'IgnoredPaths')");
a60cd7
-
a60cd7
-        return 0;
a60cd7
-    }
a60cd7
-
a60cd7
-    /* dumping core for user, if allowed */
a60cd7
-    if (setting_allowed_users || setting_allowed_groups)
a60cd7
-    {
a60cd7
-        if (setting_allowed_users && is_user_allowed(uid, setting_allowed_users))
a60cd7
-            log_debug("User %lu is listed in 'AllowedUsers'", (long unsigned)uid);
a60cd7
-        else if (setting_allowed_groups && is_user_in_allowed_group(uid, setting_allowed_groups))
a60cd7
-            log_debug("User %lu is member of group listed in 'AllowedGroups'", (long unsigned)uid);
a60cd7
-        else
a60cd7
-        {
a60cd7
-            error_msg_not_process_crash(pid_str, last_slash + 1, (long unsigned)uid, signal_no,
a60cd7
-                signame, "ignoring (not allowed in 'AllowedUsers' nor 'AllowedGroups')");
a60cd7
-
a60cd7
-            xfunc_die();
a60cd7
-        }
a60cd7
-    }
a60cd7
-
a60cd7
-    user_pwd = get_cwd(pid);
a60cd7
-    log_notice("user_pwd:'%s'", user_pwd);
a60cd7
-
a60cd7
     sprintf(path, "/proc/%lu/status", (long)pid);
a60cd7
     char *proc_pid_status = xmalloc_xopen_read_close(path, /*maxsz:*/ NULL);
a60cd7
 
a60cd7
     uid_t fsuid = uid;
a60cd7
     uid_t tmp_fsuid = get_fsuid(proc_pid_status);
a60cd7
+    if (tmp_fsuid < 0)
a60cd7
+    {
a60cd7
+        error_msg_ignore_crash(pid_str, NULL, (long unsigned)uid, signal_no,
a60cd7
+                signame, "Failed to parse /proc/%lu/status (Uid)", (long)pid);
a60cd7
+        xfunc_die();
a60cd7
+    }
a60cd7
     const int fsgid = get_fsgid(proc_pid_status);
a60cd7
+    if (fsgid < 0)
a60cd7
+    {
a60cd7
+        error_msg_ignore_crash(pid_str, NULL, (long unsigned)uid, signal_no,
a60cd7
+                signame, "Failed to parse /proc/%lu/status (Gid)", (long)pid);
a60cd7
+        xfunc_die();
a60cd7
+    }
a60cd7
 
a60cd7
     int suid_policy = dump_suid_policy();
a60cd7
     if (tmp_fsuid != uid)
a60cd7
@@ -901,8 +892,7 @@ int main(int argc, char** argv)
a60cd7
         }
a60cd7
     }
a60cd7
 
a60cd7
-    /* If PrivateReports is on, root owns all problem directories */
a60cd7
-    const uid_t dduid = g_settings_privatereports ? 0 : fsuid;
a60cd7
+    snprintf(path, sizeof(path), "%s/last-ccpp", g_settings_dump_location);
a60cd7
 
a60cd7
     /* Open a fd to compat coredump, if requested and is possible */
a60cd7
     int user_core_fd = -1;
a60cd7
@@ -910,18 +900,72 @@ int main(int argc, char** argv)
a60cd7
         /* note: checks "user_pwd == NULL" inside; updates core_basename */
a60cd7
         user_core_fd = open_user_core(uid, fsuid, fsgid, pid, &argv[1]);
a60cd7
 
a60cd7
+    int src_fd_binary = -1;
a60cd7
+    char *executable = get_executable(pid, setting_SaveBinaryImage ? &src_fd_binary : NULL);
a60cd7
     if (executable == NULL)
a60cd7
     {
a60cd7
         /* readlink on /proc/$PID/exe failed, don't create abrt dump dir */
a60cd7
-        error_msg("Can't read /proc/%lu/exe link", (long)pid);
a60cd7
+        error_msg_ignore_crash(pid_str, NULL, (long unsigned)uid, signal_no,
a60cd7
+                signame, "Can't read /proc/%lu/exe link", (long)pid);
a60cd7
+
a60cd7
+        xfunc_die();
a60cd7
+    }
a60cd7
+
a60cd7
+    const char *last_slash = strrchr(executable, '/');
a60cd7
+    /* if the last_slash was found, skip it */
a60cd7
+    if (last_slash) ++last_slash;
a60cd7
+
a60cd7
+    if (is_path_ignored(setting_ignored_paths, executable))
a60cd7
+    {
a60cd7
+        error_msg_ignore_crash(pid_str, last_slash, (long unsigned)uid, signal_no,
a60cd7
+                signame, "listed in 'IgnoredPaths'");
a60cd7
+
a60cd7
+        return 0;
a60cd7
+    }
a60cd7
+
a60cd7
+    if (strstr(executable, "/abrt-hook-ccpp"))
a60cd7
+    {
a60cd7
+        error_msg_ignore_crash(pid_str, last_slash, (long unsigned)uid, signal_no,
a60cd7
+                signame, "avoid recursion");
a60cd7
+
a60cd7
+        xfunc_die();
a60cd7
+    }
a60cd7
+
a60cd7
+    /* Check /var/tmp/abrt/last-ccpp marker, do not dump repeated crashes
a60cd7
+     * if they happen too often. Else, write new marker value.
a60cd7
+     */
a60cd7
+    if (check_recent_crash_file(path, executable))
a60cd7
+    {
a60cd7
+        error_msg_ignore_crash(pid_str, last_slash, (long unsigned)uid, signal_no,
a60cd7
+                signame, "repeated crash");
a60cd7
+
a60cd7
+        /* It is a repeating crash */
a60cd7
         return create_user_core(user_core_fd, pid, ulimit_c);
a60cd7
     }
a60cd7
 
a60cd7
+    const bool abrt_crash = (last_slash && (strncmp(last_slash, "abrt", 4) == 0));
a60cd7
+    if (abrt_crash && g_settings_debug_level == 0)
a60cd7
+    {
a60cd7
+        error_msg_ignore_crash(pid_str, last_slash, (long unsigned)uid, signal_no,
a60cd7
+                signame, "'DebugLevel' == 0");
a60cd7
+
a60cd7
+        goto finito;
a60cd7
+    }
a60cd7
+
a60cd7
+    /* unsupported signal */
a60cd7
     if (!signal_is_fatal_bool)
a60cd7
+    {
a60cd7
+        error_msg_ignore_crash(pid_str, last_slash, (long unsigned)uid, signal_no,
a60cd7
+                signame, "unsupported signal");
a60cd7
+
a60cd7
         return create_user_core(user_core_fd, pid, ulimit_c); // not a signal we care about
a60cd7
+    }
a60cd7
 
a60cd7
     if (!daemon_is_ok())
a60cd7
     {
a60cd7
+        error_msg_ignore_crash(pid_str, last_slash, (long unsigned)uid, signal_no,
a60cd7
+                signame, "abrtd is not running");
a60cd7
+
a60cd7
         /* not an error, exit with exit code 0 */
a60cd7
         log("abrtd is not running. If it crashed, "
a60cd7
             "/proc/sys/kernel/core_pattern contains a stale value, "
a60cd7
@@ -930,32 +974,40 @@ int main(int argc, char** argv)
a60cd7
         return create_user_core(user_core_fd, pid, ulimit_c);
a60cd7
     }
a60cd7
 
a60cd7
+    /* dumping core for user, if allowed */
a60cd7
+    if (setting_allowed_users || setting_allowed_groups)
a60cd7
+    {
a60cd7
+        if (setting_allowed_users && is_user_allowed(uid, setting_allowed_users))
a60cd7
+            log_debug("User %lu is listed in 'AllowedUsers'", (long unsigned)uid);
a60cd7
+        else if (setting_allowed_groups && is_user_in_allowed_group(uid, setting_allowed_groups))
a60cd7
+            log_debug("User %lu is member of group listed in 'AllowedGroups'", (long unsigned)uid);
a60cd7
+        else
a60cd7
+        {
a60cd7
+            error_msg_ignore_crash(pid_str, last_slash, (long unsigned)uid, signal_no,
a60cd7
+                signame, "not allowed in 'AllowedUsers' nor 'AllowedGroups'");
a60cd7
+
a60cd7
+            xfunc_die();
a60cd7
+        }
a60cd7
+    }
a60cd7
+
a60cd7
+    /* low free space */
a60cd7
     if (g_settings_nMaxCrashReportsSize > 0)
a60cd7
     {
a60cd7
         /* If free space is less than 1/4 of MaxCrashReportsSize... */
a60cd7
         if (low_free_space(g_settings_nMaxCrashReportsSize, g_settings_dump_location))
a60cd7
+        {
a60cd7
+            error_msg_ignore_crash(pid_str, last_slash, (long unsigned)uid, signal_no,
a60cd7
+                                    signame, "low free space");
a60cd7
             return create_user_core(user_core_fd, pid, ulimit_c);
a60cd7
+        }
a60cd7
     }
a60cd7
 
a60cd7
-    /* Check /var/tmp/abrt/last-ccpp marker, do not dump repeated crashes
a60cd7
-     * if they happen too often. Else, write new marker value.
a60cd7
-     */
a60cd7
-    snprintf(path, sizeof(path), "%s/last-ccpp", g_settings_dump_location);
a60cd7
-    if (check_recent_crash_file(path, executable))
a60cd7
-    {
a60cd7
-        /* It is a repeating crash */
a60cd7
-        return create_user_core(user_core_fd, pid, ulimit_c);
a60cd7
-    }
a60cd7
+    /* processing crash - inform user about it */
a60cd7
+    error_msg_process_crash(pid_str, last_slash, (long unsigned)uid,
a60cd7
+                signal_no, signame, "dumping core");
a60cd7
 
a60cd7
-    if (last_slash && strncmp(++last_slash, "abrt", 4) == 0)
a60cd7
+    if (abrt_crash)
a60cd7
     {
a60cd7
-        if (g_settings_debug_level == 0)
a60cd7
-        {
a60cd7
-            log_warning("Ignoring crash of %s (SIG%s).",
a60cd7
-                        executable, signame ? signame : signal_str);
a60cd7
-            goto finito;
a60cd7
-        }
a60cd7
-
a60cd7
         /* If abrtd/abrt-foo crashes, we don't want to create a _directory_,
a60cd7
          * since that can make new copy of abrtd to process it,
a60cd7
          * and maybe crash again...
a60cd7
@@ -974,7 +1026,7 @@ int main(int argc, char** argv)
a60cd7
              * but it does not log file name */
a60cd7
             error_msg_and_die("Error saving '%s'", path);
a60cd7
         }
a60cd7
-        log("Saved core dump of pid %lu (%s) to %s (%llu bytes)", (long)pid, executable, path, (long long)core_size);
a60cd7
+        log_notice("Saved core dump of pid %lu (%s) to %s (%llu bytes)", (long)pid, executable, path, (long long)core_size);
a60cd7
         err = 0;
a60cd7
         goto finito;
a60cd7
     }
a60cd7
@@ -986,6 +1038,9 @@ int main(int argc, char** argv)
a60cd7
         return create_user_core(user_core_fd, pid, ulimit_c);
a60cd7
     }
a60cd7
 
a60cd7
+    /* If PrivateReports is on, root owns all problem directories */
a60cd7
+    const uid_t dduid = g_settings_privatereports ? 0 : fsuid;
a60cd7
+
a60cd7
     /* use dduid (either fsuid or 0) instead of uid, so we don't expose any
a60cd7
      * sensitive information of suided app in /var/tmp/abrt
a60cd7
      *
a60cd7
-- 
a60cd7
1.8.3.1
a60cd7