Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c8ed235 authored by Mitch Phillips's avatar Mitch Phillips Committed by Automerger Merge Worker
Browse files

Merge "Add explicit handling for an unspecified gwpAsanMode manifest flag." am: 95e227bf

parents 8b8a0a5f 95e227bf
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -178,7 +178,14 @@ public final class Zygote {
     * GWP-ASan is activated unconditionally (but still, only a small subset of
     * allocations is protected).
     */
    public static final int GWP_ASAN_LEVEL_ALWAYS = 1 << 22;
    public static final int GWP_ASAN_LEVEL_ALWAYS = 2 << 21;

    /**
     * GWP-ASan's `gwpAsanMode` manifest flag was unspecified. Currently, this
     * means GWP_ASAN_LEVEL_LOTTERY for system apps, and GWP_ASAN_LEVEL_NONE for
     * non-system apps.
     */
    public static final int GWP_ASAN_LEVEL_DEFAULT = 3 << 21;

    /** Enable automatic zero-initialization of native heap memory allocations. */
    public static final int NATIVE_HEAP_ZERO_INIT_ENABLED = 1 << 23;
@@ -1347,15 +1354,13 @@ public final class Zygote {
                    ? GWP_ASAN_LEVEL_ALWAYS
                    : GWP_ASAN_LEVEL_NEVER;
        }
        // If the app does not specify gwpAsanMode, the default behavior is lottery among the
        // system apps, and disabled for user apps, unless overwritten by the compat feature.
        if (isCompatChangeEnabled(GWP_ASAN, info, platformCompat, 0)) {
            return GWP_ASAN_LEVEL_ALWAYS;
        }
        if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            return GWP_ASAN_LEVEL_LOTTERY;
        }
        return GWP_ASAN_LEVEL_NEVER;
        return GWP_ASAN_LEVEL_DEFAULT;
    }

    private static boolean enableNativeHeapZeroInit(
+8 −0
Original line number Diff line number Diff line
@@ -353,6 +353,7 @@ enum RuntimeFlags : uint32_t {
    GWP_ASAN_LEVEL_NEVER = 0 << 21,
    GWP_ASAN_LEVEL_LOTTERY = 1 << 21,
    GWP_ASAN_LEVEL_ALWAYS = 2 << 21,
    GWP_ASAN_LEVEL_DEFAULT = 3 << 21,
    NATIVE_HEAP_ZERO_INIT_ENABLED = 1 << 23,
    PROFILEABLE = 1 << 24,
};
@@ -1932,6 +1933,13 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids,
    gwp_asan_options.program_name = nice_name_ptr ?: process_name;
    switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) {
        default:
        case RuntimeFlags::GWP_ASAN_LEVEL_DEFAULT:
            // TODO(b/247012630): Switch this to Action::TURN_ON_FOR_APP_SAMPLED_NON_CRASHING once
            // performance and syshealth testing is completed, making the default for non-system
            // apps that don't specify a `gwpAsanMode` in their manifest to be sampled-recoverable.
            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_NEVER:
            gwp_asan_options.desire = Action::DONT_TURN_ON_UNLESS_OVERRIDDEN;
            android_mallopt(M_INITIALIZE_GWP_ASAN, &gwp_asan_options, sizeof(gwp_asan_options));