Blame SOURCES/0116-daemon-dbus-allow-only-root-to-create-CCpp-Koops-vmc.patch

baab13
From 7417505e1d93cc95ec648b74e3c801bc67aacb9f Mon Sep 17 00:00:00 2001
baab13
From: Jakub Filak <jfilak@redhat.com>
baab13
Date: Thu, 7 May 2015 11:07:12 +0200
baab13
Subject: [ABRT PATCH] daemon, dbus: allow only root to create CCpp, Koops,
baab13
 vmcore and xorg
baab13
MIME-Version: 1.0
baab13
Content-Type: text/plain; charset=UTF-8
baab13
Content-Transfer-Encoding: 8bit
baab13
baab13
Florian Weimer <fweimer@redhat.com>:
baab13
    This prevents users from feeding things that are not actually
baab13
    coredumps and excerpts from /proc to these analyzers.
baab13
baab13
    For example, it should not be possible to trigger a rule with
baab13
    “EVENT=post-create analyzer=CCpp” using NewProblem
baab13
baab13
Related: #1212861
baab13
baab13
Signed-off-by: Jakub Filak <jfilak@redhat.com>
baab13
---
baab13
 src/daemon/abrt-server.c |  2 +-
baab13
 src/dbus/abrt-dbus.c     | 10 +++++++++-
baab13
 src/include/libabrt.h    |  2 ++
baab13
 src/lib/hooklib.c        | 24 ++++++++++++++++++++++++
baab13
 4 files changed, 36 insertions(+), 2 deletions(-)
baab13
baab13
diff --git a/src/daemon/abrt-server.c b/src/daemon/abrt-server.c
baab13
index d3fa1b5..afd9fd3 100644
baab13
--- a/src/daemon/abrt-server.c
baab13
+++ b/src/daemon/abrt-server.c
baab13
@@ -487,7 +487,7 @@ static gboolean key_value_ok(gchar *key, gchar *value)
baab13
         }
baab13
     }
baab13
 
baab13
-    return TRUE;
baab13
+    return allowed_new_user_problem_entry(client_uid, key, value);
baab13
 }
baab13
 
baab13
 /* Handles a message received from client over socket. */
baab13
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
baab13
index 6de15e9..bef95bd 100644
baab13
--- a/src/dbus/abrt-dbus.c
baab13
+++ b/src/dbus/abrt-dbus.c
baab13
@@ -168,6 +168,7 @@ bool allowed_problem_dir(const char *dir_name)
baab13
 
baab13
 static char *handle_new_problem(GVariant *problem_info, uid_t caller_uid, char **error)
baab13
 {
baab13
+    char *problem_id = NULL;
baab13
     problem_data_t *pd = problem_data_new();
baab13
 
baab13
     GVariantIter *iter;
baab13
@@ -175,6 +176,12 @@ static char *handle_new_problem(GVariant *problem_info, uid_t caller_uid, char *
baab13
     gchar *key, *value;
baab13
     while (g_variant_iter_loop(iter, "{ss}", &key, &value))
baab13
     {
baab13
+        if (allowed_new_user_problem_entry(caller_uid, key, value) == false)
baab13
+        {
baab13
+            *error = xasprintf("You are not allowed to create element '%s' containing '%s'", key, value);
baab13
+            goto finito;
baab13
+        }
baab13
+
baab13
         problem_data_add_text_editable(pd, key, value);
baab13
     }
baab13
 
baab13
@@ -189,12 +196,13 @@ static char *handle_new_problem(GVariant *problem_info, uid_t caller_uid, char *
baab13
     /* At least it should generate local problem identifier UUID */
baab13
     problem_data_add_basics(pd);
baab13
 
baab13
-    char *problem_id = problem_data_save(pd);
baab13
+    problem_id = problem_data_save(pd);
baab13
     if (problem_id)
baab13
         notify_new_path(problem_id);
baab13
     else if (error)
baab13
         *error = xasprintf("Cannot create a new problem");
baab13
 
baab13
+finito:
baab13
     problem_data_free(pd);
baab13
     return problem_id;
baab13
 }
baab13
diff --git a/src/include/libabrt.h b/src/include/libabrt.h
baab13
index 5bf2397..3749a31 100644
baab13
--- a/src/include/libabrt.h
baab13
+++ b/src/include/libabrt.h
baab13
@@ -51,6 +51,8 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
baab13
 bool dir_is_in_dump_location(const char *dir_name);
baab13
 #define dir_has_correct_permissions abrt_dir_has_correct_permissions
baab13
 bool dir_has_correct_permissions(const char *dir_name);
baab13
+#define allowed_new_user_problem_entry abrt_allowed_new_user_problem_entry
baab13
+bool allowed_new_user_problem_entry(uid_t uid, const char *name, const char *value);
baab13
 
baab13
 #define g_settings_nMaxCrashReportsSize abrt_g_settings_nMaxCrashReportsSize
baab13
 extern unsigned int  g_settings_nMaxCrashReportsSize;
baab13
diff --git a/src/lib/hooklib.c b/src/lib/hooklib.c
baab13
index 4b20025..8e93663 100644
baab13
--- a/src/lib/hooklib.c
baab13
+++ b/src/lib/hooklib.c
baab13
@@ -483,3 +483,27 @@ bool dir_has_correct_permissions(const char *dir_name)
baab13
     }
baab13
     return true;
baab13
 }
baab13
+
baab13
+bool allowed_new_user_problem_entry(uid_t uid, const char *name, const char *value)
baab13
+{
baab13
+    /* Allow root to create everything */
baab13
+    if (uid == 0)
baab13
+        return true;
baab13
+
baab13
+    /* Permit non-root users to create everything except: analyzer and type */
baab13
+    if (strcmp(name, FILENAME_ANALYZER) != 0
baab13
+     && strcmp(name, FILENAME_TYPE) != 0
baab13
+     /* compatibility value used in abrt-server */
baab13
+     && strcmp(name, "basename") != 0)
baab13
+        return true;
baab13
+
baab13
+    /* Permit non-root users to create all types except: C/C++, Koops, vmcore and xorg */
baab13
+     if (strcmp(value, "CCpp") != 0
baab13
+      && strcmp(value, "Kerneloops") != 0
baab13
+      && strcmp(value, "vmcore") != 0
baab13
+      && strcmp(value, "xorg") != 0)
baab13
+        return true;
baab13
+
baab13
+    error_msg("Only root is permitted to create element '%s' containing '%s'", name, value);
baab13
+    return false;
baab13
+}
baab13
-- 
baab13
1.8.3.1
baab13