08ccc81574
* chore: bump chromium in DEPS to 106.0.5247.1 * chore: update can_create_window.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3805043 content/renderer/render_view_impl.cc was removed * chore: update patches/chromium/printing.patch Normal code shear. * chore: update patches/chromium/add_contentgpuclient_precreatemessageloop_callback.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3764862 fix minor code shear that caused the patch to not apply * chore: update patches/chromium/picture-in-picture.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3781646 Normal code shear. * chore: update patches/chromium/allow_disabling_blink_scheduler_throttling_per_renderview.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3805043 content/renderer/render_view_impl.cc was removed Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3792324 Normal code shear. * chore: update patches/chromium/feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch Normal code shear. * chore: update patches/chromium/fix_patch_out_profile_refs_in_accessibility_ui.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3798548 Normal code shear. * chore: update patches/chromium/build_disable_print_content_analysis.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3810473 Normal code shear. * chore: short-circuit_permissions_checks_in_mediastreamdevicescontroller.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3807504 Normal code shear. * chore: update patches * chore: bump chromium in DEPS to 106.0.5249.0 * chore: bump chromium in DEPS to 107.0.5250.0 * chore: bump chromium in DEPS to 107.0.5252.0 * chore: bump chromium in DEPS to 107.0.5254.0 * chore: bump chromium in DEPS to 107.0.5256.1 * chore: update v8 patches * chore: update chromium patches * [CodeHealthRotation] base::Value::Dict (v2) migration for //c/b/ui/zoom Refs https://chromium-review.googlesource.com/c/chromium/src/+/3778239 * Add support for snapped window states for lacros https://chromium-review.googlesource.com/c/chromium/src/+/3810538 * webui: Migrate /chrome/browser/ui/webui URLDataSources to GetMimeType(GURL) Refs https://chromium-review.googlesource.com/c/chromium/src/+/3774560 * Provide explicit template arguments to blink::AssociatedInterfaceRegistry::AddInterface Refs https://chromium-review.googlesource.com/c/chromium/src/+/3773459 * Make WebScriptExecutionCallback base::OnceCallback Refs https://chromium-review.googlesource.com/c/chromium/src/+/3676532 https://chromium-review.googlesource.com/c/chromium/src/+/3724623 https://chromium-review.googlesource.com/c/chromium/src/+/3675752 * Add implementation of reduce accept language service Refs https://chromium-review.googlesource.com/c/chromium/src/+/3687391 * Add PermissionResult in //content/public. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3807504 * [Extensions] Add new Webstore domain to extension URLs and clients Refs https://chromium-review.googlesource.com/c/chromium/src/+/3793043 * chore: update node patches * chore: fix lint * chore: update filenames.libcxx.gni * fixup! Make WebScriptExecutionCallback base::OnceCallback * chore: bump chromium in DEPS to 107.0.5266.1 * chore: bump chromium in DEPS to 107.0.5268.0 * chore: bump chromium in DEPS to 107.0.5270.1 * chore: update patches * 3848842: [DevTools] Added 'printing-in-progress' error code. https://chromium-review.googlesource.com/c/chromium/src/+/38488 * 3855766: PA: Move the allocator shim files into partition_allocator/shim/ | https://chromium-review.googlesource.com/c/chromium/src/+/3855766 * Change gfx::Rect to blink::mojom::WindowFeatures in AddNewContents and some related functions. https://chromium-review.googlesource.com/c/chromium/src/+/3835666 * Use base::FunctionRef for the various ForEachRenderFrameHost helpers. https://chromium-review.googlesource.com/c/chromium/src/+/3767487 * [loader] Send cached metadata as part of OnReceiveResponse https://chromium-review.googlesource.com/c/chromium/src/+/3811219 * 3832927: [json-schema-compiler] Support abs::optional<int> https://chromium-review.googlesource.com/c/chromium/src/+/3832927 * Use unique_ptr for BrowserPluginGuestDelegate::CreateNewGuestWindow https://chromium-review.googlesource.com/c/chromium/src/+/3847070 * 3847044: [Android] Dismiss select popup upon entering fullscreen https://chromium-review.googlesource.com/c/chromium/src/+/3847044 * chore: update patches * chore: add missing header * Migration of chrome/ BrowserContextKeyedServiceFactory to ProfileKeyedServiceFactory Part 12 https://chromium-review.googlesource.com/c/chromium/src/+/3804581 * 3786946: cast pwrite64 arg to long to avoid compilation error on arm https://chromium-review.googlesource.com/c/linux-syscall-support/+/3786946 * chore: update patches after rebase * 3846114: float: Implement for lacros p2. https://chromium-review.googlesource.com/c/chromium/src/+/3846114 * 3825237: Enable -Wunqualified-std-cast-call https://chromium-review.googlesource.com/c/chromium/src/+/3825237 * chore: bump chromium in DEPS to 107.0.5272.0 * chore: update patches * 3835746: Rename PepperPluginInfo to ContentPluginInfo https://chromium-review.googlesource.com/c/chromium/src/+/3835746 * 3852542: Plumb drag-image rect from blink to browser to RenderWidgetHostImpl https://chromium-review.googlesource.com/c/chromium/src/+/3852542 * 3826169: [json-schema-compiler] Support abs::optional<bool> https://chromium-review.googlesource.com/c/chromium/src/+/3826169 Also 3840687: [json-schema-compiler] Support abs::optional<double> https://chromium-review.googlesource.com/c/chromium/src/+/3840687 * 3857319: Reland "Remove PrefService::Get" https://chromium-review.googlesource.com/c/chromium/src/+/3857319 * 3854614: Rework LinuxUi ownership and creation https://chromium-review.googlesource.com/c/chromium/src/+/3854614 * chore: bump chromium in DEPS to 107.0.5274.0 * 3866104: [DownloadBubble] Change download notifications in exclusive_access https://chromium-review.googlesource.com/c/chromium/src/+/3866104 * chore: update patches * chore: disable optimization guide for preconnect feature * 3860569: Enable -Wshadow on Linux. https://chromium-review.googlesource.com/c/chromium/src/+/3860569 * chore: update patches after rebase * fixup: update to accomodate Wc++98-compat-extra-semi flag * Revert "fixup! Make WebScriptExecutionCallback base::OnceCallback" This reverts commit 0866fe8648671f04e4ea45ceed85db6e4a3b260b. * fixup! Make WebScriptExecutionCallback base::OnceCallback * fixup! Make WebScriptExecutionCallback base::OnceCallback * 3840937: [sandbox] Merge V8_SANDBOXED_POINTERS into V8_ENABLE_SANDBOX https://chromium-review.googlesource.com/c/v8/v8/+/3840937 * fixup! chore: update can_create_window.patch * chore: update patches * 53946: Track SSL_ERROR_ZERO_RETURN explicitly. https://boringssl-review.googlesource.com/c/boringssl/+/53946 * fixup: Migration of chrome/ BrowserContextKeyedServiceFactory to ProfileKeyedServiceFactory Part 12 https://chromium-review.googlesource.com/c/chromium/src/+/3804581 * 3805932: [headless] Added print compositor support for OOPIF printing. https://chromium-review.googlesource.com/c/chromium/src/+/3805932 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
235 lines
9.6 KiB
Diff
235 lines
9.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jeremy Rose <japthorp@slack-corp.com>
|
|
Date: Tue, 21 Jun 2022 10:04:21 -0700
|
|
Subject: support V8 sandboxed pointers
|
|
|
|
This refactors several allocators to allocate within the V8 memory cage,
|
|
allowing them to be compatible with the V8_SANDBOXED_POINTERS feature.
|
|
|
|
diff --git a/src/api/environment.cc b/src/api/environment.cc
|
|
index 9cbe99596b1b8c148ac076acf8a9623d6989d505..93d85d46dc6b3b30795b88ffa8070253f62e51bd 100644
|
|
--- a/src/api/environment.cc
|
|
+++ b/src/api/environment.cc
|
|
@@ -80,6 +80,14 @@ MaybeLocal<Value> PrepareStackTraceCallback(Local<Context> context,
|
|
return result;
|
|
}
|
|
|
|
+NodeArrayBufferAllocator::NodeArrayBufferAllocator() {
|
|
+ zero_fill_field_ = static_cast<uint32_t*>(allocator_->Allocate(sizeof(*zero_fill_field_)));
|
|
+}
|
|
+
|
|
+NodeArrayBufferAllocator::~NodeArrayBufferAllocator() {
|
|
+ allocator_->Free(zero_fill_field_, sizeof(*zero_fill_field_));
|
|
+}
|
|
+
|
|
void* NodeArrayBufferAllocator::Allocate(size_t size) {
|
|
void* ret;
|
|
if (zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers)
|
|
diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc
|
|
index 77af0661dbd056a38a8d7599b9e4f067f6b79f64..642bb2a012b4d96b46b0658223fbd7becacaa28d 100644
|
|
--- a/src/crypto/crypto_util.cc
|
|
+++ b/src/crypto/crypto_util.cc
|
|
@@ -344,10 +344,35 @@ ByteSource& ByteSource::operator=(ByteSource&& other) noexcept {
|
|
return *this;
|
|
}
|
|
|
|
-std::unique_ptr<BackingStore> ByteSource::ReleaseToBackingStore() {
|
|
+std::unique_ptr<BackingStore> ByteSource::ReleaseToBackingStore(Environment* env) {
|
|
// It's ok for allocated_data_ to be nullptr but
|
|
// only if size_ is zero.
|
|
CHECK_IMPLIES(size_ > 0, allocated_data_ != nullptr);
|
|
+#if defined(V8_ENABLE_SANDBOX)
|
|
+ // When V8 sandboxed pointers are enabled, we have to copy into the memory
|
|
+ // cage. We still want to ensure we erase the data on free though, so
|
|
+ // provide a custom deleter that calls OPENSSL_cleanse.
|
|
+ if (!size())
|
|
+ return ArrayBuffer::NewBackingStore(env->isolate(), 0);
|
|
+ std::unique_ptr<ArrayBuffer::Allocator> allocator(ArrayBuffer::Allocator::NewDefaultAllocator());
|
|
+ void* v8_data = allocator->Allocate(size());
|
|
+ CHECK(v8_data);
|
|
+ memcpy(v8_data, allocated_data_, size());
|
|
+ OPENSSL_clear_free(allocated_data_, size());
|
|
+ std::unique_ptr<BackingStore> ptr = ArrayBuffer::NewBackingStore(
|
|
+ v8_data,
|
|
+ size(),
|
|
+ [](void* data, size_t length, void*) {
|
|
+ OPENSSL_cleanse(data, length);
|
|
+ std::unique_ptr<ArrayBuffer::Allocator> allocator(ArrayBuffer::Allocator::NewDefaultAllocator());
|
|
+ allocator->Free(data, length);
|
|
+ }, nullptr);
|
|
+ CHECK(ptr);
|
|
+ allocated_data_ = nullptr;
|
|
+ data_ = nullptr;
|
|
+ size_ = 0;
|
|
+ return ptr;
|
|
+#else
|
|
std::unique_ptr<BackingStore> ptr = ArrayBuffer::NewBackingStore(
|
|
allocated_data_,
|
|
size(),
|
|
@@ -359,10 +384,11 @@ std::unique_ptr<BackingStore> ByteSource::ReleaseToBackingStore() {
|
|
data_ = nullptr;
|
|
size_ = 0;
|
|
return ptr;
|
|
+#endif // defined(V8_ENABLE_SANDBOX)
|
|
}
|
|
|
|
Local<ArrayBuffer> ByteSource::ToArrayBuffer(Environment* env) {
|
|
- std::unique_ptr<BackingStore> store = ReleaseToBackingStore();
|
|
+ std::unique_ptr<BackingStore> store = ReleaseToBackingStore(env);
|
|
return ArrayBuffer::New(env->isolate(), std::move(store));
|
|
}
|
|
|
|
@@ -692,6 +718,16 @@ CryptoJobMode GetCryptoJobMode(v8::Local<v8::Value> args) {
|
|
}
|
|
|
|
namespace {
|
|
+#if defined(V8_ENABLE_SANDBOX)
|
|
+// When V8 sandboxed pointers are enabled, the secure heap cannot be used as
|
|
+// all ArrayBuffers must be allocated inside the V8 memory cage.
|
|
+void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
|
|
+ CHECK(args[0]->IsUint32());
|
|
+ uint32_t len = args[0].As<Uint32>()->Value();
|
|
+ Local<ArrayBuffer> buffer = ArrayBuffer::New(args.GetIsolate(), len);
|
|
+ args.GetReturnValue().Set(Uint8Array::New(buffer, 0, len));
|
|
+}
|
|
+#else
|
|
// SecureBuffer uses openssl to allocate a Uint8Array using
|
|
// OPENSSL_secure_malloc. Because we do not yet actually
|
|
// make use of secure heap, this has the same semantics as
|
|
@@ -719,6 +755,7 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
|
|
Local<ArrayBuffer> buffer = ArrayBuffer::New(env->isolate(), store);
|
|
args.GetReturnValue().Set(Uint8Array::New(buffer, 0, len));
|
|
}
|
|
+#endif // defined(V8_ENABLE_SANDBOX)
|
|
|
|
void SecureHeapUsed(const FunctionCallbackInfo<Value>& args) {
|
|
#ifndef OPENSSL_IS_BORINGSSL
|
|
diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h
|
|
index 07ea8e44da3e54b8c24fd2d57b3922d6ddd35781..6d0d93b5b7c0bd1d8342e81024712df029d7e618 100644
|
|
--- a/src/crypto/crypto_util.h
|
|
+++ b/src/crypto/crypto_util.h
|
|
@@ -254,7 +254,7 @@ class ByteSource {
|
|
// Creates a v8::BackingStore that takes over responsibility for
|
|
// any allocated data. The ByteSource will be reset with size = 0
|
|
// after being called.
|
|
- std::unique_ptr<v8::BackingStore> ReleaseToBackingStore();
|
|
+ std::unique_ptr<v8::BackingStore> ReleaseToBackingStore(Environment* env);
|
|
|
|
v8::Local<v8::ArrayBuffer> ToArrayBuffer(Environment* env);
|
|
|
|
diff --git a/src/node_i18n.cc b/src/node_i18n.cc
|
|
index c537a247f55ff070da1988fc8b7309b5692b5c18..59bfb597849cd5a94800d6c83b238ef77245243e 100644
|
|
--- a/src/node_i18n.cc
|
|
+++ b/src/node_i18n.cc
|
|
@@ -104,7 +104,7 @@ namespace {
|
|
|
|
template <typename T>
|
|
MaybeLocal<Object> ToBufferEndian(Environment* env, MaybeStackBuffer<T>* buf) {
|
|
- MaybeLocal<Object> ret = Buffer::New(env, buf);
|
|
+ MaybeLocal<Object> ret = Buffer::Copy(env, reinterpret_cast<char*>(buf->out()), buf->length() * sizeof(T));
|
|
if (ret.IsEmpty())
|
|
return ret;
|
|
|
|
diff --git a/src/node_internals.h b/src/node_internals.h
|
|
index f7314c906e580664be445a8912030e17a3ac2fa4..99258ad0aa1e15ea1ba139fd0e83111e1436cc40 100644
|
|
--- a/src/node_internals.h
|
|
+++ b/src/node_internals.h
|
|
@@ -97,7 +97,9 @@ bool InitializePrimordials(v8::Local<v8::Context> context);
|
|
|
|
class NodeArrayBufferAllocator : public ArrayBufferAllocator {
|
|
public:
|
|
- inline uint32_t* zero_fill_field() { return &zero_fill_field_; }
|
|
+ NodeArrayBufferAllocator();
|
|
+ ~NodeArrayBufferAllocator() override;
|
|
+ inline uint32_t* zero_fill_field() { return zero_fill_field_; }
|
|
|
|
void* Allocate(size_t size) override; // Defined in src/node.cc
|
|
void* AllocateUninitialized(size_t size) override;
|
|
@@ -116,7 +118,7 @@ class NodeArrayBufferAllocator : public ArrayBufferAllocator {
|
|
}
|
|
|
|
private:
|
|
- uint32_t zero_fill_field_ = 1; // Boolean but exposed as uint32 to JS land.
|
|
+ uint32_t* zero_fill_field_ = nullptr; // Boolean but exposed as uint32 to JS land.
|
|
std::atomic<size_t> total_mem_usage_ {0};
|
|
|
|
// Delegate to V8's allocator for compatibility with the V8 memory cage.
|
|
diff --git a/src/node_serdes.cc b/src/node_serdes.cc
|
|
index f6f0034bc24d09e3ad65491c7d6be0b9c9db1581..92d5020f293c98c81d3891a82f7320629bf9f926 100644
|
|
--- a/src/node_serdes.cc
|
|
+++ b/src/node_serdes.cc
|
|
@@ -29,6 +29,11 @@ using v8::ValueSerializer;
|
|
|
|
namespace serdes {
|
|
|
|
+v8::ArrayBuffer::Allocator* GetAllocator() {
|
|
+ static v8::ArrayBuffer::Allocator* allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
|
|
+ return allocator;
|
|
+};
|
|
+
|
|
class SerializerContext : public BaseObject,
|
|
public ValueSerializer::Delegate {
|
|
public:
|
|
@@ -37,10 +42,15 @@ class SerializerContext : public BaseObject,
|
|
|
|
~SerializerContext() override = default;
|
|
|
|
+ // v8::ValueSerializer::Delegate
|
|
void ThrowDataCloneError(Local<String> message) override;
|
|
Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object) override;
|
|
Maybe<uint32_t> GetSharedArrayBufferId(
|
|
Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer) override;
|
|
+ void* ReallocateBufferMemory(void* old_buffer,
|
|
+ size_t old_length,
|
|
+ size_t* new_length) override;
|
|
+ void FreeBufferMemory(void* buffer) override;
|
|
|
|
static void SetTreatArrayBufferViewsAsHostObjects(
|
|
const FunctionCallbackInfo<Value>& args);
|
|
@@ -61,6 +71,7 @@ class SerializerContext : public BaseObject,
|
|
|
|
private:
|
|
ValueSerializer serializer_;
|
|
+ size_t last_length_ = 0;
|
|
};
|
|
|
|
class DeserializerContext : public BaseObject,
|
|
@@ -144,6 +155,24 @@ Maybe<uint32_t> SerializerContext::GetSharedArrayBufferId(
|
|
return id.ToLocalChecked()->Uint32Value(env()->context());
|
|
}
|
|
|
|
+void* SerializerContext::ReallocateBufferMemory(void* old_buffer,
|
|
+ size_t requested_size,
|
|
+ size_t* new_length) {
|
|
+ *new_length = std::max(static_cast<size_t>(4096), requested_size);
|
|
+ if (old_buffer) {
|
|
+ void* ret = GetAllocator()->Reallocate(old_buffer, last_length_, *new_length);
|
|
+ last_length_ = *new_length;
|
|
+ return ret;
|
|
+ } else {
|
|
+ last_length_ = *new_length;
|
|
+ return GetAllocator()->Allocate(*new_length);
|
|
+ }
|
|
+}
|
|
+
|
|
+void SerializerContext::FreeBufferMemory(void* buffer) {
|
|
+ GetAllocator()->Free(buffer, last_length_);
|
|
+}
|
|
+
|
|
Maybe<bool> SerializerContext::WriteHostObject(Isolate* isolate,
|
|
Local<Object> input) {
|
|
MaybeLocal<Value> ret;
|
|
@@ -211,7 +240,12 @@ void SerializerContext::ReleaseBuffer(const FunctionCallbackInfo<Value>& args) {
|
|
std::pair<uint8_t*, size_t> ret = ctx->serializer_.Release();
|
|
auto buf = Buffer::New(ctx->env(),
|
|
reinterpret_cast<char*>(ret.first),
|
|
- ret.second);
|
|
+ ret.second,
|
|
+ [](char* data, void* hint){
|
|
+ if (data)
|
|
+ GetAllocator()->Free(data, reinterpret_cast<size_t>(hint));
|
|
+ },
|
|
+ reinterpret_cast<void*>(ctx->last_length_));
|
|
|
|
if (!buf.IsEmpty()) {
|
|
args.GetReturnValue().Set(buf.ToLocalChecked());
|