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

Commit 8f357de6 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."...

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

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2405114



Change-Id: Id8b475b54c3dbe55e5de55ca6e8e2c2673503748
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 89cdadb6 8799b64d
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line 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
     * GWP-ASan is activated unconditionally (but still, only a small subset of
     * allocations is protected).
     * 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. */
    /** Enable automatic zero-initialization of native heap memory allocations. */
    public static final int NATIVE_HEAP_ZERO_INIT_ENABLED = 1 << 23;
    public static final int NATIVE_HEAP_ZERO_INIT_ENABLED = 1 << 23;
@@ -1356,15 +1363,13 @@ public final class Zygote {
                    ? GWP_ASAN_LEVEL_ALWAYS
                    ? GWP_ASAN_LEVEL_ALWAYS
                    : GWP_ASAN_LEVEL_NEVER;
                    : 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)) {
        if (isCompatChangeEnabled(GWP_ASAN, info, platformCompat, 0)) {
            return GWP_ASAN_LEVEL_ALWAYS;
            return GWP_ASAN_LEVEL_ALWAYS;
        }
        }
        if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
        if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            return GWP_ASAN_LEVEL_LOTTERY;
            return GWP_ASAN_LEVEL_LOTTERY;
        }
        }
        return GWP_ASAN_LEVEL_NEVER;
        return GWP_ASAN_LEVEL_DEFAULT;
    }
    }


    private static boolean enableNativeHeapZeroInit(
    private static boolean enableNativeHeapZeroInit(
+8 −0
Original line number Original line Diff line number Diff line
@@ -353,6 +353,7 @@ enum RuntimeFlags : uint32_t {
    GWP_ASAN_LEVEL_NEVER = 0 << 21,
    GWP_ASAN_LEVEL_NEVER = 0 << 21,
    GWP_ASAN_LEVEL_LOTTERY = 1 << 21,
    GWP_ASAN_LEVEL_LOTTERY = 1 << 21,
    GWP_ASAN_LEVEL_ALWAYS = 2 << 21,
    GWP_ASAN_LEVEL_ALWAYS = 2 << 21,
    GWP_ASAN_LEVEL_DEFAULT = 3 << 21,
    NATIVE_HEAP_ZERO_INIT_ENABLED = 1 << 23,
    NATIVE_HEAP_ZERO_INIT_ENABLED = 1 << 23,
    PROFILEABLE = 1 << 24,
    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;
    gwp_asan_options.program_name = nice_name_ptr ?: process_name;
    switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) {
    switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) {
        default:
        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:
        case RuntimeFlags::GWP_ASAN_LEVEL_NEVER:
            gwp_asan_options.desire = Action::DONT_TURN_ON_UNLESS_OVERRIDDEN;
            gwp_asan_options.desire = Action::DONT_TURN_ON_UNLESS_OVERRIDDEN;
            android_mallopt(M_INITIALIZE_GWP_ASAN, &gwp_asan_options, sizeof(gwp_asan_options));
            android_mallopt(M_INITIALIZE_GWP_ASAN, &gwp_asan_options, sizeof(gwp_asan_options));