diff options
author | Alex Klyubin <klyubin@google.com> | 2015-06-23 22:40:32 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-06-23 22:40:33 +0000 |
commit | b913aa5774c96fae83afe3dd1935394f0edcaaa9 (patch) | |
tree | 0fcff2c3faef900d8ba5377a3b106e4e4a3aa627 | |
parent | 4e88f9be2b3bb3dcea43f338532882681ee77352 (diff) | |
parent | 700c1a35c52798831b8a8d76a042c4650c6d793f (diff) | |
download | android_system_security-b913aa5774c96fae83afe3dd1935394f0edcaaa9.tar.gz android_system_security-b913aa5774c96fae83afe3dd1935394f0edcaaa9.tar.bz2 android_system_security-b913aa5774c96fae83afe3dd1935394f0edcaaa9.zip |
Merge "Abort operation pruning only if it fails to make space." into mnc-dev
-rw-r--r-- | keystore/keystore.cpp | 11 | ||||
-rw-r--r-- | keystore/operation.cpp | 6 | ||||
-rw-r--r-- | keystore/operation.h | 3 |
3 files changed, 17 insertions, 3 deletions
diff --git a/keystore/keystore.cpp b/keystore/keystore.cpp index 85289ad..cb948fd 100644 --- a/keystore/keystore.cpp +++ b/keystore/keystore.cpp @@ -2507,7 +2507,16 @@ public: while (err == KM_ERROR_TOO_MANY_OPERATIONS && mOperationMap.hasPruneableOperation()) { sp<IBinder> oldest = mOperationMap.getOldestPruneableOperation(); ALOGD("Ran out of operation handles, trying to prune %p", oldest.get()); - if (abort(oldest) != ::NO_ERROR) { + + // We mostly ignore errors from abort() below because all we care about is whether at + // least one pruneable operation has been removed. + size_t op_count_before = mOperationMap.getPruneableOperationCount(); + int abort_error = abort(oldest); + size_t op_count_after = mOperationMap.getPruneableOperationCount(); + if (op_count_after >= op_count_before) { + // Failed to create space for a new operation. Bail to avoid an infinite loop. + ALOGE("Failed to remove pruneable operation %p, error: %d", + oldest.get(), abort_error); break; } err = dev->begin(dev, purpose, &key, &inParams, &outParams, &handle); diff --git a/keystore/operation.cpp b/keystore/operation.cpp index aa37101..4a71922 100644 --- a/keystore/operation.cpp +++ b/keystore/operation.cpp @@ -103,10 +103,14 @@ void OperationMap::removeOperationTracking(sp<IBinder> token, sp<IBinder> appTok } } -bool OperationMap::hasPruneableOperation() { +bool OperationMap::hasPruneableOperation() const { return mLru.size() != 0; } +size_t OperationMap::getPruneableOperationCount() const { + return mLru.size(); +} + sp<IBinder> OperationMap::getOldestPruneableOperation() { if (!hasPruneableOperation()) { return sp<IBinder>(NULL); diff --git a/keystore/operation.h b/keystore/operation.h index 6806388..01c4dbe 100644 --- a/keystore/operation.h +++ b/keystore/operation.h @@ -56,7 +56,8 @@ public: const keymaster1_device_t** outDev, const keymaster_key_characteristics_t** outCharacteristics); bool removeOperation(sp<IBinder> token); - bool hasPruneableOperation(); + bool hasPruneableOperation() const; + size_t getPruneableOperationCount() const; bool getOperationAuthToken(sp<IBinder> token, const hw_auth_token_t** outToken); bool setOperationAuthToken(sp<IBinder> token, const hw_auth_token_t* authToken); sp<IBinder> getOldestPruneableOperation(); |