summaryrefslogtreecommitdiffstats
path: root/drm
diff options
context:
space:
mode:
authorRobert Shih <robertshih@google.com>2019-09-11 14:10:14 -0700
committerRobert Shih <robertshih@google.com>2019-09-11 22:08:19 +0000
commit1e18883b72351531e4a11df49fffc0454e9108b8 (patch)
tree9bbc732cd787a8e24229aa2f772dafc0af094997 /drm
parent222d825ea05ede89a36d2db5ac7dfc11d28b2cf6 (diff)
downloadandroid_hardware_interfaces-1e18883b72351531e4a11df49fffc0454e9108b8.tar.gz
android_hardware_interfaces-1e18883b72351531e4a11df49fffc0454e9108b8.tar.bz2
android_hardware_interfaces-1e18883b72351531e4a11df49fffc0454e9108b8.zip
default hidl CryptoPlugin: security fixes
* reject native handle output for clearkey * validate subsample sizes Bug: 137370777 Test: cryptopoc Change-Id: Idf075e1a297fe1ab3ea3e1621806dd46b4a51e35
Diffstat (limited to 'drm')
-rw-r--r--drm/1.0/default/CryptoPlugin.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/drm/1.0/default/CryptoPlugin.cpp b/drm/1.0/default/CryptoPlugin.cpp
index f9c868db8..4fe6c9b43 100644
--- a/drm/1.0/default/CryptoPlugin.cpp
+++ b/drm/1.0/default/CryptoPlugin.cpp
@@ -102,11 +102,20 @@ namespace implementation {
std::unique_ptr<android::CryptoPlugin::SubSample[]> legacySubSamples =
std::make_unique<android::CryptoPlugin::SubSample[]>(subSamples.size());
+ size_t destSize = 0;
for (size_t i = 0; i < subSamples.size(); i++) {
- legacySubSamples[i].mNumBytesOfClearData
- = subSamples[i].numBytesOfClearData;
- legacySubSamples[i].mNumBytesOfEncryptedData
- = subSamples[i].numBytesOfEncryptedData;
+ uint32_t numBytesOfClearData = subSamples[i].numBytesOfClearData;
+ legacySubSamples[i].mNumBytesOfClearData = numBytesOfClearData;
+ uint32_t numBytesOfEncryptedData = subSamples[i].numBytesOfEncryptedData;
+ legacySubSamples[i].mNumBytesOfEncryptedData = numBytesOfEncryptedData;
+ if (__builtin_add_overflow(destSize, numBytesOfClearData, &destSize)) {
+ _hidl_cb(Status::BAD_VALUE, 0, "subsample clear size overflow");
+ return Void();
+ }
+ if (__builtin_add_overflow(destSize, numBytesOfEncryptedData, &destSize)) {
+ _hidl_cb(Status::BAD_VALUE, 0, "subsample encrypted size overflow");
+ return Void();
+ }
}
AString detailMessage;
@@ -138,11 +147,24 @@ namespace implementation {
_hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
return Void();
}
+
+ if (destSize > destBuffer.size) {
+ _hidl_cb(Status::BAD_VALUE, 0, "subsample sum too large");
+ return Void();
+ }
+
destPtr = static_cast<void *>(base + destination.nonsecureMemory.offset);
} else if (destination.type == BufferType::NATIVE_HANDLE) {
+ if (!secure) {
+ _hidl_cb(Status::BAD_VALUE, 0, "native handle destination must be secure");
+ return Void();
+ }
native_handle_t *handle = const_cast<native_handle_t *>(
destination.secureMemory.getNativeHandle());
destPtr = static_cast<void *>(handle);
+ } else {
+ _hidl_cb(Status::BAD_VALUE, 0, "invalid destination type");
+ return Void();
}
ssize_t result = mLegacyPlugin->decrypt(secure, keyId.data(), iv.data(),
legacyMode, legacyPattern, srcPtr, legacySubSamples.get(),