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

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