Loading core/jni/com_android_internal_os_Zygote.cpp +14 −5 Original line number Diff line number Diff line Loading @@ -110,6 +110,8 @@ using android::base::GetBoolProperty; using android::zygote::ZygoteFailure; using Action = android_mallopt_gwp_asan_options_t::Action; // This type is duplicated in fd_utils.h typedef const std::function<void(std::string)>& fail_fn_t; Loading Loading @@ -1717,16 +1719,24 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, // runtime. runtime_flags &= ~RuntimeFlags::NATIVE_HEAP_ZERO_INIT; bool forceEnableGwpAsan = false; const char* nice_name_ptr = nice_name.has_value() ? nice_name.value().c_str() : nullptr; android_mallopt_gwp_asan_options_t gwp_asan_options; // The system server doesn't have its nice name set by the time SpecializeCommon is called. gwp_asan_options.program_name = nice_name_ptr ?: process_name; switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) { default: case RuntimeFlags::GWP_ASAN_LEVEL_NEVER: gwp_asan_options.desire = Action::DONT_TURN_ON_UNLESS_OVERRIDDEN; android_mallopt(M_INITIALIZE_GWP_ASAN, &gwp_asan_options, sizeof(gwp_asan_options)); break; case RuntimeFlags::GWP_ASAN_LEVEL_ALWAYS: forceEnableGwpAsan = true; [[fallthrough]]; gwp_asan_options.desire = Action::TURN_ON_FOR_APP; android_mallopt(M_INITIALIZE_GWP_ASAN, &gwp_asan_options, sizeof(gwp_asan_options)); break; case RuntimeFlags::GWP_ASAN_LEVEL_LOTTERY: android_mallopt(M_INITIALIZE_GWP_ASAN, &forceEnableGwpAsan, sizeof(forceEnableGwpAsan)); gwp_asan_options.desire = Action::TURN_ON_WITH_SAMPLING; android_mallopt(M_INITIALIZE_GWP_ASAN, &gwp_asan_options, sizeof(gwp_asan_options)); break; } // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART // runtime. Loading @@ -1739,7 +1749,6 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, AStatsSocket_close(); const char* se_info_ptr = se_info.has_value() ? se_info.value().c_str() : nullptr; const char* nice_name_ptr = nice_name.has_value() ? nice_name.value().c_str() : nullptr; if (selinux_android_setcontext(uid, is_system_server, se_info_ptr, nice_name_ptr) == -1) { fail_fn(CREATE_ERROR("selinux_android_setcontext(%d, %d, \"%s\", \"%s\") failed", uid, Loading Loading
core/jni/com_android_internal_os_Zygote.cpp +14 −5 Original line number Diff line number Diff line Loading @@ -110,6 +110,8 @@ using android::base::GetBoolProperty; using android::zygote::ZygoteFailure; using Action = android_mallopt_gwp_asan_options_t::Action; // This type is duplicated in fd_utils.h typedef const std::function<void(std::string)>& fail_fn_t; Loading Loading @@ -1717,16 +1719,24 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, // runtime. runtime_flags &= ~RuntimeFlags::NATIVE_HEAP_ZERO_INIT; bool forceEnableGwpAsan = false; const char* nice_name_ptr = nice_name.has_value() ? nice_name.value().c_str() : nullptr; android_mallopt_gwp_asan_options_t gwp_asan_options; // The system server doesn't have its nice name set by the time SpecializeCommon is called. gwp_asan_options.program_name = nice_name_ptr ?: process_name; switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) { default: case RuntimeFlags::GWP_ASAN_LEVEL_NEVER: gwp_asan_options.desire = Action::DONT_TURN_ON_UNLESS_OVERRIDDEN; android_mallopt(M_INITIALIZE_GWP_ASAN, &gwp_asan_options, sizeof(gwp_asan_options)); break; case RuntimeFlags::GWP_ASAN_LEVEL_ALWAYS: forceEnableGwpAsan = true; [[fallthrough]]; gwp_asan_options.desire = Action::TURN_ON_FOR_APP; android_mallopt(M_INITIALIZE_GWP_ASAN, &gwp_asan_options, sizeof(gwp_asan_options)); break; case RuntimeFlags::GWP_ASAN_LEVEL_LOTTERY: android_mallopt(M_INITIALIZE_GWP_ASAN, &forceEnableGwpAsan, sizeof(forceEnableGwpAsan)); gwp_asan_options.desire = Action::TURN_ON_WITH_SAMPLING; android_mallopt(M_INITIALIZE_GWP_ASAN, &gwp_asan_options, sizeof(gwp_asan_options)); break; } // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART // runtime. Loading @@ -1739,7 +1749,6 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, AStatsSocket_close(); const char* se_info_ptr = se_info.has_value() ? se_info.value().c_str() : nullptr; const char* nice_name_ptr = nice_name.has_value() ? nice_name.value().c_str() : nullptr; if (selinux_android_setcontext(uid, is_system_server, se_info_ptr, nice_name_ptr) == -1) { fail_fn(CREATE_ERROR("selinux_android_setcontext(%d, %d, \"%s\", \"%s\") failed", uid, Loading