-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
run wasm out of memory in mac causes node crash due to SIGBUS #46559
Comments
Ha, I remember asking if we didn't also have to catch SIGBUS to intercept WASM OOB accesses but back then that code was only enabled for Linux, which uses SIGSEGV instead of SIGBUS. Does this patch fix it? diff --git a/src/node.cc b/src/node.cc
index f92be4b089d..f2e688d7648 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -553,7 +553,12 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = TrapWebAssemblyOrContinue;
sa.sa_flags = SA_SIGINFO;
- CHECK_EQ(sigaction(SIGSEGV, &sa, nullptr), 0);
+#if __APPLE__
+ const int nr = SIGBUS;
+#else // Linux, FreeBSD
+ const int nr = SIGSEGV;
+#endif
+ CHECK_EQ(sigaction(nr, &sa, nullptr), 0);
}
#endif // defined(_WIN32)
V8::EnableWebAssemblyTrapHandler(false); |
Actually in macos we need to catch two exception, SIGBUS and SIGSEGV Bus Error occur when a process is trying to access memory that the CPU cannot physically address.In other words the memory tried to access by the program is not a valid memory address.It caused due to alignment issues with the CPU. Segmentation Fault occur when the program tries to write/read outside the memory allocated for it or when writing memory which can only be read.In other words when the program tries to access the memory to which it doesn’t have access to. from https://www.geeksforgeeks.org/segmentation-fault-sigsegv-vs-bus-error-sigbus/ |
Right, that's good general advice but in this specific case, due to how V8 wires up the trap handler, only SIGBUS is relevant. |
We're seeing the same issue on mac and HerrCai0907's fix works for us. Is there anything we can do to help get this merged in node? |
@unilynx The PR is blocked by ASan and I have no idea about node test environment and don't know how to test and fix this issue. |
I've found https://github.com/nodejs/node/blob/main/.github/workflows/test-asan.yml but that one says Too bad the logs aren't visible anymore but I do see a note at the bottom of https://github.com/nodejs/node/pull/46561/files pointing to test-cluster-primary-error.js - which is not the test you added. Maybe rebasing your PR would be sufficient? |
fix: #46559 OSX will raise both SIGBUS and SIGSEGV when out of bound memory visit, This commit set sigaction in OSX for two signals to handle this. PR-URL: #46561 Fixes: #46559 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
fix: #46559 OSX will raise both SIGBUS and SIGSEGV when out of bound memory visit, This commit set sigaction in OSX for two signals to handle this. PR-URL: #46561 Fixes: #46559 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
fix: nodejs#46559 OSX will raise both SIGBUS and SIGSEGV when out of bound memory visit, This commit set sigaction in OSX for two signals to handle this. PR-URL: nodejs#46561 Fixes: nodejs#46559 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
fix: nodejs#46559 OSX will raise both SIGBUS and SIGSEGV when out of bound memory visit, This commit set sigaction in OSX for two signals to handle this. PR-URL: nodejs#46561 Fixes: nodejs#46559 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
fix: #46559 OSX will raise both SIGBUS and SIGSEGV when out of bound memory visit, This commit set sigaction in OSX for two signals to handle this. PR-URL: #46561 Fixes: #46559 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
fix: #46559 OSX will raise both SIGBUS and SIGSEGV when out of bound memory visit, This commit set sigaction in OSX for two signals to handle this. PR-URL: #46561 Fixes: #46559 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
Version
v20.0.0-pre v16.19.0 v18.14.0
Platform
Darwin LSCN1036555 22.3.0 Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000 arm64
Subsystem
wasm
What steps will reproduce the bug?
run these code in mac, and will get SIGBUS ERROR
How often does it reproduce? Is there a required condition?
100% reproduce
What is the expected behavior?
behavior should be like in other arch.
wasm://wasm/5c312dfe:1
RuntimeError: memory access out of bounds
at assembly/index/_start (wasm://wasm/5c312dfe:wasm-function[0]:0x63)
at /Users/q540239/oss/as/tests/index.cjs:9:17
What do you see instead?
NA
Additional information
No response
The text was updated successfully, but these errors were encountered: