Merge "Make tombstones 664." into main am: d3fb7a6355 am: 19a8e857a7

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2976111

Change-Id: Ibf5acde794a7a842e714e8a56bb7a46c06ad1af4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/debuggerd/tombstoned/tombstoned.cpp b/debuggerd/tombstoned/tombstoned.cpp
index e79035f..98eb003 100644
--- a/debuggerd/tombstoned/tombstoned.cpp
+++ b/debuggerd/tombstoned/tombstoned.cpp
@@ -156,6 +156,11 @@
 
       result.temporary_path = std::move(tmp_filename);
     }
+    // We need to fchmodat after creating to avoid getting the umask applied.
+    std::string fd_path = StringPrintf("/proc/self/fd/%d", result.fd.get());
+    if (fchmodat(dir_fd_, fd_path.c_str(), 0664, 0) != 0) {
+      PLOG(ERROR) << "Failed to make tombstone world-readable";
+    }
 
     return std::move(result);
   }
diff --git a/rootdir/init.rc b/rootdir/init.rc
index f3b2d03..3c367f9 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -709,7 +709,7 @@
 
     # Start tombstoned early to be able to store tombstones.
     mkdir /data/anr 0775 system system encryption=Require
-    mkdir /data/tombstones 0771 system system encryption=Require
+    mkdir /data/tombstones 0775 system system encryption=Require
     mkdir /data/vendor/tombstones 0771 root root
     mkdir /data/vendor/tombstones/wifi 0771 wifi wifi
     start tombstoned