Fixed race condition in closeSession

Merged from http://go/wvgerrit/165498
poc: http://go/ag/20978761

Fix race that corrupts mCryptoSessions std::map,
and race that occurs when CryptoSessions are used after free.

Test: poc
Test: atest MediaDrmParameterizedTests
Test: atest GtsMediaTestCases

Bug: 258189255
Change-Id: I298d3e0770ace9cd590dfaacaa4c52a0732c2fe3
Merged-In: I298d3e0770ace9cd590dfaacaa4c52a0732c2fe3
This commit is contained in:
Edwin Wong
2023-01-04 01:56:05 +00:00
committed by Rahul Frias
parent 18be093969
commit 08acec9c3a
4 changed files with 173 additions and 103 deletions

View File

@@ -8,6 +8,7 @@
#define WV_DRM_PLUGIN_H_
#include <map>
#include <mutex>
#include "cdm_client_property_set.h"
#include "cdm_identifier.h"
@@ -450,9 +451,46 @@ struct WVDrmPlugin : public ::drm::V1_4::IDrmPlugin, IDrmPluginListener,
uint32_t getNextUniqueId();
} mCdmIdentifierBuilder;
class CryptoSessionMap {
public:
std::map<CdmSessionId, std::shared_ptr<CryptoSession>> clear() {
std::unique_lock<std::mutex> auto_lock(mLock);
auto copy = mMap;
mMap.clear();
return copy;
}
std::shared_ptr<CryptoSession> get(const CdmSessionId& sid) {
std::unique_lock<std::mutex> auto_lock(mLock);
if (mMap.count(sid)) {
return mMap[sid];
}
return nullptr;
}
bool empty() {
std::unique_lock<std::mutex> auto_lock(mLock);
return mMap.empty();
}
void erase(const CdmSessionId& sid) {
std::unique_lock<std::mutex> auto_lock(mLock);
mMap.erase(sid);
}
void insert(const CdmSessionId& sid, OEMCrypto_SESSION osid) {
std::unique_lock<std::mutex> auto_lock(mLock);
mMap[sid] = std::make_shared<CryptoSession>(osid);
}
private:
std::mutex mLock;
std::map<CdmSessionId, std::shared_ptr<CryptoSession>> mMap;
};
sp<wvcdm::WvContentDecryptionModule> const mCDM;
WVGenericCryptoInterface* mCrypto;
map<CdmSessionId, CryptoSession> mCryptoSessions;
CryptoSessionMap mCryptoSessions;
sp<IDrmPluginListener> mListener;
sp<IDrmPluginListener_V1_2> mListenerV1_2;