Blame SOURCES/0095-ccpp-do-not-override-existing-files-by-compat-cores.patch

8ec399
From af945ff58a698ce00c45059a05994ef53a13e192 Mon Sep 17 00:00:00 2001
8ec399
From: Jakub Filak <jfilak@redhat.com>
8ec399
Date: Fri, 17 Apr 2015 14:36:45 +0200
8ec399
Subject: [ABRT PATCH] ccpp: do not override existing files by compat cores
8ec399
8ec399
Implement all checks used in kernel's do_coredump() and require
8ec399
non-relative path if suid_dumpable is 2.
8ec399
8ec399
Related: #1212818
8ec399
8ec399
Signed-off-by: Jakub Filak <jfilak@redhat.com>
8ec399
---
8ec399
 src/hooks/abrt-hook-ccpp.c | 20 ++++++++++++++++----
8ec399
 1 file changed, 16 insertions(+), 4 deletions(-)
8ec399
8ec399
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
8ec399
index 85e0d35..82ff555 100644
8ec399
--- a/src/hooks/abrt-hook-ccpp.c
8ec399
+++ b/src/hooks/abrt-hook-ccpp.c
8ec399
@@ -24,6 +24,8 @@
8ec399
 #define  DUMP_SUID_UNSAFE 1
8ec399
 #define  DUMP_SUID_SAFE 2
8ec399
 
8ec399
+static int g_user_core_flags;
8ec399
+static int g_need_nonrelative;
8ec399
 
8ec399
 /* I want to use -Werror, but gcc-4.4 throws a curveball:
8ec399
  * "warning: ignoring return value of 'ftruncate', declared with attribute warn_unused_result"
8ec399
@@ -337,7 +339,14 @@ static int open_user_core(uid_t uid, uid_t fsuid, pid_t pid, char **percent_valu
8ec399
 
8ec399
     full_core_basename = core_basename;
8ec399
     if (core_basename[0] != '/')
8ec399
+    {
8ec399
+        if (g_need_nonrelative)
8ec399
+        {
8ec399
+            error_msg("Current suid_dumpable policy prevents from saving core dumps according to relative core_pattern");
8ec399
+            return -1;
8ec399
+        }
8ec399
         core_basename = concat_path_file(user_pwd, core_basename);
8ec399
+    }
8ec399
 
8ec399
     /* Open (create) compat core file.
8ec399
      * man core:
8ec399
@@ -372,19 +381,19 @@ static int open_user_core(uid_t uid, uid_t fsuid, pid_t pid, char **percent_valu
8ec399
     struct stat sb;
8ec399
     errno = 0;
8ec399
     /* Do not O_TRUNC: if later checks fail, we do not want to have file already modified here */
8ec399
-    int user_core_fd = open(core_basename, O_WRONLY | O_CREAT | O_NOFOLLOW, 0600); /* kernel makes 0600 too */
8ec399
+    int user_core_fd = open(core_basename, O_WRONLY | O_CREAT | O_NOFOLLOW | g_user_core_flags, 0600); /* kernel makes 0600 too */
8ec399
     xsetegid(0);
8ec399
     xseteuid(0);
8ec399
     if (user_core_fd < 0
8ec399
      || fstat(user_core_fd, &sb) != 0
8ec399
      || !S_ISREG(sb.st_mode)
8ec399
      || sb.st_nlink != 1
8ec399
-    /* kernel internal dumper checks this too: if (inode->i_uid != current->fsuid) <fail>, need to mimic? */
8ec399
+     || sb.st_uid != fsuid
8ec399
     ) {
8ec399
         if (user_core_fd < 0)
8ec399
             perror_msg("Can't open '%s'", full_core_basename);
8ec399
         else
8ec399
-            perror_msg("'%s' is not a regular file with link count 1", full_core_basename);
8ec399
+            perror_msg("'%s' is not a regular file with link count 1 owned by UID(%d)", full_core_basename, fsuid);
8ec399
         return -1;
8ec399
     }
8ec399
     if (ftruncate(user_core_fd, 0) != 0) {
8ec399
@@ -578,8 +587,11 @@ int main(int argc, char** argv)
8ec399
         /* use root for suided apps unless it's explicitly set to UNSAFE */
8ec399
         fsuid = 0;
8ec399
         if (suid_policy == DUMP_SUID_UNSAFE)
8ec399
-        {
8ec399
             fsuid = tmp_fsuid;
8ec399
+        else
8ec399
+        {
8ec399
+            g_user_core_flags = O_EXCL;
8ec399
+            g_need_nonrelative = 1;
8ec399
         }
8ec399
     }
8ec399
 
8ec399
-- 
8ec399
1.8.3.1
8ec399