Skip to content

Commit 54a72fd

Browse files
committed
core: Harden DeadSystem paths for optional services
Some devices legitimately ship without persistent data block / OEM lock, and those services can also be transiently absent while system_server is still coming up or already tearing down. Treating them like mandatory services routes lookups through onServiceNotFound() and emits extra WTF noise right in the same DeadSystem failure paths we are trying to contain. ActivityManagerService also should not assume DropBox remains usable once the system is already failing, and LockSettingsStorage should quietly skip FRP helpers when the persistent data block service is absent instead of turning that into another fatal-looking report. Use nullable lookups for the optional services, whitelist them in getSystemService(), and wrap DropBox queries/writes so these reporting paths fail closed instead of recursively amplifying the original failure. Signed-off-by: Quince <quinceroms@gmail.com>
1 parent 06898a0 commit 54a72fd

3 files changed

Lines changed: 39 additions & 21 deletions

File tree

core/java/android/app/SystemServiceRegistry.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,10 @@ public UsageStatsManager createService(ContextImpl ctx) throws ServiceNotFoundEx
12181218
new StaticServiceFetcher<PersistentDataBlockManager>() {
12191219
@Override
12201220
public PersistentDataBlockManager createService() throws ServiceNotFoundException {
1221-
IBinder b = ServiceManager.getServiceOrThrow(Context.PERSISTENT_DATA_BLOCK_SERVICE);
1221+
IBinder b = ServiceManager.getService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
1222+
if (b == null) {
1223+
return null;
1224+
}
12221225
IPersistentDataBlockService persistentDataBlockService =
12231226
IPersistentDataBlockService.Stub.asInterface(b);
12241227
if (persistentDataBlockService != null) {
@@ -1234,7 +1237,10 @@ public PersistentDataBlockManager createService() throws ServiceNotFoundExceptio
12341237
new StaticServiceFetcher<OemLockManager>() {
12351238
@Override
12361239
public OemLockManager createService() throws ServiceNotFoundException {
1237-
IBinder b = ServiceManager.getServiceOrThrow(Context.OEM_LOCK_SERVICE);
1240+
IBinder b = ServiceManager.getService(Context.OEM_LOCK_SERVICE);
1241+
if (b == null) {
1242+
return null;
1243+
}
12381244
IOemLockService oemLockService = IOemLockService.Stub.asInterface(b);
12391245
if (oemLockService != null) {
12401246
return new OemLockManager(oemLockService);
@@ -2113,6 +2119,8 @@ public static Object getSystemService(@NonNull ContextImpl ctx, String name) {
21132119
case Context.VIRTUALIZATION_SERVICE:
21142120
case Context.VIRTUAL_DEVICE_SERVICE:
21152121
case Context.DROPBOX_SERVICE:
2122+
case Context.PERSISTENT_DATA_BLOCK_SERVICE:
2123+
case Context.OEM_LOCK_SERVICE:
21162124
return null;
21172125
case Context.VCN_MANAGEMENT_SERVICE:
21182126
if (!hasSystemFeatureOpportunistic(ctx,

services/core/java/com/android/server/am/ActivityManagerService.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9585,7 +9585,7 @@ private void logStrictModeViolationToDropBox(
95859585

95869586
// Exit early if the dropbox isn't configured to accept this report type.
95879587
final String dropboxTag = processClass(process) + "_strictmode";
9588-
if (dbox == null || !dbox.isTagEnabled(dropboxTag)) return;
9588+
if (!isDropBoxTagEnabled(dbox, dropboxTag)) return;
95899589

95909590
final StringBuilder sb = new StringBuilder(1024);
95919591
synchronized (sb) {
@@ -9626,10 +9626,30 @@ private void logStrictModeViolationToDropBox(
96269626

96279627
final String res = sb.toString();
96289628
IoThread.getHandler().post(() -> {
9629-
dbox.addText(dropboxTag, res);
9629+
addTextToDropBox(dbox, dropboxTag, res);
96309630
});
96319631
}
96329632

9633+
private boolean isDropBoxTagEnabled(DropBoxManager dbox, String dropboxTag) {
9634+
if (dbox == null) {
9635+
return false;
9636+
}
9637+
try {
9638+
return dbox.isTagEnabled(dropboxTag);
9639+
} catch (RuntimeException e) {
9640+
Slog.w(TAG, "Unable to query DropBox tag " + dropboxTag, e);
9641+
return false;
9642+
}
9643+
}
9644+
9645+
private void addTextToDropBox(DropBoxManager dbox, String dropboxTag, String data) {
9646+
try {
9647+
dbox.addText(dropboxTag, data);
9648+
} catch (RuntimeException e) {
9649+
Slog.w(TAG, "Unable to write DropBox entry " + dropboxTag, e);
9650+
}
9651+
}
9652+
96339653
/**
96349654
* Used by {@link Log} via {@link com.android.internal.os.RuntimeInit} to report serious errors.
96359655
* @param app object of the crashing app, null for the system server
@@ -9900,7 +9920,7 @@ public void addErrorToDropBox(String eventType,
99009920

99019921
// Exit early if the dropbox isn't configured to accept this report type.
99029922
final String dropboxTag = processClass(process) + "_" + eventType;
9903-
if (dbox == null || !dbox.isTagEnabled(dropboxTag)) return;
9923+
if (!isDropBoxTagEnabled(dbox, dropboxTag)) return;
99049924

99059925
if (dropboxTag.equals("system_server_crash") && Binder.getCallingPid() != Process.myPid()) {
99069926
// processClass(process) above returns "system_server" when process is null, which
@@ -10063,7 +10083,7 @@ public void run() {
1006310083
}
1006410084
}
1006510085

10066-
dbox.addText(dropboxTag, sb.toString());
10086+
addTextToDropBox(dbox, dropboxTag, sb.toString());
1006710087
}
1006810088
};
1006910089

services/core/java/com/android/server/locksettings/LockSettingsStorage.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -624,27 +624,17 @@ public PersistentData readPersistentDataBlock() {
624624

625625
public void deactivateFactoryResetProtectionWithoutSecret() {
626626
PersistentDataBlockManagerInternal persistentDataBlock = getPersistentDataBlockManager();
627-
if (persistentDataBlock != null) {
628-
persistentDataBlock.deactivateFactoryResetProtectionWithoutSecret();
629-
} else {
630-
Slog.wtf(TAG, "Failed to get PersistentDataBlockManagerInternal");
627+
if (persistentDataBlock == null) {
628+
return;
631629
}
630+
persistentDataBlock.deactivateFactoryResetProtectionWithoutSecret();
632631
}
633632

634633
public boolean isFactoryResetProtectionActive() {
635634
PersistentDataBlockManager persistentDataBlockManager =
636635
mContext.getSystemService(PersistentDataBlockManager.class);
637-
if (persistentDataBlockManager != null) {
638-
return persistentDataBlockManager.isFactoryResetProtectionActive();
639-
} else {
640-
Slog.wtf(TAG, "Failed to get PersistentDataBlockManager");
641-
// This should never happen, but in the event it does, let's not block the user. This
642-
// may be the wrong call, since if an attacker can find a way to prevent us from
643-
// getting the PersistentDataBlockManager they can defeat FRP, but if they can block
644-
// access to PersistentDataBlockManager they must have compromised the system and we've
645-
// probably already lost this battle.
646-
return false;
647-
}
636+
return persistentDataBlockManager != null
637+
&& persistentDataBlockManager.isFactoryResetProtectionActive();
648638
}
649639

650640
/**

0 commit comments

Comments
 (0)