Blame SOURCES/0082-setgid-instead-of-setuid-the-abrt-action-install-deb.patch

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