Merge "Pass MTE RuntimeFlags to AppZygote." into sc-v2-dev

This commit is contained in:
Evgenii Stepanov
2021-12-10 20:39:46 +00:00
committed by Android (Google) Code Review
2 changed files with 28 additions and 3 deletions

View File

@@ -45,6 +45,8 @@ public class AppZygote {
// Last UID/GID of the range the AppZygote can setuid()/setgid() to // Last UID/GID of the range the AppZygote can setuid()/setgid() to
private final int mZygoteUidGidMax; private final int mZygoteUidGidMax;
private final int mZygoteRuntimeFlags;
private final Object mLock = new Object(); private final Object mLock = new Object();
/** /**
@@ -56,11 +58,13 @@ public class AppZygote {
private final ApplicationInfo mAppInfo; private final ApplicationInfo mAppInfo;
public AppZygote(ApplicationInfo appInfo, int zygoteUid, int uidGidMin, int uidGidMax) { public AppZygote(ApplicationInfo appInfo, int zygoteUid, int uidGidMin, int uidGidMax,
int runtimeFlags) {
mAppInfo = appInfo; mAppInfo = appInfo;
mZygoteUid = zygoteUid; mZygoteUid = zygoteUid;
mZygoteUidGidMin = uidGidMin; mZygoteUidGidMin = uidGidMin;
mZygoteUidGidMax = uidGidMax; mZygoteUidGidMax = uidGidMax;
mZygoteRuntimeFlags = runtimeFlags;
} }
/** /**
@@ -110,7 +114,7 @@ public class AppZygote {
mZygoteUid, mZygoteUid,
mZygoteUid, mZygoteUid,
null, // gids null, // gids
0, // runtimeFlags mZygoteRuntimeFlags, // runtimeFlags
"app_zygote", // seInfo "app_zygote", // seInfo
abi, // abi abi, // abi
abi, // acceptedAbiList abi, // acceptedAbiList

View File

@@ -373,6 +373,16 @@ public final class ProcessList {
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
private static final long NATIVE_HEAP_POINTER_TAGGING = 135754954; // This is a bug id. private static final long NATIVE_HEAP_POINTER_TAGGING = 135754954; // This is a bug id.
/**
* Native heap allocations in AppZygote process and its descendants will now have a
* non-zero tag in the most significant byte.
* @see <a href="https://source.android.com/devices/tech/debug/tagged-pointers">Tagged
* Pointers</a>
*/
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.S)
private static final long NATIVE_HEAP_POINTER_TAGGING_APP_ZYGOTE = 207557677;
/** /**
* Enable asynchronous (ASYNC) memory tag checking in this process. This * Enable asynchronous (ASYNC) memory tag checking in this process. This
* flag will only have an effect on hardware supporting the ARM Memory * flag will only have an effect on hardware supporting the ARM Memory
@@ -1738,6 +1748,16 @@ public final class ProcessList {
return level; return level;
} }
private int decideTaggingLevelForAppZygote(ProcessRecord app) {
int level = decideTaggingLevel(app);
// TBI ("fake" pointer tagging) in AppZygote is controlled by a separate compat feature.
if (!mPlatformCompat.isChangeEnabled(NATIVE_HEAP_POINTER_TAGGING_APP_ZYGOTE, app.info)
&& level == Zygote.MEMORY_TAG_LEVEL_TBI) {
level = Zygote.MEMORY_TAG_LEVEL_NONE;
}
return level;
}
private int decideGwpAsanLevel(ProcessRecord app) { private int decideGwpAsanLevel(ProcessRecord app) {
// Look at the process attribute first. // Look at the process attribute first.
if (app.processInfo != null if (app.processInfo != null
@@ -2238,7 +2258,8 @@ public final class ProcessList {
// not the calling one. // not the calling one.
appInfo.packageName = app.getHostingRecord().getDefiningPackageName(); appInfo.packageName = app.getHostingRecord().getDefiningPackageName();
appInfo.uid = uid; appInfo.uid = uid;
appZygote = new AppZygote(appInfo, uid, firstUid, lastUid); int runtimeFlags = decideTaggingLevelForAppZygote(app);
appZygote = new AppZygote(appInfo, uid, firstUid, lastUid, runtimeFlags);
mAppZygotes.put(app.info.processName, uid, appZygote); mAppZygotes.put(app.info.processName, uid, appZygote);
zygoteProcessList = new ArrayList<ProcessRecord>(); zygoteProcessList = new ArrayList<ProcessRecord>();
mAppZygoteProcesses.put(appZygote, zygoteProcessList); mAppZygoteProcesses.put(appZygote, zygoteProcessList);