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

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