Bug 1526891 - Part 16: Verify principalInfo before creating any parent actors; r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D20925
This commit is contained in:
Jan Varga 2019-02-23 17:37:25 +01:00
Родитель c5284f4f76
Коммит d4e6cf1df0
2 изменённых файлов: 147 добавлений и 7 удалений

Просмотреть файл

@ -889,6 +889,10 @@ class Quota final : public PQuotaParent {
void StartIdleMaintenance(); void StartIdleMaintenance();
bool VerifyRequestParams(const UsageRequestParams& aParams) const;
bool VerifyRequestParams(const RequestParams& aParams) const;
// IPDL methods. // IPDL methods.
virtual void ActorDestroy(ActorDestroyReason aWhy) override; virtual void ActorDestroy(ActorDestroyReason aWhy) override;
@ -6382,6 +6386,124 @@ void Quota::StartIdleMaintenance() {
quotaManager->StartIdleMaintenance(); quotaManager->StartIdleMaintenance();
} }
bool Quota::VerifyRequestParams(const UsageRequestParams& aParams) const {
AssertIsOnBackgroundThread();
MOZ_ASSERT(aParams.type() != UsageRequestParams::T__None);
switch (aParams.type()) {
case UsageRequestParams::TAllUsageParams:
break;
case UsageRequestParams::TOriginUsageParams: {
const OriginUsageParams& params = aParams.get_OriginUsageParams();
if (NS_WARN_IF(
!QuotaManager::IsPrincipalInfoValid(params.principalInfo()))) {
ASSERT_UNLESS_FUZZING();
return false;
}
break;
}
default:
MOZ_CRASH("Should never get here!");
}
return true;
}
bool Quota::VerifyRequestParams(const RequestParams& aParams) const {
AssertIsOnBackgroundThread();
MOZ_ASSERT(aParams.type() != RequestParams::T__None);
switch (aParams.type()) {
case RequestParams::TInitParams:
case RequestParams::TInitTemporaryStorageParams:
break;
case RequestParams::TInitOriginParams: {
const InitOriginParams& params = aParams.get_InitOriginParams();
if (NS_WARN_IF(
!QuotaManager::IsPrincipalInfoValid(params.principalInfo()))) {
ASSERT_UNLESS_FUZZING();
return false;
}
break;
}
case RequestParams::TClearOriginParams: {
const ClearResetOriginParams& params =
aParams.get_ClearOriginParams().commonParams();
if (NS_WARN_IF(
!QuotaManager::IsPrincipalInfoValid(params.principalInfo()))) {
ASSERT_UNLESS_FUZZING();
return false;
}
break;
}
case RequestParams::TResetOriginParams: {
const ClearResetOriginParams& params =
aParams.get_ResetOriginParams().commonParams();
if (NS_WARN_IF(
!QuotaManager::IsPrincipalInfoValid(params.principalInfo()))) {
ASSERT_UNLESS_FUZZING();
return false;
}
break;
}
case RequestParams::TClearDataParams: {
if (BackgroundParent::IsOtherProcessActor(Manager())) {
ASSERT_UNLESS_FUZZING();
return false;
}
break;
}
case RequestParams::TClearAllParams:
case RequestParams::TResetAllParams:
break;
case RequestParams::TPersistedParams: {
const PersistedParams& params = aParams.get_PersistedParams();
if (NS_WARN_IF(
!QuotaManager::IsPrincipalInfoValid(params.principalInfo()))) {
ASSERT_UNLESS_FUZZING();
return false;
}
break;
}
case RequestParams::TPersistParams: {
const PersistParams& params = aParams.get_PersistParams();
if (NS_WARN_IF(
!QuotaManager::IsPrincipalInfoValid(params.principalInfo()))) {
ASSERT_UNLESS_FUZZING();
return false;
}
break;
}
default:
MOZ_CRASH("Should never get here!");
}
return true;
}
void Quota::ActorDestroy(ActorDestroyReason aWhy) { void Quota::ActorDestroy(ActorDestroyReason aWhy) {
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
#ifdef DEBUG #ifdef DEBUG
@ -6395,6 +6517,18 @@ PQuotaUsageRequestParent* Quota::AllocPQuotaUsageRequestParent(
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(aParams.type() != UsageRequestParams::T__None); MOZ_ASSERT(aParams.type() != UsageRequestParams::T__None);
#ifdef DEBUG
// Always verify parameters in DEBUG builds!
bool trustParams = false;
#else
bool trustParams = !BackgroundParent::IsOtherProcessActor(Manager());
#endif
if (!trustParams && NS_WARN_IF(!VerifyRequestParams(aParams))) {
ASSERT_UNLESS_FUZZING();
return nullptr;
}
RefPtr<QuotaUsageRequestBase> actor; RefPtr<QuotaUsageRequestBase> actor;
switch (aParams.type()) { switch (aParams.type()) {
@ -6447,15 +6581,17 @@ PQuotaRequestParent* Quota::AllocPQuotaRequestParent(
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(aParams.type() != RequestParams::T__None); MOZ_ASSERT(aParams.type() != RequestParams::T__None);
if (aParams.type() == RequestParams::TClearDataParams) { #ifdef DEBUG
PBackgroundParent* actor = Manager(); // Always verify parameters in DEBUG builds!
MOZ_ASSERT(actor); bool trustParams = false;
#else
bool trustParams = !BackgroundParent::IsOtherProcessActor(Manager());
#endif
if (BackgroundParent::IsOtherProcessActor(actor)) { if (!trustParams && NS_WARN_IF(!VerifyRequestParams(aParams))) {
ASSERT_UNLESS_FUZZING(); ASSERT_UNLESS_FUZZING();
return nullptr; return nullptr;
} }
}
RefPtr<QuotaRequestBase> actor; RefPtr<QuotaRequestBase> actor;

Просмотреть файл

@ -65,6 +65,10 @@ nsresult CheckedPrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
return rv; return rv;
} }
if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(aPrincipalInfo))) {
return NS_ERROR_FAILURE;
}
if (aPrincipalInfo.type() != PrincipalInfo::TContentPrincipalInfo && if (aPrincipalInfo.type() != PrincipalInfo::TContentPrincipalInfo &&
aPrincipalInfo.type() != PrincipalInfo::TSystemPrincipalInfo) { aPrincipalInfo.type() != PrincipalInfo::TSystemPrincipalInfo) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;