arrfab / rpms / abrt

Forked from rpms/abrt 5 years ago
Clone

Blame SOURCES/0120-a-a-i-d-t-a-cache-don-t-open-the-build_ids-file-as-a.patch

baab13
From 3bdf6305f6a8501a692e1a98f98e0be9d3922a1d Mon Sep 17 00:00:00 2001
baab13
From: Jakub Filak <jfilak@redhat.com>
baab13
Date: Wed, 20 May 2015 08:08:58 +0200
baab13
Subject: [ABRT PATCH] a-a-i-d-t-a-cache: don't open the build_ids file as abrt
baab13
baab13
Opening the build_ids file as abrt may lead to information disclosure.
baab13
baab13
Related: #1216962
baab13
baab13
Signed-off-by: Jakub Filak <jfilak@redhat.com>
baab13
---
baab13
 .../abrt-action-install-debuginfo-to-abrt-cache.c  | 30 +++++++++++++++++-----
baab13
 1 file changed, 23 insertions(+), 7 deletions(-)
baab13
baab13
diff --git a/src/plugins/abrt-action-install-debuginfo-to-abrt-cache.c b/src/plugins/abrt-action-install-debuginfo-to-abrt-cache.c
baab13
index cd9ee7a..fafb0c4 100644
baab13
--- a/src/plugins/abrt-action-install-debuginfo-to-abrt-cache.c
baab13
+++ b/src/plugins/abrt-action-install-debuginfo-to-abrt-cache.c
baab13
@@ -72,6 +72,11 @@ int main(int argc, char **argv)
baab13
     };
baab13
     const unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
baab13
 
baab13
+    const gid_t egid = getegid();
baab13
+    const gid_t rgid = getgid();
baab13
+    const uid_t euid = geteuid();
baab13
+    const gid_t ruid = getuid();
baab13
+
baab13
     /* We need to open the build ids file under the caller's UID/GID to avoid
baab13
      * information disclosures when reading files with changed UID.
baab13
      * Unfortunately, we cannot replace STDIN with the new fd because ABRT uses
baab13
@@ -82,7 +87,20 @@ int main(int argc, char **argv)
baab13
     char *build_ids_self_fd = NULL;
baab13
     if (strcmp("-", build_ids) != 0)
baab13
     {
baab13
+        if (setregid(egid, rgid) < 0)
baab13
+            perror_msg_and_die("setregid(egid, rgid)");
baab13
+
baab13
+        if (setreuid(euid, ruid) < 0)
baab13
+            perror_msg_and_die("setreuid(euid, ruid)");
baab13
+
baab13
         const int build_ids_fd = open(build_ids, O_RDONLY);
baab13
+
baab13
+        if (setregid(rgid, egid) < 0)
baab13
+            perror_msg_and_die("setregid(rgid, egid)");
baab13
+
baab13
+        if (setreuid(ruid, euid) < 0 )
baab13
+            perror_msg_and_die("setreuid(ruid, euid)");
baab13
+
baab13
         if (build_ids_fd < 0)
baab13
             perror_msg_and_die("Failed to open file '%s'", build_ids);
baab13
 
baab13
@@ -118,14 +136,12 @@ int main(int argc, char **argv)
baab13
     /* Switch real user/group to effective ones.
baab13
      * Otherwise yum library gets confused - gets EPERM (why??).
baab13
      */
baab13
-    gid_t g = getegid();
baab13
     /* do setregid only if we have to, to not upset selinux needlessly */
baab13
-    if (g != getgid())
baab13
-        IGNORE_RESULT(setregid(g, g));
baab13
-    uid_t u = geteuid();
baab13
-    if (u != getuid())
baab13
+    if (egid != rgid)
baab13
+        IGNORE_RESULT(setregid(egid, egid));
baab13
+    if (euid != ruid)
baab13
     {
baab13
-        IGNORE_RESULT(setreuid(u, u));
baab13
+        IGNORE_RESULT(setreuid(euid, euid));
baab13
         /* We are suid'ed! */
baab13
         /* Prevent malicious user from messing up with suid'ed process: */
baab13
 #if 1
baab13
@@ -179,7 +195,7 @@ int main(int argc, char **argv)
baab13
         // abrt-action-install-debuginfo doesn't fail when spawning
baab13
         // abrt-action-trim-files
baab13
         char path_env[] = "PATH=/usr/sbin:/sbin:/usr/bin:/bin:"BIN_DIR":"SBIN_DIR;
baab13
-        if (u != 0)
baab13
+        if (euid != 0)
baab13
             strcpy(path_env, "PATH=/usr/bin:/bin:"BIN_DIR);
baab13
         putenv(path_env);
baab13
 
baab13
-- 
baab13
1.8.3.1
baab13