Commit afb49bae authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[flags] Improve flag to verify and create snapshot checksums

- Rename --skip-snapshot-checksum to --verify-snapshot-checksum to
  avoid double negations in most of the code
- Conditionally create and verify checksums in SerializedCodeData
- Remove unused Deserializer::GetChecksum

Bug: chromium:1270752
Change-Id: I8360e0dd5f25dac68bf68909155771b302184a4b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3284883
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77925}
parent 6ffcdddb
...@@ -1754,8 +1754,9 @@ DEFINE_BOOL(rcs_cpu_time, false, ...@@ -1754,8 +1754,9 @@ DEFINE_BOOL(rcs_cpu_time, false,
DEFINE_IMPLICATION(rcs_cpu_time, rcs) DEFINE_IMPLICATION(rcs_cpu_time, rcs)
// snapshot-common.cc // snapshot-common.cc
DEFINE_BOOL(skip_snapshot_checksum, false, DEFINE_BOOL(verify_snapshot_checksum, true,
"Skip snapshot checksum calculation when deserializing an Isolate.") "Verify snapshot checksums when deserializing snapshots. Enable "
"checksum creation and verification for code caches.")
DEFINE_BOOL(profile_deserialization, false, DEFINE_BOOL(profile_deserialization, false,
"Print the time it takes to deserialize the snapshot.") "Print the time it takes to deserialize the snapshot.")
DEFINE_BOOL(serialization_statistics, false, DEFINE_BOOL(serialization_statistics, false,
......
...@@ -557,8 +557,9 @@ SerializedCodeData::SerializedCodeData(const std::vector<byte>* payload, ...@@ -557,8 +557,9 @@ SerializedCodeData::SerializedCodeData(const std::vector<byte>* payload,
// Copy serialized data. // Copy serialized data.
CopyBytes(data_ + kHeaderSize, payload->data(), CopyBytes(data_ + kHeaderSize, payload->data(),
static_cast<size_t>(payload->size())); static_cast<size_t>(payload->size()));
uint32_t checksum =
SetHeaderValue(kChecksumOffset, Checksum(ChecksummedContent())); FLAG_verify_snapshot_checksum ? Checksum(ChecksummedContent()) : 0;
SetHeaderValue(kChecksumOffset, checksum);
} }
SerializedCodeSanityCheckResult SerializedCodeData::SanityCheck( SerializedCodeSanityCheckResult SerializedCodeData::SanityCheck(
...@@ -587,21 +588,23 @@ SerializedCodeSanityCheckResult SerializedCodeData::SanityCheckWithoutSource() ...@@ -587,21 +588,23 @@ SerializedCodeSanityCheckResult SerializedCodeData::SanityCheckWithoutSource()
return SerializedCodeSanityCheckResult::kMagicNumberMismatch; return SerializedCodeSanityCheckResult::kMagicNumberMismatch;
} }
uint32_t version_hash = GetHeaderValue(kVersionHashOffset); uint32_t version_hash = GetHeaderValue(kVersionHashOffset);
uint32_t flags_hash = GetHeaderValue(kFlagHashOffset);
uint32_t payload_length = GetHeaderValue(kPayloadLengthOffset);
uint32_t c = GetHeaderValue(kChecksumOffset);
if (version_hash != Version::Hash()) { if (version_hash != Version::Hash()) {
return SerializedCodeSanityCheckResult::kVersionMismatch; return SerializedCodeSanityCheckResult::kVersionMismatch;
} }
uint32_t flags_hash = GetHeaderValue(kFlagHashOffset);
if (flags_hash != FlagList::Hash()) { if (flags_hash != FlagList::Hash()) {
return SerializedCodeSanityCheckResult::kFlagsMismatch; return SerializedCodeSanityCheckResult::kFlagsMismatch;
} }
uint32_t payload_length = GetHeaderValue(kPayloadLengthOffset);
uint32_t max_payload_length = this->size_ - kHeaderSize; uint32_t max_payload_length = this->size_ - kHeaderSize;
if (payload_length > max_payload_length) { if (payload_length > max_payload_length) {
return SerializedCodeSanityCheckResult::kLengthMismatch; return SerializedCodeSanityCheckResult::kLengthMismatch;
} }
if (Checksum(ChecksummedContent()) != c) { if (FLAG_verify_snapshot_checksum) {
return SerializedCodeSanityCheckResult::kChecksumMismatch; uint32_t checksum = GetHeaderValue(kChecksumOffset);
if (Checksum(ChecksummedContent()) != checksum) {
return SerializedCodeSanityCheckResult::kChecksumMismatch;
}
} }
return SerializedCodeSanityCheckResult::kSuccess; return SerializedCodeSanityCheckResult::kSuccess;
} }
......
...@@ -49,8 +49,6 @@ class Deserializer : public SerializerDeserializer { ...@@ -49,8 +49,6 @@ class Deserializer : public SerializerDeserializer {
Deserializer(const Deserializer&) = delete; Deserializer(const Deserializer&) = delete;
Deserializer& operator=(const Deserializer&) = delete; Deserializer& operator=(const Deserializer&) = delete;
uint32_t GetChecksum() const { return source_.GetChecksum(); }
protected: protected:
// Create a deserializer from a snapshot byte source. // Create a deserializer from a snapshot byte source.
Deserializer(IsolateT* isolate, base::Vector<const byte> payload, Deserializer(IsolateT* isolate, base::Vector<const byte> payload,
......
...@@ -103,10 +103,6 @@ class SnapshotByteSource final { ...@@ -103,10 +103,6 @@ class SnapshotByteSource final {
int position() { return position_; } int position() { return position_; }
void set_position(int position) { position_ = position; } void set_position(int position) { position_ = position; }
uint32_t GetChecksum() const {
return Checksum(base::Vector<const byte>(data_, length_));
}
private: private:
const byte* data_; const byte* data_;
int length_; int length_;
......
...@@ -168,9 +168,7 @@ bool Snapshot::Initialize(Isolate* isolate) { ...@@ -168,9 +168,7 @@ bool Snapshot::Initialize(Isolate* isolate) {
const v8::StartupData* blob = isolate->snapshot_blob(); const v8::StartupData* blob = isolate->snapshot_blob();
SnapshotImpl::CheckVersion(blob); SnapshotImpl::CheckVersion(blob);
if (!FLAG_skip_snapshot_checksum) { if (FLAG_verify_snapshot_checksum) CHECK(VerifyChecksum(blob));
CHECK(VerifyChecksum(blob));
}
base::Vector<const byte> startup_data = base::Vector<const byte> startup_data =
SnapshotImpl::ExtractStartupData(blob); SnapshotImpl::ExtractStartupData(blob);
base::Vector<const byte> read_only_data = base::Vector<const byte> read_only_data =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment