summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChad Brubaker <cbrubaker@google.com>2015-07-17 13:43:24 -0700
committerChad Brubaker <cbrubaker@google.com>2015-07-17 13:48:31 -0700
commita9a17eeca2f5d9d3101a7e0bb136360697b6e2f0 (patch)
treeb88634f1053fb934737a551bcb6fe8122ffdd286
parent06114e6a1e1663c39b718224c4f326d844b15b98 (diff)
downloadandroid_system_security-a9a17eeca2f5d9d3101a7e0bb136360697b6e2f0.tar.gz
android_system_security-a9a17eeca2f5d9d3101a7e0bb136360697b6e2f0.tar.bz2
android_system_security-a9a17eeca2f5d9d3101a7e0bb136360697b6e2f0.zip
Mark 0 length files as corrupt
Files created by keystore should never be 0 length however a vendor ran into such a case when testing their keymaster and a side effect of how keystore parses files leads to these keys being considered encrypted and ulitmately undeletable. Now mark 0 length files as corrupt in readKey and when deleting a key if the key fails to read in because it was corrupt simply rm the file since it is not possible to feed the key blob to keymaster's delete method. Bug: 22561219 Change-Id: Ie8c1ffe97d1d89c202cdab7a6b4b5efc914cbbff
-rw-r--r--keystore/keystore.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/keystore/keystore.cpp b/keystore/keystore.cpp
index cb948fd..af2d301 100644
--- a/keystore/keystore.cpp
+++ b/keystore/keystore.cpp
@@ -669,6 +669,10 @@ public:
return SYSTEM_ERROR;
}
+ if (fileLength == 0) {
+ return VALUE_CORRUPTED;
+ }
+
if (isEncrypted() && (state != STATE_NO_ERROR)) {
return LOCKED;
}
@@ -1208,6 +1212,10 @@ public:
ResponseCode del(const char *filename, const BlobType type, uid_t userId) {
Blob keyBlob;
ResponseCode rc = get(filename, &keyBlob, type, userId);
+ if (rc == ::VALUE_CORRUPTED) {
+ // The file is corrupt, the best we can do is rm it.
+ return (unlink(filename) && errno != ENOENT) ? ::SYSTEM_ERROR : ::NO_ERROR;
+ }
if (rc != ::NO_ERROR) {
return rc;
}
@@ -1710,7 +1718,6 @@ public:
ResponseCode responseCode = mKeyStore->getKeyForName(&keyBlob, name8, callingUid,
TYPE_GENERIC);
if (responseCode != ::NO_ERROR) {
- ALOGW("Could not read %s", name8.string());
*item = NULL;
*itemLength = 0;
return responseCode;