Remove password shards from memory

Force a garbage collection and zeroize some fields after Activity finishes

Test: Goes through password change flow, then grab a heap dump via
      adb shell 'am dumpheap $(pidof com.android.settings)
      /data/local/tmp/settings.hprof'
      And grep for password in the dump
Bug: 144537463
Change-Id: Idd0a04ada98900aeb2a6d20bb1270a4a4aec2cfd
This commit is contained in:
Rubin Xu
2020-06-11 22:45:35 +01:00
parent 21ac98e2f1
commit 670a30e766
5 changed files with 55 additions and 0 deletions

View File

@@ -821,6 +821,14 @@ public class ChooseLockGeneric extends SettingsActivity {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (mUserPassword != null) {
mUserPassword.zeroize();
}
// Force a garbage collection immediately to remove remnant of user password shards
// from memory.
System.gc();
System.runFinalization();
System.gc();
} }
@Override @Override

View File

@@ -530,6 +530,19 @@ public class ChooseLockPassword extends SettingsActivity {
} }
} }
@Override
public void onDestroy() {
super.onDestroy();
if (mCurrentCredential != null) {
mCurrentCredential.zeroize();
}
// Force a garbage collection immediately to remove remnant of user password shards
// from memory.
System.gc();
System.runFinalization();
System.gc();
}
protected int getStageType() { protected int getStageType() {
return mForFingerprint ? Stage.TYPE_FINGERPRINT : return mForFingerprint ? Stage.TYPE_FINGERPRINT :
mForFace ? Stage.TYPE_FACE : mForFace ? Stage.TYPE_FACE :

View File

@@ -617,6 +617,19 @@ public class ChooseLockPattern extends SettingsActivity {
} }
} }
@Override
public void onDestroy() {
super.onDestroy();
if (mCurrentCredential != null) {
mCurrentCredential.zeroize();
}
// Force a garbage collection immediately to remove remnant of user password shards
// from memory.
System.gc();
System.runFinalization();
System.gc();
}
protected Intent getRedactionInterstitialIntent(Context context) { protected Intent getRedactionInterstitialIntent(Context context) {
return RedactionInterstitial.createStartIntent(context, mUserId); return RedactionInterstitial.createStartIntent(context, mUserId);
} }

View File

@@ -157,6 +157,16 @@ public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivi
} }
} }
@Override
public void onDestroy() {
super.onDestroy();
// Force a garbage collection immediately to remove remnant of user password shards
// from memory.
System.gc();
System.runFinalization();
System.gc();
}
@Override @Override
public void finish() { public void finish() {
super.finish(); super.finish();

View File

@@ -217,6 +217,17 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
} }
} }
@Override
public void onDestroy() {
super.onDestroy();
mPasswordEntry.setText(null);
// Force a garbage collection immediately to remove remnant of user password shards
// from memory.
System.gc();
System.runFinalization();
System.gc();
}
private int getDefaultHeader() { private int getDefaultHeader() {
if (mFrp) { if (mFrp) {
return mIsAlpha ? R.string.lockpassword_confirm_your_password_header_frp return mIsAlpha ? R.string.lockpassword_confirm_your_password_header_frp