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

hard_rss_limit_mb broken on Android O #981

Closed
eugenis opened this issue Jun 28, 2018 · 2 comments
Closed

hard_rss_limit_mb broken on Android O #981

eugenis opened this issue Jun 28, 2018 · 2 comments

Comments

@eugenis
Copy link
Contributor

eugenis commented Jun 28, 2018

tl;dr we spawn a background thread before the global stack cookie is initialized.

Libc has at least two constructors there, and it initializes the stack protector cookie in the second one.

First happens this:
#12 0xf6ff8ed8 in AsanInitInternal () at /code/llvm-project/compiler-rt/lib/asan/asan_rtl.cc:454
#13 0xf6fb5124 in pthread_mutex_lock ()
at /code/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:3801
#14 0xf6f034ca in jemalloc_constructor () from target:/system/lib/libc.so
#15 0xf772959a in _dl__ZL13call_functionPKcPFviPPcS2_ES0 () from target:/system/bin/linker

AsanInitInternal spawns the background thread.

Then this:
#0 0xf6f0e550 in __libc_preinit() () from target:/system/lib/libc.so
#1 0xf772959a in _dl__ZL13call_functionPKcPFviPPcS2_ES0 () from target:/system/bin/linker

That's where the stackprotector cookie is set. Our background thread, meanwhile, is waiting in
#0 0xf75c14f8 in usleep () from target:/system/lib/libc.so
#1 0xf6dec05c in BackgroundThread () at /code/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc:100

and fails the stack cookie check when leaving usleep().

Apparently, we can not create new threads in pthread_mutex_lock interceptor, or they would race with the initialization of the cookie.

I don't think this is a bug in bionic, because user code, normally, is not supposed to run that early.
Perhaps we could delay thread creation somehow?

dtzWill pushed a commit to llvm-mirror/compiler-rt that referenced this issue Jun 28, 2018
@eugenis
Copy link
Contributor Author

eugenis commented Dec 28, 2018

This does not reproduce on the current master branch of Android.

@eugenis
Copy link
Contributor Author

eugenis commented Dec 28, 2018

And the reason is: at some pointer stack protector cookie initialization has been moved to an earlier stage in __linker_init_post_relocation.

@eugenis eugenis closed this as completed Dec 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant