Fix dump() without ACCESS_KEYGUARD_SECURE_STORAGE

The only permission that LockSettingsService#dump() is meant to require
is DUMP.  As per the usual practice, the Binder calling identity should
be cleared after the permission check so that unwanted permission checks
don't happen deeper in the call stack.

This fixes commit b0bcbce79c ("Lock down the ability to read from the
locksettings database") (http://ag/21025749), which had unintentionally
made dump() start requiring ACCESS_KEYGUARD_SECURE_STORAGE.  The error
message received was the following:

    Security exception: uid=2000 needs permission android.permission.ACCESS_KEYGUARD_SECURE_STORAGE to read sp-handle for user 0

Bug: 256170784
Test: adb shell dumpsys lock_settings  # without adb root
Change-Id: Ie5e75e925dd4ffdda0cda3c3a58a6503ba44f54c
This commit is contained in:
Eric Biggers
2023-03-06 18:25:07 +00:00
parent aeba685393
commit 3766125b0b

View File

@@ -3101,6 +3101,16 @@ public class LockSettingsService extends ILockSettings.Stub {
@Override
protected void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, printWriter)) return;
final long identity = Binder.clearCallingIdentity();
try {
dumpInternal(printWriter);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
private void dumpInternal(PrintWriter printWriter) {
IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
pw.println("Current lock settings service state:");