Skip to content

Commit 9382b3b

Browse files
joyeecheungBridgeAR
authored andcommitted
deps: V8: cherry-pick e0a109c
Original commit message: [api] Implement StartupData::CanBeRehashed() for the snapshot blob This enables the embedder to check if the snapshot generated from SnapshotCreator::CreateBlob() can be rehashed and the seed can be recomputed during deserialization. The lack of this functionality resulted in a temporary vunerability in Node.js: #27365 Change-Id: I88d52337217c40f79c26438be3c87d2db874d980 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1578661 Commit-Queue: Joyee Cheung <[email protected]> Reviewed-by: Yang Guo <[email protected]> Cr-Commit-Position: refs/heads/master@{#61175} Refs: v8/v8@e0a109c PR-URL: #27533 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Refael Ackermann (רפאל פלחי) <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 6014429 commit 9382b3b

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.13',
41+
'v8_embedder_string': '-node.14',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/include/v8.h

+7
Original file line numberDiff line numberDiff line change
@@ -8605,6 +8605,13 @@ class V8_EXPORT Isolate {
86058605

86068606
class V8_EXPORT StartupData {
86078607
public:
8608+
/**
8609+
* Whether the data created can be rehashed and and the hash seed can be
8610+
* recomputed when deserialized.
8611+
* Only valid for StartupData returned by SnapshotCreator::CreateBlob().
8612+
*/
8613+
bool CanBeRehashed() const;
8614+
86088615
const char* data;
86098616
int raw_size;
86108617
};

deps/v8/src/api.cc

+5
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,11 @@ StartupData SnapshotCreator::CreateBlob(
887887
return result;
888888
}
889889

890+
bool StartupData::CanBeRehashed() const {
891+
DCHECK(i::Snapshot::VerifyChecksum(this));
892+
return i::Snapshot::ExtractRehashability(this);
893+
}
894+
890895
void V8::SetDcheckErrorHandler(DcheckErrorCallback that) {
891896
v8::base::SetDcheckFunction(that);
892897
}

deps/v8/src/snapshot/snapshot-common.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ uint32_t Snapshot::ExtractContextOffset(const v8::StartupData* data,
229229

230230
bool Snapshot::ExtractRehashability(const v8::StartupData* data) {
231231
CHECK_LT(kRehashabilityOffset, static_cast<uint32_t>(data->raw_size));
232-
return GetHeaderValue(data, kRehashabilityOffset) != 0;
232+
uint32_t rehashability = GetHeaderValue(data, kRehashabilityOffset);
233+
CHECK_IMPLIES(rehashability != 0, rehashability == 1);
234+
return rehashability != 0;
233235
}
234236

235237
namespace {

deps/v8/src/snapshot/snapshot.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ class Snapshot : public AllStatic {
8787
static bool SnapshotIsValid(const v8::StartupData* snapshot_blob);
8888
#endif // DEBUG
8989

90+
static bool ExtractRehashability(const v8::StartupData* data);
91+
9092
private:
9193
static uint32_t ExtractNumContexts(const v8::StartupData* data);
9294
static uint32_t ExtractContextOffset(const v8::StartupData* data,
9395
uint32_t index);
94-
static bool ExtractRehashability(const v8::StartupData* data);
9596
static Vector<const byte> ExtractStartupData(const v8::StartupData* data);
9697
static Vector<const byte> ExtractReadOnlyData(const v8::StartupData* data);
9798
static Vector<const byte> ExtractContextData(const v8::StartupData* data,

deps/v8/test/cctest/test-serialize.cc

+2
Original file line numberDiff line numberDiff line change
@@ -3709,6 +3709,7 @@ UNINITIALIZED_TEST(ReinitializeHashSeedNotRehashable) {
37093709
}
37103710
blob =
37113711
creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
3712+
CHECK(!blob.CanBeRehashed());
37123713
}
37133714

37143715
i::FLAG_hash_seed = 1337;
@@ -3774,6 +3775,7 @@ UNINITIALIZED_TEST(ReinitializeHashSeedRehashable) {
37743775
}
37753776
blob =
37763777
creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
3778+
CHECK(blob.CanBeRehashed());
37773779
}
37783780

37793781
i::FLAG_hash_seed = 1337;

0 commit comments

Comments
 (0)