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

Qjs errors with on darwin asan #841

Closed
satk0 opened this issue Jan 20, 2025 · 6 comments
Closed

Qjs errors with on darwin asan #841

satk0 opened this issue Jan 20, 2025 · 6 comments

Comments

@satk0
Copy link
Contributor

satk0 commented Jan 20, 2025

Hi all,

While working on r2, @trufae has found an issue with asan while running qjs on Mac. Namely:

Image

The patch that makes it work is the following:

diff --git a/quickjs.c b/quickjs.c
index 3108855..4656d96 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -1773,9 +1773,13 @@ static inline uintptr_t js_get_stack_pointer(void)

 static inline bool js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
 {
+#if __has_feature(address_sanitizer)
+    return false;
+#else
     uintptr_t sp;
     sp = js_get_stack_pointer() - alloca_size;
     return unlikely(sp < rt->stack_limit);
+#endif
 }

 JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)

But idk if that's an elegant solution to this problem.

@saghul
Copy link
Contributor

saghul commented Jan 20, 2025

It's probably because due to how much ASN bloats the stack size the check doesn't pass.

Rather than doing that you can override it at the app layer by setting the stack size to 0 when compiling under ASAN.

qjs itself it able to run under ASAN no problem, I suppose because the extra JS code it runs is minimal.

@satk0
Copy link
Contributor Author

satk0 commented Jan 20, 2025

Oh nice, thanks for the answer, so setting STACK_SIZE=0 in Makefile should help?

@trufae
Copy link
Contributor

trufae commented Jan 20, 2025

Or by calling the api in the constructor at runtime. Thanks

@saghul
Copy link
Contributor

saghul commented Jan 20, 2025

Yep, you can do this:

#if __has_feature(address_sanitizer)
    JS_SetMaxStackSize(rt, 0);
#endif

Or you can play with it until you find the right value. It's 1MB by default.

@satk0
Copy link
Contributor Author

satk0 commented Jan 20, 2025

Nicee, thanks! Will let you know how it goes ;)

@trufae
Copy link
Contributor

trufae commented Jan 20, 2025

Solved here radareorg/radare2#23911 Thanks for clarifying

@saghul saghul closed this as completed Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants