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

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