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

[compiler-rt][nsan] Disable coredump creation #98807

Merged

Conversation

chestnykh
Copy link
Contributor

@chestnykh chestnykh commented Jul 14, 2024

  • Disable coredump creation
    If NSAN_OPTIONS contains abort_on_error=1 the process hangs because the kernel tries to create a very huge core

msan, asan, tsan etc. runtimes disables coredumps too

Fix #98806

@chestnykh
Copy link
Contributor Author

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 14, 2024

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

Author: Dmitriy Chestnykh (chestnykh)

Changes
  • Install deadly signal handlers to print an informative report if something like SIGSEGV was happened
  • Disable coredump creation
  • If NSAN_OPTIONS contains abort_on_error=1 the process hangs because the kernel tries to create a very huge core

Fix #98806


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

1 Files Affected:

  • (modified) compiler-rt/lib/nsan/nsan.cpp (+17-1)
diff --git a/compiler-rt/lib/nsan/nsan.cpp b/compiler-rt/lib/nsan/nsan.cpp
index 7a5f013579dfb..efcbf6a1bedb4 100644
--- a/compiler-rt/lib/nsan/nsan.cpp
+++ b/compiler-rt/lib/nsan/nsan.cpp
@@ -535,7 +535,10 @@ int32_t checkFT(const FT value, ShadowFT Shadow, CheckTypeT CheckType,
   }
 
   if (flags().halt_on_error) {
-    Printf("Exiting\n");
+    if (common_flags()->abort_on_error)
+      Printf("ABORTING\n");
+    else
+      Printf("Exiting\n");
     Die();
   }
   return flags().resume_after_warning ? kResumeFromValue : kContinueWithShadow;
@@ -776,6 +779,16 @@ extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_dump_shadow_args() {
   printf("args tag: %lx\n", __nsan_shadow_args_tag);
 }
 
+static void OnStackUnwind(const SignalContext &sig, const void *,
+                          BufferedStackTrace *stack) {
+  stack->Unwind(StackTrace::GetNextInstructionPc(sig.pc), sig.bp, sig.context,
+                common_flags()->fast_unwind_on_fatal);
+}
+
+static void NsanOnDeadlySignal(int signo, void *siginfo, void *context) {
+  HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr);
+}
+
 bool __nsan::nsan_initialized;
 bool __nsan::nsan_init_is_running;
 
@@ -789,6 +802,9 @@ extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_init() {
   InitializeSuppressions();
   InitializePlatformEarly();
 
+  DisableCoreDumperIfNecessary();
+  InstallDeadlySignalHandlers(NsanOnDeadlySignal);
+
   if (!MmapFixedNoReserve(TypesAddr(), UnusedAddr() - TypesAddr()))
     Die();
 

- Install deadly signal handlers to print an informative
report if something like SIGSEGV was happened
- Disable coredump creation
If NSAN_OPTIONS contains `abort_on_error=1` the process
hangs because the kernel tries to create a very huge core

Fix llvm#98806
Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling core dumps makes sense.

google/sanitizers#637 describes why many sanitizers install signal handlers. But nsan doesn't deal with these undefined behaviors and perhaps doesn't need it?

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling core dumps makes sense.

google/sanitizers#637 describes why many sanitizers install signal handlers. But nsan doesn't deal with these undefined behaviors and perhaps doesn't need it?

@chestnykh
Copy link
Contributor Author

Disabling core dumps makes sense.

google/sanitizers#637 describes why many sanitizers install signal handlers. But nsan doesn't deal with these undefined behaviors and perhaps doesn't need it?

Okay, i thought that signal handler is installed to have detail report about crashes caused by signal :)

@chestnykh chestnykh changed the title [compiler-rt][nsan] Add two steps in init process [compiler-rt][nsan] Disable coredump creation Jul 15, 2024
Copy link
Collaborator

@alexander-shaposhnikov alexander-shaposhnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to me LG, i'd wait for @MaskRay

@chestnykh
Copy link
Contributor Author

@MaskRay @alexander-shaposhnikov merge please this PR, I don't have write permissions

@alexander-shaposhnikov alexander-shaposhnikov merged commit 56ee6a1 into llvm:main Jul 15, 2024
6 checks passed
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.

[compiler-rt][nsan] abort_on_error=1 causes hang of the process
4 participants