summaryrefslogtreecommitdiff
path: root/drm/1.0/default/CryptoPlugin.cpp
diff options
context:
space:
mode:
authorEdwin Wong <edwinwong@google.com>2021-03-08 18:46:42 -0800
committerEdwin Wong <edwinwong@google.com>2021-04-01 10:13:31 -0700
commit989975ec5a2a9284d13b6b5e76d34bc7c214673e (patch)
treea1958611163fc76b837d0ea8612b60367cc262f0 /drm/1.0/default/CryptoPlugin.cpp
parent9b0b0b83ae0f9ac682dcaf1a37c586485d773db0 (diff)
Fix CryptoPlugin use after free vulnerability.
The shared memory buffer used by srcPtr can be freed by another thread because it is not protected by a mutex. Subsequently, a use after free AIGABRT can occur in a race condition. SafetyNet logging is not added to avoid log spamming. The mutex lock is called to setup for decryption, which is called frequently. The crash was reproduced on the device before the fix. Verified the test passes after the fix. Test: sts sts-tradefed run sts-engbuild-no-spl-lock -m StsHostTestCases --test android.security.sts.Bug_176495665#testPocBug_176495665 Test: push to device with target_hwasan-userdebug build adb shell /data/local/tmp/Bug-176495665_sts64 Bug: 176495665 Bug: 176444161 Change-Id: I4c83c44873eef960b654f387a3574fcad49c41a9
Diffstat (limited to 'drm/1.0/default/CryptoPlugin.cpp')
-rw-r--r--drm/1.0/default/CryptoPlugin.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/drm/1.0/default/CryptoPlugin.cpp b/drm/1.0/default/CryptoPlugin.cpp
index e6d4e8447b..de8bbd599c 100644
--- a/drm/1.0/default/CryptoPlugin.cpp
+++ b/drm/1.0/default/CryptoPlugin.cpp
@@ -53,6 +53,8 @@ namespace implementation {
uint32_t bufferId) {
sp<IMemory> hidlMemory = mapMemory(base);
+ std::lock_guard<std::mutex> shared_buffer_lock(mSharedBufferLock);
+
// allow mapMemory to return nullptr
mSharedBufferMap[bufferId] = hidlMemory;
return Void();
@@ -65,7 +67,7 @@ namespace implementation {
const SharedBuffer& source, uint64_t offset,
const DestinationBuffer& destination,
decrypt_cb _hidl_cb) {
-
+ std::unique_lock<std::mutex> shared_buffer_lock(mSharedBufferLock);
if (mSharedBufferMap.find(source.bufferId) == mSharedBufferMap.end()) {
_hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "source decrypt buffer base not set");
return Void();
@@ -79,7 +81,7 @@ namespace implementation {
}
}
- android::CryptoPlugin::Mode legacyMode;
+ android::CryptoPlugin::Mode legacyMode = android::CryptoPlugin::kMode_Unencrypted;
switch(mode) {
case Mode::UNENCRYPTED:
legacyMode = android::CryptoPlugin::kMode_Unencrypted;
@@ -170,6 +172,10 @@ namespace implementation {
_hidl_cb(Status::BAD_VALUE, 0, "invalid destination type");
return Void();
}
+
+ // release mSharedBufferLock
+ shared_buffer_lock.unlock();
+
ssize_t result = mLegacyPlugin->decrypt(secure, keyId.data(), iv.data(),
legacyMode, legacyPattern, srcPtr, legacySubSamples.get(),
subSamples.size(), destPtr, &detailMessage);