Merge "Expose a function to reset the stack protector for the zygote." am: 1efa573832 am: 24509c663e

Original change: https://android-review.googlesource.com/c/platform/bionic/+/1424970

Change-Id: If9974850dc7e653079c60c30c36dfaf6d25af768
This commit is contained in:
Elliott Hughes 2020-09-11 21:17:18 +00:00 committed by Automerger Merge Worker
commit 803ae885b2
2 changed files with 15 additions and 5 deletions

View file

@ -101,6 +101,19 @@ void __init_tcb_dtv(bionic_tcb* tcb) {
__set_tcb_dtv(tcb, const_cast<TlsDtv*>(&zero_dtv));
}
// This is public so that the zygote can call it too. It is not expected
// to be useful otherwise.
//
// Note in particular that it is not possible to return from any existing
// stack frame with stack protector enabled after this function is called.
extern "C" void android_reset_stack_guards() {
// The TLS stack guard is set from the global, so ensure that we've initialized the global
// before we initialize the TLS. Dynamic executables will initialize their copy of the global
// stack protector from the one in the main thread's TLS.
__libc_safe_arc4random_buf(&__stack_chk_guard, sizeof(__stack_chk_guard));
__init_tcb_stack_guard(__get_bionic_tcb());
}
// Finish initializing the main thread.
__BIONIC_WEAK_FOR_NATIVE_BRIDGE
extern "C" void __libc_init_main_thread_late() {
@ -119,11 +132,7 @@ extern "C" void __libc_init_main_thread_late() {
// User code should never see this; we'll compute it when asked.
pthread_attr_setstacksize(&main_thread.attr, 0);
// The TLS stack guard is set from the global, so ensure that we've initialized the global
// before we initialize the TLS. Dynamic executables will initialize their copy of the global
// stack protector from the one in the main thread's TLS.
__libc_safe_arc4random_buf(&__stack_chk_guard, sizeof(__stack_chk_guard));
__init_tcb_stack_guard(__get_bionic_tcb());
android_reset_stack_guards();
__init_thread(&main_thread);

View file

@ -1770,4 +1770,5 @@ LIBC_PLATFORM {
android_net_res_stats_get_info_for_net;
android_net_res_stats_aggregate;
android_net_res_stats_get_usable_servers;
android_reset_stack_guards;
} LIBC_Q;