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

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