Blame 0097-ccpp-harden-dealing-with-UID-GID.patch

69165ba
From b72616471ec52a009904689592f4f69e730a6f56 Mon Sep 17 00:00:00 2001
69165ba
From: Jakub Filak <jfilak@redhat.com>
69165ba
Date: Fri, 17 Apr 2015 14:42:13 +0200
69165ba
Subject: [ABRT PATCH] ccpp: harden dealing with UID/GID
69165ba
69165ba
* Don't fall back to UID 0.
69165ba
* Use fsgid.
69165ba
69165ba
This issue was discovered by Florian Weimer of Red Hat Product Security.
69165ba
69165ba
Signed-off-by: Jakub Filak <jfilak@redhat.com>
69165ba
---
69165ba
 src/hooks/abrt-hook-ccpp.c | 39 ++++++++++++++++++++++++++-------------
69165ba
 1 file changed, 26 insertions(+), 13 deletions(-)
69165ba
69165ba
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
69165ba
index d600bb7..d9f1f5e 100644
69165ba
--- a/src/hooks/abrt-hook-ccpp.c
69165ba
+++ b/src/hooks/abrt-hook-ccpp.c
69165ba
@@ -218,23 +218,27 @@ static char* get_rootdir(pid_t pid)
69165ba
     return malloc_readlink(buf);
69165ba
 }
69165ba
 
69165ba
-static int get_fsuid(void)
69165ba
+static int get_proc_fs_id(char type)
69165ba
 {
69165ba
-    int real, euid, saved;
69165ba
-    /* if we fail to parse the uid, then make it root only readable to be safe */
69165ba
-    int fs_uid = 0;
69165ba
+    const char *scanf_format = "%*cid:\t%d\t%d\t%d\t%d\n";
69165ba
+    char id_type[] = "_id";
69165ba
+    id_type[0] = type;
69165ba
+
69165ba
+    int real, e_id, saved;
69165ba
+    int fs_id = 0;
69165ba
 
69165ba
     char *line = proc_pid_status; /* never NULL */
69165ba
     for (;;)
69165ba
     {
69165ba
-        if (strncmp(line, "Uid", 3) == 0)
69165ba
+        if (strncmp(line, id_type, 3) == 0)
69165ba
         {
69165ba
-            int n = sscanf(line, "Uid:\t%d\t%d\t%d\t%d\n", &real, &euid, &saved, &fs_uid);
69165ba
+            int n = sscanf(line, scanf_format, &real, &e_id, &saved, &fs_id);
69165ba
             if (n != 4)
69165ba
             {
69165ba
-                perror_msg_and_die("Can't parse Uid: line");
69165ba
+                perror_msg_and_die("Can't parse %cid: line", type);
69165ba
             }
69165ba
-            break;
69165ba
+
69165ba
+            return fs_id;
69165ba
         }
69165ba
         line = strchr(line, '\n');
69165ba
         if (!line)
69165ba
@@ -242,7 +246,17 @@ static int get_fsuid(void)
69165ba
         line++;
69165ba
     }
69165ba
 
69165ba
-    return fs_uid;
69165ba
+    perror_msg_and_die("Failed to get file system %cID of the crashed process", type);
69165ba
+}
69165ba
+
69165ba
+static int get_fsuid(void)
69165ba
+{
69165ba
+    return get_proc_fs_id(/*UID*/'U');
69165ba
+}
69165ba
+
69165ba
+static int get_fsgid(void)
69165ba
+{
69165ba
+    return get_proc_fs_id(/*GID*/'G');
69165ba
 }
69165ba
 
69165ba
 static int dump_suid_policy()
69165ba
@@ -278,10 +292,9 @@ static int open_user_core(uid_t uid, uid_t fsuid, pid_t pid, char **percent_valu
69165ba
     if (proc_cwd == NULL)
69165ba
         return -1;
69165ba
 
69165ba
-    struct passwd* pw = getpwuid(uid);
69165ba
-    gid_t gid = pw ? pw->pw_gid : uid;
69165ba
-    //log("setting uid: %i gid: %i", uid, gid);
69165ba
-    xsetegid(gid);
69165ba
+    errno = 0;
69165ba
+
69165ba
+    xsetegid(get_fsgid());
69165ba
     xseteuid(fsuid);
69165ba
 
69165ba
     if (strcmp(core_basename, "core") == 0)
69165ba
-- 
69165ba
1.8.3.1
69165ba