8a8645
From 0966d7fd6e3d51fc99088de94343212c5f09e74d Mon Sep 17 00:00:00 2001
8a8645
From: =?UTF-8?q?Miroslav=20Such=C3=BD?= <msuchy@redhat.com>
8a8645
Date: Tue, 5 May 2020 18:28:50 +0200
8a8645
Subject: [PATCH] setgid instead of setuid the
8a8645
 abrt-action-install-debuginfo-to-abrt-cache [RHBZ 1796245]
8a8645
8a8645
OpenSCAP does not like setuid files, we can be setgid instead.
8a8645
8a8645
We need to g+w the directories so other run under a different user can be able to write there too.
8a8645
8a8645
Resolves:
8a8645
    https://bugzilla.redhat.com/show_bug.cgi?id=1796245
8a8645
---
8a8645
 abrt.spec.in                                      |  4 ++--
8a8645
 .../abrt-action-install-debuginfo-to-abrt-cache.c | 15 +++------------
8a8645
 src/plugins/abrt-action-install-debuginfo.in      |  6 ++++++
8a8645
 3 files changed, 11 insertions(+), 14 deletions(-)
8a8645
8a8645
diff --git a/abrt.spec.in b/abrt.spec.in
8a8645
index 326294008..4c01fffe6 100644
8a8645
--- a/abrt.spec.in
8a8645
+++ b/abrt.spec.in
8a8645
@@ -1015,8 +1015,8 @@ killall abrt-dbus >/dev/null 2>&1 || :
8a8645
 
8a8645
 %dir %{_localstatedir}/lib/abrt
8a8645
 
8a8645
-# attr(6755) ~= SETUID|SETGID
8a8645
-%attr(6755, abrt, abrt) %{_libexecdir}/abrt-action-install-debuginfo-to-abrt-cache
8a8645
+# attr(2755) ~= SETGID
8a8645
+%attr(2755, abrt, abrt) %{_libexecdir}/abrt-action-install-debuginfo-to-abrt-cache
8a8645
 
8a8645
 %{_bindir}/abrt-action-analyze-c
8a8645
 %{_bindir}/abrt-action-trim-files
8a8645
diff --git a/src/plugins/abrt-action-install-debuginfo-to-abrt-cache.c b/src/plugins/abrt-action-install-debuginfo-to-abrt-cache.c
8a8645
index 71967f77a..0f843512e 100644
8a8645
--- a/src/plugins/abrt-action-install-debuginfo-to-abrt-cache.c
8a8645
+++ b/src/plugins/abrt-action-install-debuginfo-to-abrt-cache.c
8a8645
@@ -78,7 +78,6 @@ int main(int argc, char **argv)
8a8645
     const gid_t egid = getegid();
8a8645
     const gid_t rgid = getgid();
8a8645
     const uid_t euid = geteuid();
8a8645
-    const gid_t ruid = getuid();
8a8645
 
8a8645
     /* We need to open the build ids file under the caller's UID/GID to avoid
8a8645
      * information disclosures when reading files with changed UID.
8a8645
@@ -93,17 +92,11 @@ int main(int argc, char **argv)
8a8645
         if (setregid(egid, rgid) < 0)
8a8645
             perror_msg_and_die("setregid(egid, rgid)");
8a8645
 
8a8645
-        if (setreuid(euid, ruid) < 0)
8a8645
-            perror_msg_and_die("setreuid(euid, ruid)");
8a8645
-
8a8645
         const int build_ids_fd = open(build_ids, O_RDONLY);
8a8645
 
8a8645
         if (setregid(rgid, egid) < 0)
8a8645
             perror_msg_and_die("setregid(rgid, egid)");
8a8645
 
8a8645
-        if (setreuid(ruid, euid) < 0 )
8a8645
-            perror_msg_and_die("setreuid(ruid, euid)");
8a8645
-
8a8645
         if (build_ids_fd < 0)
8a8645
             perror_msg_and_die("Failed to open file '%s'", build_ids);
8a8645
 
8a8645
@@ -155,12 +148,10 @@ int main(int argc, char **argv)
8a8645
      */
8a8645
     /* do setregid only if we have to, to not upset selinux needlessly */
8a8645
     if (egid != rgid)
8a8645
-        IGNORE_RESULT(setregid(egid, egid));
8a8645
-    if (euid != ruid)
8a8645
     {
8a8645
-        IGNORE_RESULT(setreuid(euid, euid));
8a8645
-        /* We are suid'ed! */
8a8645
-        /* Prevent malicious user from messing up with suid'ed process: */
8a8645
+        IGNORE_RESULT(setregid(egid, egid));
8a8645
+        /* We are sgid'ed! */
8a8645
+        /* Prevent malicious user from messing up with sgid'ed process: */
8a8645
 #if 1
8a8645
 // We forgot to sanitize PYTHONPATH. And who knows what else we forgot
8a8645
 // (especially considering *future* new variables of this kind).
8a8645
diff --git a/src/plugins/abrt-action-install-debuginfo.in b/src/plugins/abrt-action-install-debuginfo.in
8a8645
index 6269c221e..659a9aa84 100644
8a8645
--- a/src/plugins/abrt-action-install-debuginfo.in
8a8645
+++ b/src/plugins/abrt-action-install-debuginfo.in
8a8645
@@ -248,6 +248,12 @@ if __name__ == "__main__":
8a8645
                                     repo_pattern=repo_pattern,
8a8645
                                     releasever=releasever)
8a8645
             result = downloader.download(missing, download_exact_files=exact_fls)
8a8645
+
8a8645
+            # make sure that all downloaded directories are writeable by abrt group
8a8645
+            for root, dirs, files in os.walk(self.cachedirs[0]):
8a8645
+                for walked_dir in dirs:
8a8645
+                    os.chmod(os.path.join(root, walked_dir), 0o775)
8a8645
+
8a8645
         except OSError as ex:
8a8645
             if ex.errno == errno.EPIPE:
8a8645
                 clean_up(TMPDIR, silent=True)
8a8645
-- 
8a8645
2.21.3
8a8645