arrfab / rpms / abrt

Forked from rpms/abrt 5 years ago
Clone

Blame SOURCES/0100-make-the-dump-directories-owned-by-root-by-default.patch

8ec399
From 8939398b82006ba1fec4ed491339fc075f43fc7c Mon Sep 17 00:00:00 2001
8ec399
From: Jakub Filak <jfilak@redhat.com>
8ec399
Date: Mon, 20 Apr 2015 07:56:34 +0200
8ec399
Subject: [ABRT PATCH] make the dump directories owned by root by default
8ec399
8ec399
It was discovered that the abrt event scripts create a user-readable
8ec399
copy of a sosreport file in abrt problem directories, and include
8ec399
excerpts of /var/log/messages selected by the user-controlled process
8ec399
name, leading to an information disclosure.
8ec399
8ec399
This issue was discovered by Florian Weimer of Red Hat Product Security.
8ec399
8ec399
Related: #1212868
8ec399
8ec399
Signed-off-by: Jakub Filak <jfilak@redhat.com>
8ec399
---
8ec399
 src/daemon/abrt-server.c     | 34 ++++++++++++++++++++++++++++++++--
8ec399
 src/daemon/abrt.conf         |  5 +++++
8ec399
 src/hooks/abrt-hook-ccpp.c   | 10 +++++++---
8ec399
 src/include/libabrt.h        |  2 ++
8ec399
 src/lib/abrt_conf.c          |  8 ++++++++
8ec399
 src/lib/hooklib.c            |  7 ++++++-
8ec399
 src/plugins/abrt-dump-oops.c |  8 ++++++++
8ec399
 src/plugins/abrt-dump-xorg.c |  8 ++++++++
8ec399
 8 files changed, 76 insertions(+), 6 deletions(-)
8ec399
8ec399
diff --git a/src/daemon/abrt-server.c b/src/daemon/abrt-server.c
8ec399
index 307b41b..5789075 100644
8ec399
--- a/src/daemon/abrt-server.c
8ec399
+++ b/src/daemon/abrt-server.c
8ec399
@@ -15,6 +15,7 @@
8ec399
   with this program; if not, write to the Free Software Foundation, Inc.,
8ec399
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
8ec399
 */
8ec399
+#include "problem_api.h"
8ec399
 #include "libabrt.h"
8ec399
 
8ec399
 /* Maximal length of backtrace. */
8ec399
@@ -153,7 +154,36 @@ static int run_post_create(const char *dirname)
8ec399
         error_msg("Bad problem directory name '%s', should start with: '%s'", dirname, g_settings_dump_location);
8ec399
         return 400; /* Bad Request */
8ec399
     }
8ec399
-    if (!dump_dir_accessible_by_uid(dirname, client_uid))
8ec399
+    if (g_settings_privatereports)
8ec399
+    {
8ec399
+        struct stat statbuf;
8ec399
+        if (lstat(dirname, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))
8ec399
+        {
8ec399
+            error_msg("Path '%s' isn't directory", dirname);
8ec399
+            return 404; /* Not Found */
8ec399
+        }
8ec399
+        /* Get ABRT's group gid */
8ec399
+        struct group *gr = getgrnam("abrt");
8ec399
+        if (!gr)
8ec399
+        {
8ec399
+            error_msg("Group 'abrt' does not exist");
8ec399
+            return 500;
8ec399
+        }
8ec399
+        if (statbuf.st_uid != 0 || !(statbuf.st_gid == 0 || statbuf.st_gid == gr->gr_gid) || statbuf.st_mode & 07)
8ec399
+        {
8ec399
+            error_msg("Problem directory '%s' isn't owned by root:abrt or others are not restricted from access", dirname);
8ec399
+            return 403;
8ec399
+        }
8ec399
+        struct dump_dir *dd = dd_opendir(dirname, DD_OPEN_READONLY);
8ec399
+        const bool complete = dd && problem_dump_dir_is_complete(dd);
8ec399
+        dd_close(dd);
8ec399
+        if (complete)
8ec399
+        {
8ec399
+            error_msg("Problem directory '%s' has already been processed", dirname);
8ec399
+            return 403;
8ec399
+        }
8ec399
+    }
8ec399
+    else if (!dump_dir_accessible_by_uid(dirname, client_uid))
8ec399
     {
8ec399
         if (errno == ENOTDIR)
8ec399
         {
8ec399
@@ -377,7 +407,7 @@ static int create_problem_dir(GHashTable *problem_info, unsigned pid)
8ec399
     /* No need to check the path length, as all variables used are limited,
8ec399
      * and dd_create() fails if the path is too long.
8ec399
      */
8ec399
-    struct dump_dir *dd = dd_create(path, client_uid, DEFAULT_DUMP_DIR_MODE);
8ec399
+    struct dump_dir *dd = dd_create(path, g_settings_privatereports ? 0 : client_uid, DEFAULT_DUMP_DIR_MODE);
8ec399
     if (!dd)
8ec399
     {
8ec399
         error_msg_and_die("Error creating problem directory '%s'", path);
8ec399
diff --git a/src/daemon/abrt.conf b/src/daemon/abrt.conf
8ec399
index 59d1831..6c0d6b0 100644
8ec399
--- a/src/daemon/abrt.conf
8ec399
+++ b/src/daemon/abrt.conf
8ec399
@@ -43,3 +43,8 @@ AutoreportingEnabled = no
8ec399
 #                session; otherwise No.
8ec399
 #
8ec399
 # ShortenedReporting = yes
8ec399
+
8ec399
+# Disable this if you want to regular users to own the problem data colleted by
8ec399
+# abrt.
8ec399
+#
8ec399
+PrivateReports = yes
8ec399
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
8ec399
index 00ae621..3a6d002 100644
8ec399
--- a/src/hooks/abrt-hook-ccpp.c
8ec399
+++ b/src/hooks/abrt-hook-ccpp.c
8ec399
@@ -682,6 +682,9 @@ int main(int argc, char** argv)
8ec399
         }
8ec399
     }
8ec399
 
8ec399
+    /* If PrivateReports is on, root owns all problem directories */
8ec399
+    const uid_t dduid = g_settings_privatereports ? 0 : fsuid;
8ec399
+
8ec399
     /* Open a fd to compat coredump, if requested and is possible */
8ec399
     if (setting_MakeCompatCore && ulimit_c != 0)
8ec399
         /* note: checks "user_pwd == NULL" inside; updates core_basename */
8ec399
@@ -773,18 +776,19 @@ int main(int argc, char** argv)
8ec399
         goto create_user_core;
8ec399
     }
8ec399
 
8ec399
-    /* use fsuid instead of uid, so we don't expose any sensitive
8ec399
-     * information of suided app in /var/tmp/abrt
8ec399
+    /* use dduid (either fsuid or 0) instead of uid, so we don't expose any
8ec399
+     * sensitive information of suided app in /var/tmp/abrt
8ec399
      *
8ec399
      * dd_create_skeleton() creates a new directory and leaves ownership to
8ec399
      * the current user, hence, we have to call dd_reset_ownership() after the
8ec399
      * directory is populated.
8ec399
      */
8ec399
-    dd = dd_create_skeleton(path, fsuid, DEFAULT_DUMP_DIR_MODE, /*no flags*/0);
8ec399
+    dd = dd_create_skeleton(path, dduid, DEFAULT_DUMP_DIR_MODE, /*no flags*/0);
8ec399
     if (dd)
8ec399
     {
8ec399
         char *rootdir = get_rootdir(pid);
8ec399
 
8ec399
+        /* This function uses fsuid only for its value. The function stores fsuid in a file name 'uid'*/
8ec399
         dd_create_basic_files(dd, fsuid, NULL);
8ec399
 
8ec399
         char source_filename[sizeof("/proc/%lu/somewhat_long_name") + sizeof(long)*3];
8ec399
diff --git a/src/include/libabrt.h b/src/include/libabrt.h
8ec399
index 85a5a5c..0320c5b 100644
8ec399
--- a/src/include/libabrt.h
8ec399
+++ b/src/include/libabrt.h
8ec399
@@ -62,6 +62,8 @@ extern bool          g_settings_autoreporting;
8ec399
 extern char *        g_settings_autoreporting_event;
8ec399
 #define g_settings_shortenedreporting abrt_g_settings_shortenedreporting
8ec399
 extern bool          g_settings_shortenedreporting;
8ec399
+#define g_settings_privatereports abrt_g_settings_privatereports
8ec399
+extern bool          g_settings_privatereports;
8ec399
 
8ec399
 
8ec399
 #define load_abrt_conf abrt_load_abrt_conf
8ec399
diff --git a/src/lib/abrt_conf.c b/src/lib/abrt_conf.c
8ec399
index 5eb69e2..c6aba58 100644
8ec399
--- a/src/lib/abrt_conf.c
8ec399
+++ b/src/lib/abrt_conf.c
8ec399
@@ -27,6 +27,7 @@ bool          g_settings_delete_uploaded = 0;
8ec399
 bool          g_settings_autoreporting = 0;
8ec399
 char *        g_settings_autoreporting_event = NULL;
8ec399
 bool          g_settings_shortenedreporting = 0;
8ec399
+bool          g_settings_privatereports = true;
8ec399
 
8ec399
 void free_abrt_conf_data()
8ec399
 {
8ec399
@@ -102,6 +103,13 @@ static void ParseCommon(map_string_t *settings, const char *conf_filename)
8ec399
     else
8ec399
         g_settings_shortenedreporting = 0;
8ec399
 
8ec399
+    value = get_map_string_item_or_NULL(settings, "PrivateReports");
8ec399
+    if (value)
8ec399
+    {
8ec399
+        g_settings_privatereports = string_to_bool(value);
8ec399
+        remove_map_string_item(settings, "PrivateReports");
8ec399
+    }
8ec399
+
8ec399
     GHashTableIter iter;
8ec399
     const char *name;
8ec399
     /*char *value; - already declared */
8ec399
diff --git a/src/lib/hooklib.c b/src/lib/hooklib.c
8ec399
index 1d45cdd..fb7750d 100644
8ec399
--- a/src/lib/hooklib.c
8ec399
+++ b/src/lib/hooklib.c
8ec399
@@ -410,7 +410,12 @@ char* problem_data_save(problem_data_t *pd)
8ec399
 {
8ec399
     load_abrt_conf();
8ec399
 
8ec399
-    struct dump_dir *dd = create_dump_dir_from_problem_data(pd, g_settings_dump_location);
8ec399
+    struct dump_dir *dd = NULL;
8ec399
+
8ec399
+    if (g_settings_privatereports)
8ec399
+        dd = create_dump_dir_from_problem_data_ext(pd, g_settings_dump_location, 0);
8ec399
+    else
8ec399
+        dd = create_dump_dir_from_problem_data(pd, g_settings_dump_location);
8ec399
 
8ec399
     char *problem_id = NULL;
8ec399
     if (dd)
8ec399
diff --git a/src/plugins/abrt-dump-oops.c b/src/plugins/abrt-dump-oops.c
8ec399
index 9f0dc87..05cb728 100644
8ec399
--- a/src/plugins/abrt-dump-oops.c
8ec399
+++ b/src/plugins/abrt-dump-oops.c
8ec399
@@ -189,6 +189,14 @@ static unsigned create_oops_dump_dirs(GList *oops_list, unsigned oops_cnt)
8ec399
         mode = DEFAULT_DUMP_DIR_MODE;
8ec399
         my_euid = geteuid();
8ec399
     }
8ec399
+    if (g_settings_privatereports)
8ec399
+    {
8ec399
+        if (world_readable_dump)
8ec399
+            log("Not going to make dump directories world readable because PrivateReports is on");
8ec399
+
8ec399
+        mode = DEFAULT_DUMP_DIR_MODE;
8ec399
+        my_euid = 0;
8ec399
+    }
8ec399
 
8ec399
     pid_t my_pid = getpid();
8ec399
     unsigned idx = 0;
8ec399
diff --git a/src/plugins/abrt-dump-xorg.c b/src/plugins/abrt-dump-xorg.c
8ec399
index 3500629..434dc76 100644
8ec399
--- a/src/plugins/abrt-dump-xorg.c
8ec399
+++ b/src/plugins/abrt-dump-xorg.c
8ec399
@@ -82,6 +82,14 @@ static void save_bt_to_dump_dir(const char *bt, const char *exe, const char *rea
8ec399
         mode = DEFAULT_DUMP_DIR_MODE;
8ec399
         my_euid = geteuid();
8ec399
     }
8ec399
+    if (g_settings_privatereports)
8ec399
+    {
8ec399
+        if ((g_opts & OPT_x))
8ec399
+            log("Not going to make dump directories world readable because PrivateReports is on");
8ec399
+
8ec399
+        mode = DEFAULT_DUMP_DIR_MODE;
8ec399
+        my_euid = 0;
8ec399
+    }
8ec399
 
8ec399
     pid_t my_pid = getpid();
8ec399
 
8ec399
-- 
8ec399
1.8.3.1
8ec399