Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[compiler-rt] Avoid generating coredumps when piped to a tool" #85390

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

antmox
Copy link
Contributor

@antmox antmox commented Mar 15, 2024

This reverts commit 27e5312.

This commit broke some bots:

#83701

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 15, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: antoine moynault (antmox)

Changes

This reverts commit 27e5312.

This commit broke some bots:

#83701


Full diff: https://github.com/llvm/llvm-project/pull/85390.diff

2 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp (+1-18)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/corelimit.cpp (+1-6)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
index 3605d0d666e3fd..ef1fc354974396 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
@@ -104,24 +104,7 @@ static void setlim(int res, rlim_t lim) {
 
 void DisableCoreDumperIfNecessary() {
   if (common_flags()->disable_coredump) {
-    rlimit rlim;
-    CHECK_EQ(0, getrlimit(RLIMIT_CORE, &rlim));
-    // On Linux, if the kernel.core_pattern sysctl starts with a '|' (i.e. it
-    // is being piped to a coredump handler such as systemd-coredumpd), the
-    // kernel ignores RLIMIT_CORE (since we aren't creating a file in the file
-    // system) except for the magic value of 1, which disables coredumps when
-    // piping. 1 byte is too small for any kind of valid core dump, so it
-    // also disables coredumps if kernel.core_pattern creates files directly.
-    // While most piped coredump handlers do respect the crashing processes'
-    // RLIMIT_CORE, this is notable not the case for Debian's systemd-coredump
-    // due to a local patch that changes sysctl.d/50-coredump.conf to ignore
-    // the specified limit and instead use RLIM_INFINITY.
-    //
-    // The alternative to using RLIMIT_CORE=1 would be to use prctl() with the
-    // PR_SET_DUMPABLE flag, however that also prevents ptrace(), so makes it
-    // impossible to attach a debugger.
-    rlim.rlim_cur = Min<rlim_t>(SANITIZER_LINUX ? 1 : 0, rlim.rlim_max);
-    CHECK_EQ(0, setrlimit(RLIMIT_CORE, &rlim));
+    setlim(RLIMIT_CORE, 0);
   }
 }
 
diff --git a/compiler-rt/test/sanitizer_common/TestCases/corelimit.cpp b/compiler-rt/test/sanitizer_common/TestCases/corelimit.cpp
index fed2e1d89cbffa..2378a4cfdced12 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/corelimit.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/corelimit.cpp
@@ -10,12 +10,7 @@ int main() {
   getrlimit(RLIMIT_CORE, &lim_core);
   void *p;
   if (sizeof(p) == 8) {
-#ifdef __linux__
-    // See comments in DisableCoreDumperIfNecessary().
-    assert(lim_core.rlim_cur == 1);
-#else
-    assert(lim_core.rlim_cur == 0);
-#endif
+    assert(0 == lim_core.rlim_cur);
   }
   return 0;
 }

@antmox antmox merged commit 0b9f19a into llvm:main Mar 15, 2024
6 of 7 checks passed
@antmox antmox deleted the revert_avoid_generating_coredumps branch March 15, 2024 14:07
@MaskRay
Copy link
Member

MaskRay commented Mar 15, 2024

@arichardson compiler-rt/test/sanitizer_common/TestCases/corelimit.cpp needs an update

@arichardson
Copy link
Member

@arichardson compiler-rt/test/sanitizer_common/TestCases/corelimit.cpp needs an update

Hmm sounds like rlimit was already zero, will need to relax the test to accept zero or one to handle the min().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants