Guard against double initialize am: 03f8d1b6f7 am: 6864a04975
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/16306734 Change-Id: I82dacd938afd609f48eeb786b8ad78098b6dbe36
This commit is contained in:
committed by
Automerger Merge Worker
commit
b47aa150ea
@@ -723,7 +723,7 @@ struct LevelSession {
|
||||
level1_.Name = (L1_##Name##_t)dlsym(level1_library_, QUOTE(Function)); \
|
||||
if (!level1_.Name) { \
|
||||
LOGW("Could not load L1 %s. Falling back to L3.", QUOTE(Function)); \
|
||||
if (level1_.Terminate) level1_.Terminate(); \
|
||||
if (level1_.Terminate) Level1Terminate(); \
|
||||
return false; \
|
||||
} \
|
||||
}
|
||||
@@ -745,7 +745,11 @@ class Adapter {
|
||||
public:
|
||||
using map_iterator = std::map<OEMCrypto_SESSION, LevelSession>::iterator;
|
||||
|
||||
Adapter() : level1_valid_(false), level1_library_(nullptr) {}
|
||||
Adapter()
|
||||
: level1_valid_(false),
|
||||
level1_initialized_(false),
|
||||
level1_failed_(false),
|
||||
level1_library_(nullptr) {}
|
||||
|
||||
// The adapter is only destroyed on certain errors, or when the process
|
||||
// dies. It is NOT deleted after each OEMCrypto_Terminate.
|
||||
@@ -824,9 +828,23 @@ class Adapter {
|
||||
return result;
|
||||
}
|
||||
|
||||
OEMCryptoResult Level1Terminate() {
|
||||
OEMCryptoResult result = OEMCrypto_SUCCESS;
|
||||
if (level1_.Terminate && level1_initialized_) {
|
||||
LOGE("L1 Terminate");
|
||||
result = level1_.Terminate();
|
||||
} else {
|
||||
LOGE("L1 Terminate not needed");
|
||||
}
|
||||
level1_initialized_ = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
void FallBackToLevel3() {
|
||||
Level1Terminate();
|
||||
level1_ = FunctionPointers(); // revert to all null pointers.
|
||||
level1_valid_ = false;
|
||||
level1_failed_ = true;
|
||||
// Note: if the function pointers are bad, we do not close the library and
|
||||
// try again later. Instead, we permanently fall back to L3. This is a
|
||||
// debatable choice: I decided the risk of a dlclose resource leak out
|
||||
@@ -838,6 +856,12 @@ class Adapter {
|
||||
if (metrics == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (level1_failed_) {
|
||||
// If we failed to initialize the level 1 library before, then we don't
|
||||
// try again.
|
||||
LOGE("Still falling back to L3.");
|
||||
return false;
|
||||
}
|
||||
level1_valid_ = true;
|
||||
const uint32_t kMinimumVersion = 8;
|
||||
const uint32_t kMaximumVersion = 16;
|
||||
@@ -869,6 +893,7 @@ class Adapter {
|
||||
OEMCrypto_INITIALIZED_USING_L3_COULD_NOT_INITIALIZE_L1);
|
||||
return false;
|
||||
}
|
||||
level1_initialized_ = true;
|
||||
level1_.version = level1_.APIVersion();
|
||||
level1_.security_level = wvcdm::kSecurityLevelUninitialized;
|
||||
metrics->SetL1ApiVersion(level1_.version);
|
||||
@@ -879,7 +904,7 @@ class Adapter {
|
||||
level1_.version, kMinimumVersion);
|
||||
metrics->OemCryptoDynamicAdapterMetrics::SetInitializationMode(
|
||||
wvcdm::metrics::OEMCrypto_INITIALIZED_USING_L3_WRONG_L1_VERSION);
|
||||
level1_.Terminate();
|
||||
Level1Terminate();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1002,7 +1027,6 @@ class Adapter {
|
||||
level1_.security_level = wvcdm::kSecurityLevelUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1089,7 +1113,7 @@ class Adapter {
|
||||
session_map_.clear();
|
||||
OEMCryptoResult result = Level3_Terminate();
|
||||
if (level1_valid_) {
|
||||
result = level1_.Terminate();
|
||||
result = Level1Terminate();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1160,8 +1184,7 @@ class Adapter {
|
||||
if (!level1_.IsKeyboxOrOEMCertValid) {
|
||||
// TODO(b/189989043): add metrics.
|
||||
LOGE("L1 invalid function pointers. Falling back to L3");
|
||||
if (level1_.Terminate) level1_.Terminate();
|
||||
level1_valid_ = false;
|
||||
FallBackToLevel3();
|
||||
return level3_.IsKeyboxOrOEMCertValid ? level3_.IsKeyboxOrOEMCertValid()
|
||||
: OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
@@ -1211,14 +1234,16 @@ class Adapter {
|
||||
wvcdm::metrics::
|
||||
OEMCrypto_INITIALIZED_USING_L3_COULD_NOT_INSTALL_KEYBOX);
|
||||
}
|
||||
if (level1_.Terminate) level1_.Terminate();
|
||||
level1_valid_ = false;
|
||||
FallBackToLevel3();
|
||||
return level3_.IsKeyboxOrOEMCertValid ? level3_.IsKeyboxOrOEMCertValid()
|
||||
: OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
private:
|
||||
bool level1_valid_;
|
||||
bool level1_initialized_;
|
||||
// If the level 1 fails to initialize once, we don't try again.
|
||||
bool level1_failed_;
|
||||
void* level1_library_;
|
||||
struct FunctionPointers level1_;
|
||||
struct FunctionPointers level3_;
|
||||
|
||||
Reference in New Issue
Block a user