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

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