Commit 689f4ac0 authored by Drew Fisher's avatar Drew Fisher Committed by Commit Bot

fuchsia: make NativeLibrary use fdio_get_vmo_exec

This lets us remove ambient replace-as-executable from things that don't
use V8.  This includes:

* cast_runner and web_runner, which simply provide fuchsia.sys.Runner
  glue implementations
* http, which provides a legacy HTTP implementation that also doesn't
  need to directly execute memory.

We can also remove the implied executability from some tests.  As a
start, convert the base unittests (which test LoadLibrary) to eschew
the deprecated-ambient-replace-as-executable feature.

Bug: fxb/37924
Change-Id: I461312972881a0e05d31834227e482c78b445ef9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1881697
Commit-Queue: Drew Fisher <zarvox@google.com>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711367}
parent 80f0a769
...@@ -3118,6 +3118,8 @@ test("base_unittests") { ...@@ -3118,6 +3118,8 @@ test("base_unittests") {
"//third_party/fuchsia-sdk/sdk:sys", "//third_party/fuchsia-sdk/sdk:sys",
"//third_party/fuchsia-sdk/sdk:sys_cpp", "//third_party/fuchsia-sdk/sdk:sys_cpp",
] ]
manifest = "//build/config/fuchsia/tests.cmx"
} }
if (!is_fuchsia && !is_ios) { if (!is_fuchsia && !is_ios) {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "base/native_library.h" #include "base/native_library.h"
#include <fcntl.h> #include <fcntl.h>
#include <fuchsia/io/cpp/fidl.h>
#include <lib/fdio/directory.h>
#include <lib/fdio/io.h> #include <lib/fdio/io.h>
#include <lib/zx/vmo.h> #include <lib/zx/vmo.h>
#include <stdio.h> #include <stdio.h>
...@@ -43,37 +45,29 @@ NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path, ...@@ -43,37 +45,29 @@ NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path,
FilePath computed_path; FilePath computed_path;
base::PathService::Get(DIR_SOURCE_ROOT, &computed_path); base::PathService::Get(DIR_SOURCE_ROOT, &computed_path);
computed_path = computed_path.AppendASCII("lib").Append(components[0]); computed_path = computed_path.AppendASCII("lib").Append(components[0]);
base::File library(computed_path,
base::File::FLAG_OPEN | base::File::FLAG_READ);
if (!library.IsValid()) {
if (error) {
error->message = base::StringPrintf(
"open library: %s",
base::File::ErrorToString(library.error_details()).c_str());
}
return nullptr;
}
zx::vmo vmo; // Use fdio_open_fd (a Fuchsia-specific API) here so we can pass the
zx_status_t status = fdio_get_vmo_clone(library.GetPlatformFile(), // appropriate FS rights flags to request executability.
vmo.reset_and_get_address()); // TODO(1018538): Teach base::File about FLAG_EXECUTE on Fuchsia, and then
// use it here instead of using fdio_open_fd() directly.
base::ScopedFD fd;
zx_status_t status = fdio_open_fd(
computed_path.value().c_str(),
fuchsia::io::OPEN_RIGHT_READABLE | fuchsia::io::OPEN_RIGHT_EXECUTABLE,
base::ScopedFD::Receiver(fd).get());
if (status != ZX_OK) { if (status != ZX_OK) {
if (error) { if (error) {
error->message = base::StringPrintf("fdio_get_vmo_clone: %s", error->message =
zx_status_get_string(status)); base::StringPrintf("fdio_open_fd: %s", zx_status_get_string(status));
} }
return nullptr; return nullptr;
} }
// VMOs must be marked as exec-capable to be mapped executable in dlopen_vmo, zx::vmo vmo;
// and fdio_get_vmo_clone shouldn't be marking every VMO it returns status = fdio_get_vmo_exec(fd.get(), vmo.reset_and_get_address());
// exec-capable. So we should mark it as exec-capable here.
// In the fullness of time, this invalid handle should be swapped out for a
// ZX_RSRC_KIND_VMEX handle.
status = vmo.replace_as_executable(zx::handle(), &vmo);
if (status != ZX_OK) { if (status != ZX_OK) {
if (error) { if (error) {
error->message = base::StringPrintf("zx_vmo_replace_as_executable: %s", error->message = base::StringPrintf("fdio_get_vmo_exec: %s",
zx_status_get_string(status)); zx_status_get_string(status));
} }
return nullptr; return nullptr;
......
...@@ -12,7 +12,7 @@ import("//build/config/sysroot.gni") ...@@ -12,7 +12,7 @@ import("//build/config/sysroot.gni")
# if different than |target_name|. # if different than |target_name|.
# binary: The executable target which should be launched. # binary: The executable target which should be launched.
# manifest: A path to the manifest that will be used. # manifest: A path to the manifest that will be used.
# "testonly" targets default to using //build/config/fuchsia/tests.cmx. # "testonly" targets default to using //build/config/fuchsia/tests-with-exec.cmx.
# Non-test targets must explicitly specify a |manifest|. # Non-test targets must explicitly specify a |manifest|.
# deps: Additional targets to build and include in the package (optional). # deps: Additional targets to build and include in the package (optional).
template("fuchsia_package") { template("fuchsia_package") {
...@@ -27,7 +27,10 @@ template("fuchsia_package") { ...@@ -27,7 +27,10 @@ template("fuchsia_package") {
if (!defined(manifest)) { if (!defined(manifest)) {
assert(testonly == true) assert(testonly == true)
manifest = "//build/config/fuchsia/tests.cmx"
# TODO(1019938): switch the default to tests.cmx which doesn't request
# the deprecated-ambient-replace-as-executable feature.
manifest = "//build/config/fuchsia/tests-with-exec.cmx"
} }
} }
assert(defined(pkg.binary)) assert(defined(pkg.binary))
......
{
"sandbox": {
"features": [
"deprecated-ambient-replace-as-executable",
"isolated-persistent-storage",
"isolated-temp",
"root-ssl-certificates",
"vulkan"
],
"dev": [
"null",
"zero"
],
"services": [
"fuchsia.device.NameProvider",
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.fonts.Provider",
"fuchsia.logger.Log",
"fuchsia.logger.LogSink",
"fuchsia.media.Audio",
"fuchsia.media.drm.Widevine",
"fuchsia.mediacodec.CodecFactory",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.sys.Environment",
"fuchsia.sys.Launcher",
"fuchsia.sys.Loader",
"fuchsia.sysmem.Allocator",
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input.ImeVisibilityService",
"fuchsia.web.ContextProvider"
]
}
}
{ {
"sandbox": { "sandbox": {
"features": [ "features": [
"deprecated-ambient-replace-as-executable",
"isolated-persistent-storage", "isolated-persistent-storage",
"isolated-temp", "isolated-temp",
"root-ssl-certificates", "root-ssl-certificates",
......
{ {
"sandbox": { "sandbox": {
"features": [ "features": [
"deprecated-ambient-replace-as-executable",
"hub", "hub",
"isolated-persistent-storage", "isolated-persistent-storage",
"isolated-temp" "isolated-temp"
......
{ {
"sandbox": { "sandbox": {
"features": [
"deprecated-ambient-replace-as-executable"
],
"services": [ "services": [
"chromium.cast.ApplicationConfigManager", "chromium.cast.ApplicationConfigManager",
"fuchsia.deprecatedtimezone.Timezone", "fuchsia.deprecatedtimezone.Timezone",
......
{ {
"sandbox": { "sandbox": {
"features": [ "features": [
"isolated-persistent-storage", "isolated-persistent-storage"
"deprecated-ambient-replace-as-executable"
], ],
"services": [ "services": [
"fuchsia.deprecatedtimezone.Timezone", "fuchsia.deprecatedtimezone.Timezone",
......
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