Skip to content

Commit

Permalink
Bug 1653659 - Part 2: Add support for Wasm sandboxing hunspell. r=fir…
Browse files Browse the repository at this point in the history
…efox-build-system-reviewers,dmajor

Differential Revision: https://phabricator.services.mozilla.com/D86063
  • Loading branch information
deian committed Jan 13, 2021
1 parent 6543a57 commit 400fbf1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions browser/installer/package-manifest.in
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
#ifdef MOZ_WASM_SANDBOXING_OGG
@BINPATH@/@DLL_PREFIX@oggwasm@DLL_SUFFIX@
#endif
#ifdef MOZ_WASM_SANDBOXING_HUNSPELL
@BINPATH@/@DLL_PREFIX@hunspellwasm@DLL_SUFFIX@
#endif

; We don't have a complete view of which dlls to expect when doing an artifact
; build because we haven't run the relevant parts of configure, so we guess
Expand Down
15 changes: 15 additions & 0 deletions extensions/spellcheck/hunspell/glue/RLBoxHunspell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/Assertions.h"
#ifdef MOZ_WASM_SANDBOXING_HUNSPELL
# include "mozilla/ipc/LibrarySandboxPreload.h"
#endif
#include "RLBoxHunspell.h"
#include "mozHunspellRLBoxGlue.h"
#include "mozHunspellRLBoxHost.h"
Expand Down Expand Up @@ -34,7 +37,19 @@ static tainted_hunspell<char*> allocStrInSandbox(
RLBoxHunspell::RLBoxHunspell(const nsAutoCString& affpath,
const nsAutoCString& dpath)
: mHandle(nullptr) {
#ifdef MOZ_WASM_SANDBOXING_HUNSPELL
// Firefox preloads the library externally to ensure we won't be stopped by
// the content sandbox
const bool external_loads_exist = true;
// See Bug 1606981: In some environments allowing stdio in the wasm sandbox
// fails as the I/O redirection involves querying meta-data of file
// descriptors. This querying fails in some environments.
const bool allow_stdio = false;
mSandbox.create_sandbox(mozilla::ipc::GetSandboxedHunspellPath().get(),
external_loads_exist, allow_stdio);
#else
mSandbox.create_sandbox();
#endif

// Add the aff and dict files to allow list
mozHunspellCallbacks::AllowFile(affpath);
Expand Down
9 changes: 8 additions & 1 deletion extensions/spellcheck/hunspell/src/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

UNIFIED_SOURCES += [
all_sources = [
'../glue/mozHunspellRLBoxSandbox.cpp',
'affentry.cxx',
'affixmgr.cxx',
Expand All @@ -16,6 +16,13 @@ UNIFIED_SOURCES += [
'suggestmgr.cxx',
]

UNIFIED_SOURCES += all_sources

if CONFIG['MOZ_WASM_SANDBOXING_HUNSPELL']:
SANDBOXED_WASM_LIBRARY_NAME = 'hunspellwasm'
WASM_DEFINES['MOZILLA_CLIENT'] = True
WASM_SOURCES += all_sources

DEFINES['HUNSPELL_STATIC'] = True

FINAL_LIBRARY = 'xul'
Expand Down
10 changes: 10 additions & 0 deletions ipc/glue/LibrarySandboxPreload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ nsAutoCString GetSandboxedOggPath() {
nsLiteralCString(MOZ_DLL_PREFIX "oggwasm" MOZ_DLL_SUFFIX));
}

nsAutoCString GetSandboxedHunspellPath() {
return GetSandboxedPath(
nsLiteralCString(MOZ_DLL_PREFIX "hunspellwasm" MOZ_DLL_SUFFIX));
}

PRLibrary* PreloadLibrary(const nsAutoCString& path) {
PRLibSpec libSpec;
libSpec.type = PR_LibSpec_Pathname;
Expand All @@ -75,6 +80,11 @@ void PreloadSandboxedDynamicLibraries() {
MOZ_CRASH("Library preload failure: Failed to load libogg\n");
}
# endif
# if defined(MOZ_WASM_SANDBOXING_HUNSPELL)
if (!PreloadLibrary(GetSandboxedHunspellPath())) {
MOZ_CRASH("Library preload failure: Failed to load libhunspell\n");
}
# endif
#endif
}

Expand Down
1 change: 1 addition & 0 deletions ipc/glue/LibrarySandboxPreload.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace mozilla {
namespace ipc {
nsAutoCString GetSandboxedGraphitePath();
nsAutoCString GetSandboxedOggPath();
nsAutoCString GetSandboxedHunspellPath();
void PreloadSandboxedDynamicLibraries();
} // namespace ipc
} // namespace mozilla
Expand Down
1 change: 1 addition & 0 deletions toolkit/moz.configure
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,7 @@ def wasm_sandboxing_libraries():
return (
"graphite",
"ogg",
"hunspell",
)


Expand Down

0 comments on commit 400fbf1

Please sign in to comment.