Skip to content

Commit 6f260e5

Browse files
author
Allan Sandfeld Jensen
committed
[Backport] CVE-2020-6461: Use after free in storage
[Blobs] Fix bug when BytesProvider replies with invalid data. (cherry picked from commit 38990b7d56e6dde6bfdc2d81950db8ddef4e4116) Bug: 1072983 Change-Id: Ideaa0a67680375e770995880a4b8d2014b51d642 Reviewed-by: enne <[email protected]> Commit-Queue: Marijn Kruisselbrink <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#761203} Reviewed-by: Marijn Kruisselbrink <[email protected]> Cr-Commit-Position: refs/branch-heads/4044@{#972} Cr-Branched-From: a6d9daf149a473ceea37f629c41d4527bf2055bd-refs/heads/master@{#737173} Reviewed-by: Michal Klocek <[email protected]>
1 parent 165753b commit 6f260e5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

chromium/storage/browser/blob/blob_registry_impl.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ void BlobRegistryImpl::BlobUnderConstruction::TransportComplete(
432432
// try to delete |this| again afterwards.
433433
auto weak_this = weak_ptr_factory_.GetWeakPtr();
434434

435+
// Store the bad_message_callback_, so we can invoke it if needed, after
436+
// notifying about the blob being finished.
437+
auto bad_message_callback = std::move(bad_message_callback_);
438+
435439
// The blob might no longer have any references, in which case it may no
436440
// longer exist. If that happens just skip calling Complete.
437441
// TODO(mek): Stop building sooner if a blob is no longer referenced.
@@ -445,7 +449,7 @@ void BlobRegistryImpl::BlobUnderConstruction::TransportComplete(
445449
// BlobTransportStrategy might have already reported a BadMessage on the
446450
// BytesProvider binding, but just to be safe, also report one on the
447451
// BlobRegistry binding itself.
448-
std::move(bad_message_callback_)
452+
std::move(bad_message_callback)
449453
.Run("Received invalid data while transporting blob");
450454
}
451455
if (weak_this)

chromium/storage/browser/blob/blob_registry_impl_unittest.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,36 @@ TEST_F(BlobRegistryImplTest, Register_ValidBytesAsReply) {
770770
EXPECT_EQ(0u, BlobsUnderConstruction());
771771
}
772772

773+
TEST_F(BlobRegistryImplTest, Register_InvalidBytesAsReply) {
774+
const std::string kId = "id";
775+
const std::string kData = "hello";
776+
777+
std::vector<blink::mojom::DataElementPtr> elements;
778+
elements.push_back(
779+
blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New(
780+
kData.size(), base::nullopt, CreateBytesProvider(""))));
781+
782+
mojo::PendingRemote<blink::mojom::Blob> blob;
783+
EXPECT_TRUE(registry_->Register(blob.InitWithNewPipeAndPassReceiver(), kId,
784+
"", "", std::move(elements)));
785+
786+
std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId);
787+
WaitForBlobCompletion(handle.get());
788+
789+
EXPECT_TRUE(handle->IsBroken());
790+
ASSERT_EQ(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS,
791+
handle->GetBlobStatus());
792+
793+
EXPECT_EQ(1u, reply_request_count_);
794+
EXPECT_EQ(0u, stream_request_count_);
795+
EXPECT_EQ(0u, file_request_count_);
796+
EXPECT_EQ(0u, BlobsUnderConstruction());
797+
798+
// Expect 2 bad messages, one for the bad reply by the bytes provider, and one
799+
// for the original register call.
800+
EXPECT_EQ(2u, bad_messages_.size());
801+
}
802+
773803
TEST_F(BlobRegistryImplTest, Register_ValidBytesAsStream) {
774804
const std::string kId = "id";
775805
const std::string kData =

0 commit comments

Comments
 (0)