Set permissions explicitly for directories and reports 02/253202/1
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 5 Feb 2021 10:47:31 +0000 (11:47 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 5 Feb 2021 11:41:12 +0000 (12:41 +0100)
Change-Id: If01ddf2a7f73a6b808f3cd8d39f20a77c74231d3

include/defs.h.in
src/crash-manager/crash-manager.c

index 8c0760a..906b649 100644 (file)
@@ -3,6 +3,8 @@
 
 #define KERNEL_DEFINED_TASK_COMM_LEN 16 // from include/linux/sched.h
 #define DEFAULT_UMASK                0077
+#define DEFAULT_REPORT_PERM          0644
+#define DEFAULT_CRASH_DIR_PERM       0775
 
 #define CRASH_PATH                     "@CRASH_PATH@"
 #define CRASH_ROOT_PATH                        "@CRASH_ROOT_PATH@"
index 71ab920..80e3b69 100644 (file)
@@ -265,14 +265,17 @@ static bool make_dump_dir(void)
                const char *dirname = dirs[i];
 
                int r = mkdir(dirname, 0775);
-               if (r >= 0)
-                       continue;
 
-               if (errno != EEXIST) {
+               if (r < 0 && errno != EEXIST) {
                        _E("Unable to create directory %s: %m", dirname);
                        return false;
                }
 
+               chmod(dirname, DEFAULT_CRASH_DIR_PERM); // Fixup permissions for directories created with bad umask
+
+               if (r >= 0)
+                       continue;
+
                struct stat st = {0};
                r = stat(dirname, &st);
                bool isdir = !!(st.st_mode & S_IFDIR);
@@ -1208,9 +1211,10 @@ static bool move_dump_data(const char *from_path, const struct crash_info *cinfo
 
        if ((lock_fd = lock_dir(crash_dump_path, false)) < 0)
                return false;
-       if (!rename(from_path, cinfo->result_path))
+       if (!rename(from_path, cinfo->result_path)) {
+               chmod(cinfo->result_path, DEFAULT_REPORT_PERM);
                clean_dump();
-       else {
+       else {
                _E("Failed to move %s to %s", from_path, cinfo->result_path);
                (void)check_disk_available(crash_dump_path, SPACE_REQUIRED_KB);
                is_ok = false;