Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: delta_performer.cc

Issue 3712003: AU: Verify source rootfs/kernel hashes before applying delta. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: verify source partitions only for new updates Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « delta_performer.h ('k') | delta_performer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "update_engine/delta_performer.h" 5 #include "update_engine/delta_performer.h"
6 6
7 #include <endian.h> 7 #include <endian.h>
8 #include <errno.h> 8 #include <errno.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 TEST_AND_RETURN_FALSE(hasher.UpdateFile(*paths[i], infos[i]->size())); 571 TEST_AND_RETURN_FALSE(hasher.UpdateFile(*paths[i], infos[i]->size()));
572 TEST_AND_RETURN_FALSE(hasher.Finalize()); 572 TEST_AND_RETURN_FALSE(hasher.Finalize());
573 TEST_AND_RETURN_FALSE(hasher.raw_hash().size() == infos[i]->hash().size()); 573 TEST_AND_RETURN_FALSE(hasher.raw_hash().size() == infos[i]->hash().size());
574 TEST_AND_RETURN_FALSE(memcmp(hasher.raw_hash().data(), 574 TEST_AND_RETURN_FALSE(memcmp(hasher.raw_hash().data(),
575 infos[i]->hash().data(), 575 infos[i]->hash().data(),
576 hasher.raw_hash().size()) == 0); 576 hasher.raw_hash().size()) == 0);
577 } 577 }
578 return true; 578 return true;
579 } 579 }
580 580
581 bool DeltaPerformer::VerifySourcePartitions() {
582 LOG(INFO) << "Verifying source partitions.";
583 CHECK(manifest_valid_);
584 if (manifest_.has_old_kernel_info()) {
585 const PartitionInfo& info = manifest_.old_kernel_info();
586 TEST_AND_RETURN_FALSE(current_kernel_hash_ != NULL &&
587 current_kernel_hash_->size() == info.hash().size() &&
588 memcmp(current_kernel_hash_->data(),
589 info.hash().data(),
590 current_kernel_hash_->size()) == 0);
591 }
592 if (manifest_.has_old_rootfs_info()) {
593 const PartitionInfo& info = manifest_.old_rootfs_info();
594 TEST_AND_RETURN_FALSE(current_rootfs_hash_ != NULL &&
595 current_rootfs_hash_->size() == info.hash().size() &&
596 memcmp(current_rootfs_hash_->data(),
597 info.hash().data(),
598 current_rootfs_hash_->size()) == 0);
599 }
600 return true;
601 }
602
581 void DeltaPerformer::DiscardBufferHeadBytes(size_t count) { 603 void DeltaPerformer::DiscardBufferHeadBytes(size_t count) {
582 hash_calculator_.Update(&buffer_[0], count); 604 hash_calculator_.Update(&buffer_[0], count);
583 buffer_.erase(buffer_.begin(), buffer_.begin() + count); 605 buffer_.erase(buffer_.begin(), buffer_.begin() + count);
584 } 606 }
585 607
586 bool DeltaPerformer::CanResumeUpdate(PrefsInterface* prefs, 608 bool DeltaPerformer::CanResumeUpdate(PrefsInterface* prefs,
587 string update_check_response_hash) { 609 string update_check_response_hash) {
588 int64_t next_operation = kUpdateStateOperationInvalid; 610 int64_t next_operation = kUpdateStateOperationInvalid;
589 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsUpdateStateNextOperation, 611 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsUpdateStateNextOperation,
590 &next_operation) && 612 &next_operation) &&
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 676
655 bool DeltaPerformer::PrimeUpdateState() { 677 bool DeltaPerformer::PrimeUpdateState() {
656 CHECK(manifest_valid_); 678 CHECK(manifest_valid_);
657 block_size_ = manifest_.block_size(); 679 block_size_ = manifest_.block_size();
658 680
659 int64_t next_operation = kUpdateStateOperationInvalid; 681 int64_t next_operation = kUpdateStateOperationInvalid;
660 if (!prefs_->GetInt64(kPrefsUpdateStateNextOperation, &next_operation) || 682 if (!prefs_->GetInt64(kPrefsUpdateStateNextOperation, &next_operation) ||
661 next_operation == kUpdateStateOperationInvalid || 683 next_operation == kUpdateStateOperationInvalid ||
662 next_operation <= 0) { 684 next_operation <= 0) {
663 // Initiating a new update, no more state needs to be initialized. 685 // Initiating a new update, no more state needs to be initialized.
686 TEST_AND_RETURN_FALSE(VerifySourcePartitions());
664 return true; 687 return true;
665 } 688 }
666 next_operation_num_ = next_operation; 689 next_operation_num_ = next_operation;
667 690
668 // Resuming an update -- load the rest of the update state. 691 // Resuming an update -- load the rest of the update state.
669 int64_t next_data_offset = -1; 692 int64_t next_data_offset = -1;
670 TEST_AND_RETURN_FALSE(prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, 693 TEST_AND_RETURN_FALSE(prefs_->GetInt64(kPrefsUpdateStateNextDataOffset,
671 &next_data_offset) && 694 &next_data_offset) &&
672 next_data_offset >= 0); 695 next_data_offset >= 0);
673 buffer_offset_ = next_data_offset; 696 buffer_offset_ = next_data_offset;
(...skipping 19 matching lines...) Expand all
693 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { 716 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) {
694 resumed_update_failures++; 717 resumed_update_failures++;
695 } else { 718 } else {
696 resumed_update_failures = 1; 719 resumed_update_failures = 1;
697 } 720 }
698 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); 721 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures);
699 return true; 722 return true;
700 } 723 }
701 724
702 } // namespace chromeos_update_engine 725 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « delta_performer.h ('k') | delta_performer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698