diff --git a/src/core/asm.c b/src/core/asm.c index 4afc7a28..171754c0 100644 --- a/src/core/asm.c +++ b/src/core/asm.c @@ -1064,6 +1064,7 @@ JANET_CORE_FN(cfun_asm, "The syntax for the assembly can be found on the Janet website, and should correspond\n" "to the return value of disasm. Will throw an\n" "error on invalid assembly.") { + janet_sandbox_assert(JANET_SANDBOX_ASM); janet_fixarity(argc, 1); JanetAssembleResult res; res = janet_asm(argv[0], 0); @@ -1094,6 +1095,7 @@ JANET_CORE_FN(cfun_disasm, "* :sourcemap - a mapping of each bytecode instruction to a line and column in the source file.\n" "* :environments - an internal mapping of which enclosing functions are referenced for bindings.\n" "* :defs - other function definitions that this function may instantiate.\n") { + janet_sandbox_assert(JANET_SANDBOX_ASM); janet_arity(argc, 1, 2); JanetFunction *f = janet_getfunction(argv, 0); if (argc == 2) { diff --git a/src/core/compile.c b/src/core/compile.c index 152b95cb..45a252a7 100644 --- a/src/core/compile.c +++ b/src/core/compile.c @@ -1156,6 +1156,7 @@ JANET_CORE_FN(cfun_compile, "struct with keys :line, :column, and :error if compilation fails. " "If a `lints` array is given, linting messages will be appended to the array. " "Each message will be a tuple of the form `(level line col message)`.") { + janet_sandbox_assert(JANET_SANDBOX_COMPILE); janet_arity(argc, 1, 4); JanetTable *env = (argc > 1 && !janet_checktype(argv[1], JANET_NIL)) ? janet_gettable(argv, 1) : janet_vm.fiber->env; diff --git a/src/core/corelib.c b/src/core/corelib.c index e2450269..c67d3b9e 100644 --- a/src/core/corelib.c +++ b/src/core/corelib.c @@ -746,7 +746,9 @@ typedef struct SandboxOption { static const SandboxOption sandbox_options[] = { {"all", JANET_SANDBOX_ALL}, + {"asm", JANET_SANDBOX_ASM}, {"chroot", JANET_SANDBOX_CHROOT}, + {"compile", JANET_SANDBOX_COMPILE}, {"env", JANET_SANDBOX_ENV}, {"ffi", JANET_SANDBOX_FFI}, {"ffi-define", JANET_SANDBOX_FFI_DEFINE}, @@ -764,6 +766,7 @@ static const SandboxOption sandbox_options[] = { {"sandbox", JANET_SANDBOX_SANDBOX}, {"signal", JANET_SANDBOX_SIGNAL}, {"subprocess", JANET_SANDBOX_SUBPROCESS}, + {"threads", JANET_SANDBOX_THREADS}, {NULL, 0} }; @@ -772,7 +775,9 @@ JANET_CORE_FN(janet_core_sandbox, "Disable feature sets to prevent the interpreter from using certain system resources. " "Once a feature is disabled, there is no way to re-enable it. Capabilities can be:\n\n" "* :all - disallow all (except IO to stdout, stderr, and stdin)\n" + "* :asm - disallow calling `asm` and `disasm` functions.\n" "* :chroot - disallow calling `os/posix-chroot`\n" + "* :compile - disallow calling `compile`. This will disable a lot of functionality, such as `eval`.\n" "* :env - disallow reading and write env variables\n" "* :ffi - disallow FFI (recommended if disabling anything else)\n" "* :ffi-define - disallow loading new FFI modules and binding new functions\n" @@ -789,7 +794,8 @@ JANET_CORE_FN(janet_core_sandbox, "* :net-listen - disallow accepting inbound network connections\n" "* :sandbox - disallow calling this function\n" "* :signal - disallow adding or removing signal handlers\n" - "* :subprocess - disallow running subprocesses") { + "* :subprocess - disallow running subprocesses\n" + "* :threads - disallow spawning threads with `ev/thread`. Certain helper threads may still be spawned.") { uint32_t flags = 0; for (int32_t i = 0; i < argc; i++) { JanetKeyword kw = janet_getkeyword(argv, i); diff --git a/src/core/ev.c b/src/core/ev.c index 9d2e8fd3..250ab728 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -3178,6 +3178,7 @@ JANET_CORE_FN(cfun_ev_thread, "* `:t` - set the task-id of the new thread to value. The task-id is passed in messages to the supervisor channel.\n" "* `:a` - don't copy abstract registry to new thread (performance optimization)\n" "* `:c` - don't copy cfunction registry to new thread (performance optimization)") { + janet_sandbox_assert(JANET_SANDBOX_THREADS); janet_arity(argc, 1, 4); Janet value = argc >= 2 ? argv[1] : janet_wrap_nil(); if (!janet_checktype(argv[0], JANET_FUNCTION)) janet_getfiber(argv, 0); diff --git a/src/include/janet.h b/src/include/janet.h index 8514ed1d..9f47d8ef 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -2005,6 +2005,9 @@ JANET_API void janet_stacktrace_ext(JanetFiber *fiber, Janet err, const char *pr #define JANET_SANDBOX_FFI (JANET_SANDBOX_FFI_DEFINE | JANET_SANDBOX_FFI_USE | JANET_SANDBOX_FFI_JIT) #define JANET_SANDBOX_FS (JANET_SANDBOX_FS_WRITE | JANET_SANDBOX_FS_READ | JANET_SANDBOX_FS_TEMP) #define JANET_SANDBOX_NET (JANET_SANDBOX_NET_CONNECT | JANET_SANDBOX_NET_LISTEN) +#define JANET_SANDBOX_COMPILE 32768 +#define JANET_SANDBOX_ASM 65536 +#define JANET_SANDBOX_THREADS 131072 #define JANET_SANDBOX_ALL (UINT32_MAX) JANET_API void janet_sandbox(uint32_t flags); JANET_API void janet_sandbox_assert(uint32_t forbidden_flags);