[RESTRICT AUTOMERGE] Fix potential decrypt destPtr overflow.

There is a potential integer overflow to bypass the
destination base size check in decrypt. The destPtr
can then point to the outside of the destination buffer.

Test: sts-tradefed
  sts-tradefed run sts-engbuild-no-spl-lock -m StsHostTestCases --test android.security.sts.Bug_176444622#testPocBug_176444622

Test: push to device with target_hwasan-userdebug build
  adb shell /data/local/tmp/Bug-17644462264

Bug: 176444622
Bug: 176496353
Change-Id: Ic511871dfa3ddf7e66e94f7d58c4c9558add09a2
This commit is contained in:
Edwin Wong
2021-02-02 12:55:27 -08:00
parent 0253cb580e
commit 1bd967f9a8

View File

@@ -171,7 +171,10 @@ Return<void> WVCryptoPlugin::decrypt(
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, "176444622");
_hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
return Void();
}