CVE-2026-58857 AI-generated analysis
platform/frameworks/av, drm/libmediadrm (CryptoHal AIDL and HIDL wrappers)
Reworks CryptoHalAidl::decrypt and CryptoHalHidl::decrypt (and CryptoHalAidl::getKeyHandle on Android 17) in libmediadrm so the plugin pointer is copied into a local strong reference while mLock is held, the Autolock is explicitly scoped instead of manually unlocked, and the HAL IPC is dispatched on the local reference with a null check.
Root cause
In CryptoHalAidl::decrypt and CryptoHalHidl::decrypt, a Mutex::Autolock on mLock was taken at function entry, the input validation ran, then mLock.unlock() was called manually and the IPC was issued through the member pointer mPlugin (and mPluginV1_2 in the HIDL path). Because the lock was released before the dispatch, destroyPlugin() could concurrently reset mPlugin, so the call could go through a freed or null plugin (per the commit message). In addition, the Autolock destructor unlocked mLock again at scope exit after the manual unlock, producing a double unlock. The same manual-unlock pattern existed in CryptoHalAidl::getKeyHandle on Android 17.
How the fix works
- drm/libmediadrm/CryptoHalAidl.cpp:CryptoHalAidl::decrypt: output variables (aMode, aPattern, stdSubSamples, secure, plugin) are declared before an explicit block. Inside the block, Mutex::Autolock autoLock(mLock) is taken, then the mInitCheck test, mode conversion, pattern/subsample conversion and checkSharedBuffer() checks run as before, and `plugin = mPlugin` copies a std::shared_ptr<ICryptoPluginAidl> under the lock. The lock is released once, when the block ends. The manual `mLock.unlock()` is removed. A new `if (plugin == nullptr) return NO_INIT;` guard is added, and the IPC becomes `plugin->decrypt(args, &result)` instead of `mPlugin->decrypt(...)`.
- drm/libmediadrm/CryptoHalHidl.cpp:CryptoHalHidl::decrypt: the same restructuring. Both `plugin = mPlugin` (sp<ICryptoPlugin>) and `pluginV1_2 = mPluginV1_2` (sp<drm::V1_2::ICryptoPlugin>) are captured under the lock, `mLock.unlock()` is removed, and `if (plugin == nullptr) return NO_INIT;` is added. The hidl_vec<SubSample> conversion moves after the locked block, and the dispatch uses `pluginV1_2->decrypt_1_2(...)` or `plugin->decrypt(...)` on the local references.
- drm/libmediadrm/CryptoHalAidl.cpp:CryptoHalAidl::getKeyHandle (Android 17 commit only): the same pattern. The version check, mode conversion and subsample/offset overflow validation stay under the scoped Autolock, `plugin = mPlugin` is captured, `mLock.unlock()` is removed, the null guard returns NO_INIT, and `plugin->getKeyHandle(keyIdAidl, aMode, &result)` is used.
Completeness
- Covers both the AIDL and HIDL decrypt paths. The wrapper keeps a strong reference to the plugin for the duration of the IPC, and the double unlock is removed.
- On Android 17 the same treatment is applied to CryptoHalAidl::getKeyHandle. On 14/15/16 the diff only touches decrypt in both files (getKeyHandle does not appear in those diffs).
- The fix does not change destroyPlugin() or add any synchronization between an in-flight IPC and plugin teardown. It only guarantees that the wrapper holds its own reference during the call.
- CryptoHalAidl::setMediaDrmSession, visible in the context, calls mPlugin with the Autolock held for the whole call, so it does not show the unlock-then-use pattern. It is not touched by this change.
- In getKeyHandle on 17, mPlugin->getInterfaceVersion() is still called directly on the member, but under the lock.
Behavior changes
- decrypt (and getKeyHandle on 17) now returns NO_INIT when the plugin pointer captured under the lock is null, instead of dereferencing it.
- mLock is released exactly once (at the end of the scoped block) rather than once manually and once by the Autolock destructor.
- The IPC still runs without mLock held, so concurrency between decrypt and other CryptoHal methods is unchanged. The difference is that the wrapper now holds its own strong reference to the plugin for the call.
- In the HIDL path the hidl_vec<SubSample> construction moved outside the locked region. For invalid inputs, the validation order and error codes do not change.
Per major
- Android 14: same fix: platform/frameworks/av 8cf7d2e9937b in android-security-14.0.0_r29. The diff is identical to the 15 commit (same blob hashes c1fd7975e4..130f95fb83 and 458a1aea7d..f471167b68); 8/8 patched lines present at android-security-14.0.0_r31.
- Android 15: fix commit 864123e86fc9 in android-security-15.0.0_r17 (cherry-pick of ea704d433d61, Change-Id I2e07e603ef641ddf83485a7a0e4c539b1325b91d). It touches decrypt in CryptoHalAidl.cpp and CryptoHalHidl.cpp; 8/8 patched lines present at android-security-15.0.0_r19.
- Android 16: same fix: platform/frameworks/av 0031ce0a8891 in android-security-16.0.0_r8, diff identical to the 15 commit; 8/8 lines present at android-security-16.0.0_r10.
- Android 17: adapted fix: platform/frameworks/av f103cdde766d in android-security-17.0.0_r1. CryptoHalAidl.cpp there uses convertCryptoMode() instead of the inline switch and also contains getKeyHandle, which gets the same scoped-lock/local-plugin treatment. The CryptoHalHidl.cpp hunk has the same content as on 15; 8/8 lines present at android-security-17.0.0_r3.
Unknowns
- The material does not show the implementation of destroyPlugin() or which callers can trigger it concurrently with decrypt.
- The material does not show whether other CryptoHal methods outside the shown context use the manual-unlock pattern. The 14/15/16 diffs only cover decrypt, although the commit message also mentions getKeyHandle.
- The excerpt does not show the lock state of CryptoHalAidl::notifyResolution or around the mPlugin->setSharedBufferBase call at CryptoHalHidl.cpp lines 249-252.
- The material does not show which external binder surface reaches CryptoHal decrypt.