Fixed race condition in closeSession
Merged from http://go/wvgerrit/164799 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
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "OEMCryptoCENC.h"
|
||||
#include "WVGenericCryptoInterface.h"
|
||||
@@ -396,9 +397,46 @@ class WVDrmPlugin : public ::aidl::android::hardware::drm::BnDrmPlugin,
|
||||
android::Mutex mLock;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
android::sp<wvcdm::WvContentDecryptionModule> const mCDM;
|
||||
WVGenericCryptoInterface* mCrypto;
|
||||
std::map<CdmSessionId, CryptoSession> mCryptoSessions;
|
||||
CryptoSessionMap mCryptoSessions;
|
||||
std::shared_ptr<::aidl::android::hardware::drm::IDrmPluginListener> mListener;
|
||||
|
||||
std::string mProvisioningServiceCertificate;
|
||||
|
||||
Reference in New Issue
Block a user