From 68b5b0056721217d70106c08b0b99384de18385f Mon Sep 17 00:00:00 2001 From: Edwin Wong Date: Mon, 19 Apr 2021 18:25:35 -0700 Subject: [PATCH] [RESTRICT AUTOMERGE] Fix potential decrypt destPtr overflow. sc-dev branch is missing this fix, it did not auto merge from http://ag/13617980 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: I88fff54de09d6753672b2a46c029960b5c30f5e7 --- libwvdrmengine/mediacrypto/src_hidl/WVCryptoPlugin.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libwvdrmengine/mediacrypto/src_hidl/WVCryptoPlugin.cpp b/libwvdrmengine/mediacrypto/src_hidl/WVCryptoPlugin.cpp index b105aea9..9f2520bc 100644 --- a/libwvdrmengine/mediacrypto/src_hidl/WVCryptoPlugin.cpp +++ b/libwvdrmengine/mediacrypto/src_hidl/WVCryptoPlugin.cpp @@ -233,7 +233,10 @@ Return WVCryptoPlugin::decrypt_1_2( 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_V1_2::ERROR_DRM_FRAME_TOO_LARGE, 0, "invalid buffer size"); return Void(); }