-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
src: prepare for v8 sandboxing #58376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
d21804d
to
474cba4
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
474cba4
to
fd4f0e7
Compare
This comment was marked as outdated.
This comment was marked as outdated.
src/crypto/crypto_util.cc
Outdated
std::unique_ptr<BackingStore> ptr = ArrayBuffer::NewBackingStore( | ||
allocated_data_, | ||
size(), | ||
[](void* data, size_t length, void* deleter_data) { | ||
OPENSSL_clear_free(deleter_data, length); | ||
}, allocated_data_); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it would be a good idea to add a helper to e.g. util.h that switches between the two variants in a single location rather than having #ifdef
s for every call, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely yes. I'm wanting to minimize the individual changes in this PR so we can make sure they are correct, but then we can likely extract out some utilities (maybe in node_buffer.h
) that handle this in a more general way separately. That can be done separately I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a TODO
fd4f0e7
to
d9af9b2
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
// The v8 sandbox is enabled, so we cannot use the secure heap because | ||
// the sandbox requires that all array buffers be allocated via the isolate. | ||
// That is fundamentally incompatible with the secure heap which allocates | ||
// in openssl's secure heap area. Instead we'll just throw an error here. | ||
// | ||
// That said, we really shouldn't get here in the first place since the | ||
// option to enable the secure heap is only available when the sandbox | ||
// is disabled. | ||
THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be
// The v8 sandbox is enabled, so we cannot use the secure heap because | |
// the sandbox requires that all array buffers be allocated via the isolate. | |
// That is fundamentally incompatible with the secure heap which allocates | |
// in openssl's secure heap area. Instead we'll just throw an error here. | |
// | |
// That said, we really shouldn't get here in the first place since the | |
// option to enable the secure heap is only available when the sandbox | |
// is disabled. | |
THROW_ERR_CRYPTO_UNSUPPORTED_OPERATION(env); | |
// Secure heap is only available when the sandbox is disabled. | |
UNREACHABLE(); |
auto backing = ArrayBuffer::NewBackingStore( | ||
env->isolate(), | ||
data.size(), | ||
BackingStoreInitializationMode::kUninitialized); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these use the default BackingStoreOnFailureMode::kOutOfMemory
? I think previously the caller would throw catchable errors instead of memory allocation on the OpenSSL side fails. Now this would just crash.
When the v8 sandbox is enabled (possibly at some point in the future) all ArrayBuffer allocations must be done within the isolate. Externally allocated backing stores are not permitted. This starts to prepare for that by adding some compile time branches to copy some external buffers rather than wrapping them. We also disable the
--secure-heap
feature since that fundamentally doesn't make sense and can't be supported with v8 sandbox enabled.This PR cannot yet include additional tests for the new branches largely because we cannot yet build node with v8 sandbox enabled.