Merge "[RESTRICT AUTOMERGE] Fix potential decrypt destPtr overflow." into pi-dev

This commit is contained in:
Edwin Wong 2021-03-10 19:00:01 +00:00 committed by Android (Google) Code Review
commit 0dc3f03835

View file

@ -80,7 +80,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;
@ -147,7 +147,10 @@ namespace implementation {
return Void();
}
if (destBuffer.offset + destBuffer.size > destBase->getSize()) {
size_t totalDstSize = 0;
if (__builtin_add_overflow(destBuffer.offset, destBuffer.size, &totalDstSize) ||
totalDstSize > destBase->getSize()) {
android_errorWriteLog(0x534e4554, "176496353");
_hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
return Void();
}
@ -158,7 +161,7 @@ namespace implementation {
}
base = static_cast<uint8_t *>(static_cast<void *>(destBase->getPointer()));
destPtr = static_cast<void *>(base + destination.nonsecureMemory.offset);
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");