kobako 0.29.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +552 -10
- data/Cargo.lock +595 -139
- data/README.md +126 -564
- data/ROADMAP.md +3 -2
- data/crates/kobako-runtime/CHANGELOG.md +488 -1
- data/crates/kobako-runtime/Cargo.toml +73 -15
- data/crates/kobako-runtime/README.md +11 -4
- data/crates/kobako-runtime/src/cred.rs +124 -0
- data/crates/kobako-runtime/src/dispatch.rs +5 -6
- data/crates/kobako-runtime/src/endpoint/buffer.rs +301 -0
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +292 -0
- data/crates/kobako-runtime/src/endpoint/invoke.rs +181 -0
- data/crates/kobako-runtime/src/endpoint.rs +267 -0
- data/crates/kobako-runtime/src/errno.rs +391 -0
- data/crates/kobako-runtime/src/error.rs +31 -10
- data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +82 -0
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +274 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +248 -0
- data/crates/kobako-runtime/src/filesystem/bind.rs +2857 -0
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +89 -0
- data/crates/kobako-runtime/src/filesystem/overlay/inode.rs +106 -0
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +263 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +128 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +238 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +135 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +54 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +316 -739
- data/crates/kobako-runtime/src/filesystem/overlay.rs +2627 -1154
- data/crates/kobako-runtime/src/filesystem/pipe.rs +224 -0
- data/crates/kobako-runtime/src/filesystem/rdir.rs +84 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +107 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +22 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +1997 -0
- data/crates/kobako-runtime/src/filesystem/wrap.rs +208 -0
- data/crates/kobako-runtime/src/filesystem.rs +25 -388
- data/crates/kobako-runtime/src/fork.rs +96 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +46 -0
- data/crates/kobako-runtime/src/lib.rs +27 -11
- data/crates/kobako-runtime/src/limits.rs +195 -0
- data/crates/kobako-runtime/src/locking/seqlock.rs +66 -0
- data/crates/kobako-runtime/src/locking.rs +228 -0
- data/crates/kobako-runtime/src/memcg.rs +383 -0
- data/crates/kobako-runtime/src/mount.rs +86 -101
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +179 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +160 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +2733 -0
- data/crates/kobako-runtime/src/net/lookup.rs +285 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
- data/crates/kobako-runtime/src/net/reactor.rs +531 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
- data/crates/kobako-runtime/src/net/resolv.rs +227 -0
- data/crates/kobako-runtime/src/net/socket.rs +870 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
- data/crates/kobako-runtime/src/net/tls.rs +58 -0
- data/crates/kobako-runtime/src/net/transport.rs +279 -0
- data/crates/kobako-runtime/src/net/udp.rs +1003 -0
- data/crates/kobako-runtime/src/net.rs +42 -0
- data/crates/kobako-runtime/src/network/builder.rs +177 -0
- data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
- data/crates/kobako-runtime/src/network.rs +551 -0
- data/crates/kobako-runtime/src/policy.rs +16 -0
- data/crates/kobako-runtime/src/profile.rs +37 -16
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +311 -0
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/security/hooks.rs +242 -0
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +601 -0
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +162 -0
- data/crates/kobako-runtime/src/vfs/dentry.rs +1466 -0
- data/crates/kobako-runtime/src/vfs/file.rs +1911 -0
- data/crates/kobako-runtime/src/vfs/inode.rs +425 -0
- data/crates/kobako-runtime/src/vfs/kern_path.rs +213 -0
- data/crates/kobako-runtime/src/vfs/mount.rs +60 -0
- data/crates/kobako-runtime/src/vfs/namei.rs +5837 -0
- data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +116 -0
- data/crates/kobako-runtime/src/vfs/path.rs +64 -0
- data/crates/kobako-runtime/src/vfs/readdir.rs +163 -0
- data/crates/kobako-runtime/src/vfs/stat.rs +293 -0
- data/crates/kobako-runtime/src/vfs/super_block.rs +126 -0
- data/crates/kobako-runtime/src/vfs/utimes.rs +299 -0
- data/crates/kobako-runtime/src/vfs.rs +63 -0
- data/crates/kobako-runtime/src/wait.rs +356 -0
- data/crates/kobako-transport/CHANGELOG.md +39 -2
- data/crates/kobako-transport/Cargo.toml +3 -3
- data/crates/kobako-transport/README.md +8 -8
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +49 -30
- data/crates/kobako-transport/src/envelope/call.rs +37 -9
- data/crates/kobako-transport/src/envelope/compile_reply.rs +2 -2
- data/crates/kobako-transport/src/envelope/error_record.rs +24 -3
- data/crates/kobako-transport/src/envelope/fault.rs +2 -2
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +11 -11
- data/crates/kobako-transport/src/envelope/preamble.rs +34 -31
- data/crates/kobako-transport/src/envelope/reply.rs +29 -29
- data/crates/kobako-transport/src/envelope/request.rs +2 -2
- data/crates/kobako-transport/src/envelope/run.rs +1 -1
- data/crates/kobako-transport/src/envelope/unsupported.rs +12 -12
- data/crates/kobako-transport/src/envelope.rs +15 -10
- data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
- data/crates/kobako-wasmtime/Cargo.toml +35 -15
- data/crates/kobako-wasmtime/README.md +11 -6
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +19 -47
- data/crates/kobako-wasmtime/src/ambient.rs +33 -19
- data/crates/kobako-wasmtime/src/cache.rs +28 -20
- data/crates/kobako-wasmtime/src/config.rs +59 -60
- data/crates/kobako-wasmtime/src/driver.rs +63 -145
- data/crates/kobako-wasmtime/src/exports.rs +147 -32
- data/crates/kobako-wasmtime/src/guest.rs +44 -0
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +48 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +7 -7
- data/crates/kobako-wasmtime/src/invocation.rs +93 -51
- data/crates/kobako-wasmtime/src/lib.rs +6 -7
- data/crates/kobako-wasmtime/src/limiter.rs +52 -211
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +70 -57
- data/crates/kobako-wasmtime/src/preview1/differential.rs +137 -27
- data/crates/kobako-wasmtime/src/preview1/errno.rs +90 -233
- data/crates/kobako-wasmtime/src/preview1/fd.rs +1301 -522
- data/crates/kobako-wasmtime/src/preview1/memory.rs +126 -150
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +192 -0
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +1989 -708
- data/crates/kobako-wasmtime/src/preview1/path.rs +181 -365
- data/crates/kobako-wasmtime/src/preview1/poll.rs +345 -173
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -25
- data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +147 -0
- data/crates/kobako-wasmtime/src/preview1.rs +471 -416
- data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
- data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
- data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +31 -16
- data/crates/kobako-wasmtime/src/wasi.rs +238 -93
- data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
- data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
- data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
- data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
- data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
- data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
- data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
- data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
- data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +35 -27
- data/ext/kobako/src/escape.rs +98 -0
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +36 -16
- data/ext/kobako/src/filesystem/ruby.rs +689 -0
- data/ext/kobako/src/filesystem.rs +217 -0
- data/ext/kobako/src/gvl.rs +306 -0
- data/ext/kobako/src/lib.rs +64 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +591 -0
- data/ext/kobako/src/runtime/bridge.rs +31 -30
- data/ext/kobako/src/runtime/snapshot.rs +5 -5
- data/ext/kobako/src/runtime.rs +221 -138
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +19 -7
- data/lib/kobako/catalog/flags.rb +4 -6
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +9 -31
- data/lib/kobako/catalog/mount.rb +12 -12
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +7 -21
- data/lib/kobako/catalog/snippets.rb +10 -25
- data/lib/kobako/catalog.rb +4 -1
- data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
- data/lib/kobako/codec/decoder.rb +12 -12
- data/lib/kobako/codec/ext_types.rb +5 -7
- data/lib/kobako/codec/handle_walk.rb +5 -47
- data/lib/kobako/codec/nesting.rb +7 -7
- data/lib/kobako/codec/value_budget.rb +134 -42
- data/lib/kobako/codec.rb +1 -1
- data/lib/kobako/context.rb +28 -15
- data/lib/kobako/errors.rb +15 -12
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +53 -15
- data/lib/kobako/handle.rb +2 -2
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/payload/arguments.rb +2 -2
- data/lib/kobako/pool.rb +47 -25
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +113 -56
- data/lib/kobako/sandbox_options.rb +41 -107
- data/lib/kobako/snippet/bytecode.rb +1 -1
- data/lib/kobako/snippet/source.rb +1 -1
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +10 -10
- data/lib/kobako/transport/exposure.rb +28 -17
- data/lib/kobako/transport/reflection.rb +28 -11
- data/lib/kobako/transport/run.rb +13 -28
- data/lib/kobako/transport/yielder.rb +3 -10
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +38 -0
- data/release-please-config.json +16 -0
- data/sig/core/thread.rbs +6 -0
- data/sig/kobako/catalog/extensions.rbs +5 -3
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +2 -4
- data/sig/kobako/catalog/mount.rbs +3 -5
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +1 -5
- data/sig/kobako/catalog/snippets.rbs +3 -5
- data/sig/kobako/catalog.rbs +1 -1
- data/sig/kobako/codec/boundary.rbs +9 -0
- data/sig/kobako/codec/decoder.rbs +1 -1
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/nesting.rbs +2 -2
- data/sig/kobako/codec/value_budget.rbs +48 -5
- data/sig/kobako/codec.rbs +1 -2
- data/sig/kobako/context.rbs +4 -2
- data/sig/kobako/errors.rbs +4 -4
- data/sig/kobako/filesystem.rbs +38 -15
- data/sig/kobako/guest_yielder.rbs +1 -1
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/payload/arguments.rbs +1 -1
- data/sig/kobako/pool.rbs +8 -4
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +22 -7
- data/sig/kobako/sandbox_options.rbs +29 -38
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/dispatcher.rbs +2 -2
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +3 -5
- data/sig/kobako/transport/reflection.rbs +12 -2
- data/sig/kobako/transport/run.rbs +3 -5
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +2 -2
- data/sig/kobako.rbs +13 -0
- metadata +131 -34
- data/crates/kobako-runtime/src/filesystem/directory/spelling.rs +0 -194
- data/crates/kobako-runtime/src/filesystem/directory.rs +0 -1082
- data/crates/kobako-runtime/src/filesystem/memory.rs +0 -1100
- data/crates/kobako-runtime/src/filesystem/overlay/exclusive.rs +0 -88
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -60
- data/crates/kobako-runtime/src/filesystem/temporary.rs +0 -167
- data/crates/kobako-wasmtime/src/capture.rs +0 -96
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -167
- data/crates/kobako-wasmtime/src/dispatch.rs +0 -125
- data/crates/kobako-wasmtime/src/guest_mem.rs +0 -271
- data/crates/kobako-wasmtime/src/io.rs +0 -89
- data/crates/kobako-wasmtime/src/preview1/args.rs +0 -60
- data/crates/kobako-wasmtime/src/preview1/beneath.rs +0 -188
- data/crates/kobako-wasmtime/tests/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/guest_file.rs +0 -1054
- data/crates/kobako-wasmtime/tests/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/escape.rs +0 -53
- data/ext/kobako/src/runtime/filesystem/ruby.rs +0 -400
- data/ext/kobako/src/runtime/filesystem.rs +0 -236
- data/ext/kobako/src/runtime/gvl.rs +0 -112
- data/lib/kobako/constant_name.rb +0 -8
- data/sig/kobako/codec/utils.rbs +0 -9
- data/sig/kobako/constant_name.rbs +0 -3
- /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
# neutral value types (`Snapshot`, `Trap`, `SetupError`, ...), the
|
|
6
6
|
# dispatch / yield re-entry traits a frontend supplies, and the Grants
|
|
7
7
|
# a frontend hands each invocation, the Mount and the Filesystems it
|
|
8
|
-
# places.
|
|
8
|
+
# places. It also holds what every engine would answer alike: the host
|
|
9
|
+
# ABI endpoint and the VFS. Engine implementations (`kobako-wasmtime`) and host frontends
|
|
9
10
|
# (the Ruby ext) meet on this surface, so the engine stays swappable.
|
|
10
|
-
# `cap-std` confines
|
|
11
|
+
# `cap-std` confines a Bind to its host directory.
|
|
11
12
|
#
|
|
12
13
|
# Self-contained by design: the Ruby gem ships this crate without the
|
|
13
14
|
# `crates/` workspace manifest, so no `workspace = true` inheritance
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
|
|
16
17
|
[package]
|
|
17
18
|
name = "kobako-runtime"
|
|
18
|
-
version = "0.
|
|
19
|
+
version = "0.21.0"
|
|
19
20
|
edition = "2021"
|
|
20
21
|
description = "Engine-neutral host runtime contract for embedding kobako Wasm guests."
|
|
21
22
|
license = "Apache-2.0"
|
|
@@ -23,29 +24,86 @@ repository = "https://github.com/elct9620/kobako"
|
|
|
23
24
|
readme = "README.md"
|
|
24
25
|
keywords = ["wasm", "mruby", "sandbox", "wasi"]
|
|
25
26
|
categories = ["wasm", "virtualization"]
|
|
27
|
+
# The tests reach files only this repository holds, so a copy of the crate
|
|
28
|
+
# taken to customize builds without them.
|
|
29
|
+
exclude = ["tests/"]
|
|
26
30
|
|
|
27
|
-
# The fixed tier: the
|
|
31
|
+
# The fixed tier: the Envelope this contract routes and attributes
|
|
28
32
|
# through. The version pin rides the linked release group; the path keeps
|
|
29
33
|
# in-tree builds (and the Ruby gem, which ships both crates) resolving
|
|
30
34
|
# locally.
|
|
31
35
|
[dependencies]
|
|
32
|
-
kobako-transport = { version = "0.
|
|
33
|
-
# cap-std resolves
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
36
|
+
kobako-transport = { version = "0.21.0", path = "../kobako-transport" }
|
|
37
|
+
# cap-std resolves each name a Bind is asked beneath its host directory,
|
|
38
|
+
# on every host Windows included. The VFS already hands one name and
|
|
39
|
+
# follows links itself; cap-std still refuses a `..` or a symbolic link
|
|
40
|
+
# leading out, should anything else hand one. 4.0.3 is the first release
|
|
41
|
+
# whose trailing-slash lookup keeps that refusal (GHSA-hp8f-xmx4-4qrg).
|
|
37
42
|
cap-std = "4.0.3"
|
|
38
|
-
# cap-fs-ext opens a
|
|
39
|
-
#
|
|
43
|
+
# cap-fs-ext opens a Bind's directory by name without following a link,
|
|
44
|
+
# as no Filesystem follows one the runtime has not.
|
|
40
45
|
cap-fs-ext = "4.0.3"
|
|
46
|
+
# Bounds the host directories a Bind keeps open for walks.
|
|
47
|
+
lru = "0.19.0"
|
|
48
|
+
# Reads the host's own addresses, which the ruleset counts as local
|
|
49
|
+
# whatever registry classes them, on POSIX and Windows alike.
|
|
50
|
+
if-addrs = "0.15.0"
|
|
51
|
+
# Reads a host the guest names as wasmtime-wasi's lookup does, with the URL
|
|
52
|
+
# host parser: an address in any IPv4 spelling, or a name as its A-label, so
|
|
53
|
+
# the hooks and the endpoints judge one spelling of it.
|
|
54
|
+
url = "2.5.8"
|
|
55
|
+
# The outbound seam: hyper's HTTP/1 client, which binds to no async
|
|
56
|
+
# runtime, driven on kobako's reactor and dialing only through kobako's
|
|
57
|
+
# connector; no default feature, so it decompresses and redirects nothing.
|
|
58
|
+
hyper = { version = "1.12.0", features = ["client", "http1"] }
|
|
59
|
+
http-body = "1.0.1"
|
|
60
|
+
http-body-util = "0.1.3"
|
|
61
|
+
bytes = "1.11.1"
|
|
62
|
+
# The I/O traits tokio-rustls reads and writes through; no feature, so no
|
|
63
|
+
# runtime comes with them.
|
|
64
|
+
tokio = { version = "1.54.1", default-features = false }
|
|
65
|
+
tokio-rustls = { version = "0.26.4", default-features = false, features = ["ring", "tls12"] }
|
|
66
|
+
# TLS ends on the host, over ring, trusting the OS's own store, so a revoked or
|
|
67
|
+
# added root follows the host's patches rather than a kobako release.
|
|
68
|
+
rustls = { version = "0.23.46", default-features = false, features = ["std", "ring", "tls12"] }
|
|
69
|
+
rustls-platform-verifier = "0.7.1"
|
|
70
|
+
# The reactor: one thread waits on every host socket without blocking on
|
|
71
|
+
# any, on epoll, kqueue, or IOCP alike, and on the socket macOS answers a
|
|
72
|
+
# name lookup through.
|
|
73
|
+
mio = { version = "1.2.0", features = ["os-poll", "os-ext", "net"] }
|
|
74
|
+
# Sets the socket options a guest asks for, such as SO_KEEPALIVE, on the host
|
|
75
|
+
# socket it dials, on POSIX and Windows alike; std sets only a few.
|
|
76
|
+
socket2 = { version = "0.6.3", features = ["all"] }
|
|
77
|
+
# Zeroes a credential's value as it drops, so a freed page holds no secret.
|
|
78
|
+
zeroize = "1.9.1"
|
|
41
79
|
|
|
42
|
-
# rustix switches a
|
|
80
|
+
# rustix switches a Bind's file to append mode for one write, so the
|
|
43
81
|
# host places it at the file's end in one step; std cannot set file flags.
|
|
82
|
+
# It also opens a Bind's directory several names deep with Linux's
|
|
83
|
+
# openat2, holds a file by O_PATH before reopening it through /proc,
|
|
84
|
+
# and reads which macOS release confines such an open, and which errno a
|
|
85
|
+
# host call failed with, which std names no kind for.
|
|
44
86
|
[target.'cfg(unix)'.dependencies]
|
|
45
|
-
rustix = { version = "1.1.4", features = ["fs"] }
|
|
87
|
+
rustix = { version = "1.1.4", features = ["fs", "system"] }
|
|
88
|
+
|
|
89
|
+
# rustix reads which Winsock error a host call failed with, which std
|
|
90
|
+
# names no kind for, as on POSIX. windows-sys asks Windows for a name through
|
|
91
|
+
# GetAddrInfoExW, whose query a lookup can cancel, which std cannot.
|
|
92
|
+
[target.'cfg(windows)'.dependencies]
|
|
93
|
+
rustix = { version = "1.1.4", features = ["net"] }
|
|
94
|
+
windows-sys = { version = "0.61.2", features = ["Win32_Foundation", "Win32_Networking_WinSock", "Win32_System_IO"] }
|
|
95
|
+
|
|
96
|
+
# simple-dns reads and writes the DNS messages the Linux stub resolver sends
|
|
97
|
+
# to a name server, its compression loops refused; it pulls in only bitflags.
|
|
98
|
+
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
|
|
99
|
+
simple-dns = "0.13.1"
|
|
46
100
|
|
|
47
101
|
# libc asks macOS for the name a directory stores, which a Mount's Policy
|
|
48
|
-
# judges in place of a spelling the host folds
|
|
49
|
-
#
|
|
102
|
+
# judges in place of a spelling the host folds, and opens a directory
|
|
103
|
+
# beneath another with O_NOFOLLOW_ANY; rustix has neither.
|
|
50
104
|
[target.'cfg(target_os = "macos")'.dependencies]
|
|
51
105
|
libc = "0.2.191"
|
|
106
|
+
|
|
107
|
+
# libc makes the syscalls tests/linux_baseline holds the VFS to.
|
|
108
|
+
[target.'cfg(target_os = "linux")'.dev-dependencies]
|
|
109
|
+
libc = "0.2.191"
|
|
@@ -14,9 +14,16 @@ engine stays swappable.
|
|
|
14
14
|
| `snapshot` | each invocation's `Completion` (outcome or trap), both output `Capture`s, and `Usage` |
|
|
15
15
|
| `error` | the neutral failure types: `Trap`, `SetupError`, and `InvokeError` over both |
|
|
16
16
|
| `profile` | the isolation `Profile` a runtime declares |
|
|
17
|
-
| `grant` | the `Grant`
|
|
18
|
-
| `mount` | the `Mount` at a guest path, and the `
|
|
19
|
-
| `
|
|
17
|
+
| `grant` | the `Grant` each invocation receives, the supported `GrantKind`s, and the `Policy` |
|
|
18
|
+
| `mount` | the `Mount` at a guest path, its `Access`, and the `MountRequest` its `Policy` judges |
|
|
19
|
+
| `network` | a named `Network` entry: its endpoints, credentials, and `Policies` |
|
|
20
|
+
| `net` | the `Namespace` behind the guest's sockets and HTTP, and its seams |
|
|
21
|
+
| `filesystem` | the `FileSystemType` and `InodeOperations` traits and the three kinds kobako ships |
|
|
22
|
+
| `endpoint` | the host side of the kobako ABI, over the `GuestInstance` an engine implements |
|
|
23
|
+
| `vfs` | the walk, open files, and pipes each engine's calls reach, whichever ABI it encodes |
|
|
24
|
+
| `security` | the security modules an invocation registers: kobako's own rules and each Mount's `Policy` |
|
|
25
|
+
| `sched` | the `Blocking` a frontend registers, how its threads wait |
|
|
26
|
+
| `wait` | the wait queues and `do_poll` a host-side wait sleeps on |
|
|
20
27
|
| `dispatch` / `yielder` | the `DispatchHandler` and `Yielder` traits a frontend supplies for guest→host dispatch and block-yield re-entry |
|
|
21
28
|
|
|
22
29
|
Engine implementations such as `kobako-wasmtime` implement `Runtime`.
|
|
@@ -29,7 +36,7 @@ Add the crate to an engine or a frontend that speaks the contract.
|
|
|
29
36
|
|
|
30
37
|
```toml
|
|
31
38
|
[dependencies]
|
|
32
|
-
kobako-runtime = "0.
|
|
39
|
+
kobako-runtime = "0.21.0" # x-release-please-version
|
|
33
40
|
```
|
|
34
41
|
|
|
35
42
|
## License
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
//! Who a call is made for, as Linux's `struct cred`: the security modules
|
|
2
|
+
//! registered for the caller, the memory charged on its behalf, the profile it
|
|
3
|
+
//! sees entries through, and its mount namespace. The hooks that ask its
|
|
4
|
+
//! modules live with the security framework, as `security/security.c` holds
|
|
5
|
+
//! them apart from `kernel/cred.c`.
|
|
6
|
+
|
|
7
|
+
use std::sync::Arc;
|
|
8
|
+
|
|
9
|
+
use crate::memcg::MemoryBudget;
|
|
10
|
+
use crate::profile::Profile;
|
|
11
|
+
use crate::security::SecurityOperations;
|
|
12
|
+
use crate::vfs::{MntNamespace, VfsMount};
|
|
13
|
+
|
|
14
|
+
/// Who a call is made for, holding the security modules registered for it, as
|
|
15
|
+
/// `cred->security` holds a Landlock domain, and the memory budget the host
|
|
16
|
+
/// charges what it holds on the caller's behalf to, which every Cred restricted
|
|
17
|
+
/// from it shares, as a task's memory cgroup does. Its profile decides what the
|
|
18
|
+
/// caller sees of an entry, as `cred->user_ns` decides the owner `cp_new_stat`
|
|
19
|
+
/// reports. Its mount namespace says which mount stands on which name, as a
|
|
20
|
+
/// task's `nsproxy` holds one beside its credentials.
|
|
21
|
+
pub struct Cred {
|
|
22
|
+
security: Vec<Arc<dyn SecurityOperations>>,
|
|
23
|
+
memory: Arc<MemoryBudget>,
|
|
24
|
+
profile: Profile,
|
|
25
|
+
mnt_ns: Arc<MntNamespace>,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// One no module is registered for, which this crate's tests make calls as.
|
|
29
|
+
#[cfg(test)]
|
|
30
|
+
impl Default for Cred {
|
|
31
|
+
fn default() -> Self {
|
|
32
|
+
Self {
|
|
33
|
+
security: Vec::new(),
|
|
34
|
+
memory: MemoryBudget::new(None),
|
|
35
|
+
profile: Profile::Hermetic,
|
|
36
|
+
mnt_ns: Arc::default(),
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
impl Cred {
|
|
42
|
+
/// One with `security` registered, its memory unbounded.
|
|
43
|
+
pub(crate) fn new(security: Vec<Arc<dyn SecurityOperations>>) -> Arc<Self> {
|
|
44
|
+
Self::within(security, MemoryBudget::new(None))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// One with `security` registered, charging what is held on its behalf to
|
|
48
|
+
/// `memory`, seeing entries as the hermetic profile does until told
|
|
49
|
+
/// otherwise.
|
|
50
|
+
pub(crate) fn within(
|
|
51
|
+
security: Vec<Arc<dyn SecurityOperations>>,
|
|
52
|
+
memory: Arc<MemoryBudget>,
|
|
53
|
+
) -> Arc<Self> {
|
|
54
|
+
Arc::new(Self {
|
|
55
|
+
security,
|
|
56
|
+
memory,
|
|
57
|
+
profile: Profile::Hermetic,
|
|
58
|
+
mnt_ns: Arc::default(),
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// This Cred with `more` modules registered after its own, sharing the
|
|
63
|
+
/// memory held on its behalf, as `landlock_restrict_self` adds a domain.
|
|
64
|
+
pub(crate) fn with_modules(&self, more: Vec<Arc<dyn SecurityOperations>>) -> Arc<Self> {
|
|
65
|
+
let mut security = self.security.clone();
|
|
66
|
+
security.extend(more);
|
|
67
|
+
Arc::new(Self {
|
|
68
|
+
security,
|
|
69
|
+
memory: self.memory.clone(),
|
|
70
|
+
profile: self.profile,
|
|
71
|
+
mnt_ns: self.mnt_ns.clone(),
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// This Cred with `mnt_ns` as its mount namespace, as a task that unshared
|
|
76
|
+
/// its mounts holds a namespace of its own.
|
|
77
|
+
pub(crate) fn with_mnt_ns(&self, mnt_ns: Arc<MntNamespace>) -> Arc<Self> {
|
|
78
|
+
Arc::new(Self {
|
|
79
|
+
security: self.security.clone(),
|
|
80
|
+
memory: self.memory.clone(),
|
|
81
|
+
profile: self.profile,
|
|
82
|
+
mnt_ns,
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/// The mount a walk from the root of `mnt` stands on: the topmost of those
|
|
87
|
+
/// stacked over that root, as Linux's `topmost_overmount` answers.
|
|
88
|
+
pub fn topmost_overmount(&self, mnt: &Arc<VfsMount>) -> Arc<VfsMount> {
|
|
89
|
+
self.mnt_ns.topmost_overmount(mnt)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// This Cred seeing entries as `profile` does, as a task's credentials
|
|
93
|
+
/// carry the user namespace its stat is reported in.
|
|
94
|
+
pub fn with_profile(&self, profile: Profile) -> Arc<Self> {
|
|
95
|
+
Arc::new(Self {
|
|
96
|
+
security: self.security.clone(),
|
|
97
|
+
memory: self.memory.clone(),
|
|
98
|
+
profile,
|
|
99
|
+
mnt_ns: self.mnt_ns.clone(),
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// The security modules registered for the caller, in the order they are
|
|
104
|
+
/// asked.
|
|
105
|
+
pub(crate) fn modules(&self) -> &[Arc<dyn SecurityOperations>] {
|
|
106
|
+
&self.security
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// Which mount stands on which name for the caller.
|
|
110
|
+
pub(crate) fn mnt_ns(&self) -> &MntNamespace {
|
|
111
|
+
&self.mnt_ns
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// The isolation profile the caller runs under.
|
|
115
|
+
pub fn profile(&self) -> Profile {
|
|
116
|
+
self.profile
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// The budget the caller's memory is charged to, which a Wasm Driver also
|
|
120
|
+
/// charges the guest's own growth to.
|
|
121
|
+
pub fn memory_budget(&self) -> &Arc<MemoryBudget> {
|
|
122
|
+
&self.memory
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
//! Engine-neutral guest→host dispatch contract, free of any `magnus`
|
|
2
2
|
//! dependency.
|
|
3
3
|
//!
|
|
4
|
-
//! The runtime decodes the
|
|
4
|
+
//! The runtime decodes the Envelope and hands a handler the routed
|
|
5
5
|
//! `Call` — target, method, block flag, and the payload bytes it never
|
|
6
|
-
//! reads — then expects a `
|
|
6
|
+
//! reads — then expects a `CallReply` back. What the handler *is* — a Ruby
|
|
7
7
|
//! Proc, a Rust closure — is the frontend's concern; the runtime only sees
|
|
8
|
-
//! this trait.
|
|
9
|
-
//! it.
|
|
8
|
+
//! this trait.
|
|
10
9
|
|
|
11
10
|
use crate::yielder::Yielder;
|
|
12
|
-
use kobako_transport::envelope::{Call,
|
|
11
|
+
use kobako_transport::envelope::{Call, CallReply};
|
|
13
12
|
|
|
14
13
|
/// Host-side handler for a guest→host dispatch.
|
|
15
14
|
///
|
|
@@ -24,7 +23,7 @@ use kobako_transport::envelope::{Call, Reply};
|
|
|
24
23
|
/// The `Call` borrows the buffer the runtime decoded, so a handler passes
|
|
25
24
|
/// the payload onward without copying it first.
|
|
26
25
|
pub trait DispatchHandler: Send + Sync {
|
|
27
|
-
fn dispatch(&self, call: Call<'_>, yielder: &mut dyn Yielder) -> Option<
|
|
26
|
+
fn dispatch(&self, call: Call<'_>, yielder: &mut dyn Yielder) -> Option<CallReply>;
|
|
28
27
|
|
|
29
28
|
/// Whether the host gave up on this invocation, as when one of its
|
|
30
29
|
/// callbacks raised something meant for the host rather than the
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
//! Guest linear-memory I/O for the ABI's list handoffs, whether the
|
|
2
|
+
//! invocation body or an upcall drives one.
|
|
3
|
+
//!
|
|
4
|
+
//! Every list the ABI carries is named by a return area: two little-endian
|
|
5
|
+
//! u32, its place then its length, 4-byte aligned, as the Canonical ABI lays
|
|
6
|
+
//! a `list<u8>` out. The shared steps answer an error kind, and each caller
|
|
7
|
+
//! words it, because depth decides what the same problem means: before the
|
|
8
|
+
//! export call it is a `Trap`, inside a callback it is a wire failure the
|
|
9
|
+
//! guest receives.
|
|
10
|
+
|
|
11
|
+
use kobako_transport::abi::MAX_MESSAGE_LEN;
|
|
12
|
+
|
|
13
|
+
use super::{GuestInstance, RUNTIME_INCOMPATIBLE, SANDBOX_RUNTIME_NOT_KOBAKO};
|
|
14
|
+
|
|
15
|
+
// The size-limit messages here and in the endpoint name the cap as 16 MiB, so
|
|
16
|
+
// moving the cap fails the build until they are reworded with it.
|
|
17
|
+
const _: () = assert!(MAX_MESSAGE_LEN == 16 << 20);
|
|
18
|
+
|
|
19
|
+
/// The bytes of a return area: a u32 place, then a u32 length.
|
|
20
|
+
const RETURN_AREA_SIZE: usize = 8;
|
|
21
|
+
|
|
22
|
+
/// The alignment a return area keeps, its u32's own.
|
|
23
|
+
const RETURN_AREA_ALIGN: usize = 4;
|
|
24
|
+
|
|
25
|
+
/// Why a host write into guest memory failed.
|
|
26
|
+
pub(super) enum WriteError<F> {
|
|
27
|
+
TooLarge,
|
|
28
|
+
/// The allocator or the memory is missing or mistyped; carries the
|
|
29
|
+
/// message for it.
|
|
30
|
+
Incompatible(&'static str),
|
|
31
|
+
Trapped(F),
|
|
32
|
+
OutOfBounds,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// Why a host read of a guest-named buffer failed.
|
|
36
|
+
pub(super) enum ReadError {
|
|
37
|
+
TooLarge,
|
|
38
|
+
OutOfBounds,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// Take room from the guest's `cabi_realloc` and copy `bytes` into it,
|
|
42
|
+
/// answering the room's address.
|
|
43
|
+
pub(super) fn alloc_and_write<G: GuestInstance>(
|
|
44
|
+
guest: &mut G,
|
|
45
|
+
bytes: &[u8],
|
|
46
|
+
) -> Result<u32, WriteError<G::Fault>> {
|
|
47
|
+
let len = checked_payload_len(bytes.len()).map_err(|_| WriteError::TooLarge)?;
|
|
48
|
+
if guest.memory().is_none() {
|
|
49
|
+
return Err(WriteError::Incompatible(SANDBOX_RUNTIME_NOT_KOBAKO));
|
|
50
|
+
}
|
|
51
|
+
// Fresh room for a `list<u8>`, which the Canonical ABI aligns to 1.
|
|
52
|
+
let ptr = guest
|
|
53
|
+
.realloc(0, 0, 1, len as u32)
|
|
54
|
+
.ok_or(WriteError::Incompatible(RUNTIME_INCOMPATIBLE))?
|
|
55
|
+
.map_err(WriteError::Trapped)?;
|
|
56
|
+
let memory = guest
|
|
57
|
+
.memory()
|
|
58
|
+
.ok_or(WriteError::Incompatible(SANDBOX_RUNTIME_NOT_KOBAKO))?;
|
|
59
|
+
let range = guest_buffer_range(ptr as usize, bytes.len(), memory.len())
|
|
60
|
+
.map_err(|_| WriteError::OutOfBounds)?;
|
|
61
|
+
memory[range].copy_from_slice(bytes);
|
|
62
|
+
Ok(ptr)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Write `bytes` into the guest and name them in the return area at `ret`.
|
|
66
|
+
/// A return area the guest cannot hold is refused before the guest gives
|
|
67
|
+
/// room for the answer; memory only grows, so it still holds after.
|
|
68
|
+
pub(super) fn lower_list<G: GuestInstance>(
|
|
69
|
+
guest: &mut G,
|
|
70
|
+
bytes: &[u8],
|
|
71
|
+
ret: u32,
|
|
72
|
+
) -> Result<(), WriteError<G::Fault>> {
|
|
73
|
+
let mem_size = guest
|
|
74
|
+
.memory()
|
|
75
|
+
.ok_or(WriteError::Incompatible(SANDBOX_RUNTIME_NOT_KOBAKO))?
|
|
76
|
+
.len();
|
|
77
|
+
let area = return_area_range(ret as usize, mem_size).map_err(|_| WriteError::OutOfBounds)?;
|
|
78
|
+
let ptr = alloc_and_write(guest, bytes)?;
|
|
79
|
+
let memory = guest
|
|
80
|
+
.memory()
|
|
81
|
+
.ok_or(WriteError::Incompatible(SANDBOX_RUNTIME_NOT_KOBAKO))?;
|
|
82
|
+
// The write has already held the length to the payload cap.
|
|
83
|
+
memory[area.start..area.start + 4].copy_from_slice(&ptr.to_le_bytes());
|
|
84
|
+
memory[area.start + 4..area.end].copy_from_slice(&(bytes.len() as u32).to_le_bytes());
|
|
85
|
+
Ok(())
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// Copy out the list the return area at `ret` names; a length past the
|
|
89
|
+
/// 16 MiB cap is refused before the list is touched.
|
|
90
|
+
pub(super) fn lift_list(memory: &[u8], ret: u32) -> Result<Vec<u8>, ReadError> {
|
|
91
|
+
let area = return_area_range(ret as usize, memory.len()).map_err(|_| ReadError::OutOfBounds)?;
|
|
92
|
+
let word =
|
|
93
|
+
|at: usize| u32::from_le_bytes(memory[at..at + 4].try_into().expect("a u32's width"));
|
|
94
|
+
let (ptr, len) = (word(area.start), word(area.start + 4));
|
|
95
|
+
read_buffer(memory, ptr as usize, len as usize)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// Copy out the buffer the guest names; a length past the 16 MiB cap is
|
|
99
|
+
/// refused before memory is touched.
|
|
100
|
+
pub(super) fn read_buffer(data: &[u8], ptr: usize, len: usize) -> Result<Vec<u8>, ReadError> {
|
|
101
|
+
if len > MAX_MESSAGE_LEN {
|
|
102
|
+
return Err(ReadError::TooLarge);
|
|
103
|
+
}
|
|
104
|
+
let range = guest_buffer_range(ptr, len, data.len()).map_err(|_| ReadError::OutOfBounds)?;
|
|
105
|
+
Ok(data[range].to_vec())
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/// Every host write boundary routes its length through here, so the
|
|
109
|
+
/// wire-violation reason is uniform.
|
|
110
|
+
pub(super) fn checked_payload_len(len: usize) -> Result<i32, &'static str> {
|
|
111
|
+
if len > MAX_MESSAGE_LEN {
|
|
112
|
+
return Err("payload exceeds the 16 MiB limit");
|
|
113
|
+
}
|
|
114
|
+
// The cap above sits below `i32::MAX`, so this conversion cannot wrap.
|
|
115
|
+
i32::try_from(len).map_err(|_| "payload exceeds the 16 MiB limit")
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// The bytes of guest memory a `(ptr, len)` names.
|
|
119
|
+
fn guest_buffer_range(
|
|
120
|
+
ptr: usize,
|
|
121
|
+
len: usize,
|
|
122
|
+
mem_size: usize,
|
|
123
|
+
) -> Result<core::ops::Range<usize>, &'static str> {
|
|
124
|
+
let end = ptr.checked_add(len).ok_or("ptr + len overflow")?;
|
|
125
|
+
if end > mem_size {
|
|
126
|
+
return Err("range exceeds Sandbox memory size");
|
|
127
|
+
}
|
|
128
|
+
Ok(ptr..end)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// The bytes of guest memory the return area at `ret` covers, refused off
|
|
132
|
+
/// its alignment or reaching past memory.
|
|
133
|
+
fn return_area_range(ret: usize, mem_size: usize) -> Result<core::ops::Range<usize>, &'static str> {
|
|
134
|
+
if !ret.is_multiple_of(RETURN_AREA_ALIGN) {
|
|
135
|
+
return Err("the return area is not aligned");
|
|
136
|
+
}
|
|
137
|
+
guest_buffer_range(ret, RETURN_AREA_SIZE, mem_size)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#[cfg(test)]
|
|
141
|
+
mod tests {
|
|
142
|
+
use super::{checked_payload_len, guest_buffer_range, lift_list, lower_list, MAX_MESSAGE_LEN};
|
|
143
|
+
use crate::endpoint::{Calls, GuestInstance};
|
|
144
|
+
use crate::error::Trap;
|
|
145
|
+
|
|
146
|
+
/// 64 bytes of guest memory whose allocator counts the room it gave.
|
|
147
|
+
#[derive(Default)]
|
|
148
|
+
struct Counted {
|
|
149
|
+
memory: Vec<u8>,
|
|
150
|
+
given: u32,
|
|
151
|
+
calls: Calls<String>,
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
impl GuestInstance for Counted {
|
|
155
|
+
type Fault = String;
|
|
156
|
+
|
|
157
|
+
fn calls(&mut self) -> &mut Calls<String> {
|
|
158
|
+
&mut self.calls
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
fn memory(&mut self) -> Option<&mut [u8]> {
|
|
162
|
+
Some(&mut self.memory)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fn realloc(&mut self, _: u32, _: u32, _: u32, _: u32) -> Option<Result<u32, String>> {
|
|
166
|
+
self.given += 1;
|
|
167
|
+
Some(Ok(32))
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
fn downcall(&mut self, _ptr: i32, _len: i32) -> Option<Result<u32, String>> {
|
|
171
|
+
None
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
fn cap_trap_of(_fault: &String) -> Option<Trap> {
|
|
175
|
+
None
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// @behavior WE-059
|
|
180
|
+
#[test]
|
|
181
|
+
fn a_transfer_of_nothing_or_at_the_cap_is_admitted() {
|
|
182
|
+
assert_eq!(
|
|
183
|
+
(checked_payload_len(0), checked_payload_len(MAX_MESSAGE_LEN)),
|
|
184
|
+
(Ok(0), Ok(MAX_MESSAGE_LEN as i32)),
|
|
185
|
+
"0 bytes and MAX_MESSAGE_LEN bytes through checked_payload_len must be admitted"
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// @behavior WE-060
|
|
190
|
+
#[test]
|
|
191
|
+
fn a_transfer_past_the_cap_is_refused() {
|
|
192
|
+
assert!(
|
|
193
|
+
checked_payload_len(MAX_MESSAGE_LEN + 1).is_err()
|
|
194
|
+
&& checked_payload_len(usize::MAX).is_err(),
|
|
195
|
+
"one byte past MAX_MESSAGE_LEN and usize::MAX through checked_payload_len must be \
|
|
196
|
+
refused"
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// @behavior WE-061
|
|
201
|
+
#[test]
|
|
202
|
+
fn a_guest_buffer_is_read_half_open() {
|
|
203
|
+
assert_eq!(
|
|
204
|
+
guest_buffer_range(10, 5, 100),
|
|
205
|
+
Ok(10..15),
|
|
206
|
+
"5 bytes at 10 in 100 bytes of memory through guest_buffer_range must answer 10..15"
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// @behavior WE-062
|
|
211
|
+
#[test]
|
|
212
|
+
fn a_buffer_of_no_length_is_read_at_any_pointer_inside_memory() {
|
|
213
|
+
assert_eq!(
|
|
214
|
+
(guest_buffer_range(0, 0, 0), guest_buffer_range(42, 0, 100)),
|
|
215
|
+
(Ok(0..0), Ok(42..42)),
|
|
216
|
+
"no bytes at 0 in no memory and at 42 in 100 bytes through guest_buffer_range must \
|
|
217
|
+
answer an empty range there"
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// @behavior WE-063
|
|
222
|
+
#[test]
|
|
223
|
+
fn a_pointer_and_length_that_overflow_are_refused() {
|
|
224
|
+
assert!(
|
|
225
|
+
guest_buffer_range(usize::MAX, 1, usize::MAX).is_err(),
|
|
226
|
+
"1 byte at usize::MAX through guest_buffer_range must be refused"
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// @behavior WE-064
|
|
231
|
+
#[test]
|
|
232
|
+
fn a_buffer_ending_past_memory_is_refused() {
|
|
233
|
+
assert_eq!(
|
|
234
|
+
(guest_buffer_range(10, 100, 50).is_err(), guest_buffer_range(0, 50, 50)),
|
|
235
|
+
(true, Ok(0..50)),
|
|
236
|
+
"100 bytes at 10 in 50 bytes of memory through guest_buffer_range must be refused, and \
|
|
237
|
+
50 bytes at 0 admitted"
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/// 64 bytes of memory holding `answer` at 32, named by a return area at 8.
|
|
242
|
+
fn memory_naming(answer: &[u8]) -> Vec<u8> {
|
|
243
|
+
let mut memory = vec![0; 64];
|
|
244
|
+
memory[8..12].copy_from_slice(&32u32.to_le_bytes());
|
|
245
|
+
memory[12..16].copy_from_slice(&(answer.len() as u32).to_le_bytes());
|
|
246
|
+
memory[32..32 + answer.len()].copy_from_slice(answer);
|
|
247
|
+
memory
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// @behavior WE-092
|
|
251
|
+
#[test]
|
|
252
|
+
fn a_return_area_names_its_answers_place_then_its_length() {
|
|
253
|
+
let memory = memory_naming(b"answer");
|
|
254
|
+
|
|
255
|
+
assert_eq!(
|
|
256
|
+
lift_list(&memory, 8).ok(),
|
|
257
|
+
Some(b"answer".to_vec()),
|
|
258
|
+
"a return area holding 32 then 6, read by the host, must answer the 6 bytes at 32"
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// @behavior WE-093
|
|
263
|
+
#[test]
|
|
264
|
+
fn a_return_area_off_its_alignment_or_past_memory_is_refused() {
|
|
265
|
+
let mut memory = memory_naming(b"answer");
|
|
266
|
+
// At 1, off alignment, the same place and length the area at 8 holds.
|
|
267
|
+
memory.copy_within(8..16, 1);
|
|
268
|
+
|
|
269
|
+
assert!(
|
|
270
|
+
[1, 60, u32::MAX - 3]
|
|
271
|
+
.iter()
|
|
272
|
+
.all(|&ret| lift_list(&memory, ret).is_err()),
|
|
273
|
+
"a return area at 1 (unaligned, naming a list inside memory), 60 (past 64 bytes), or \
|
|
274
|
+
u32::MAX - 3, read by the host, must be refused"
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// @behavior WE-093
|
|
279
|
+
#[test]
|
|
280
|
+
fn an_answer_for_a_return_area_the_guest_cannot_hold_is_never_copied() {
|
|
281
|
+
let mut guest = Counted {
|
|
282
|
+
memory: vec![0; 64],
|
|
283
|
+
..Counted::default()
|
|
284
|
+
};
|
|
285
|
+
let refused = [1, 60, u32::MAX - 3]
|
|
286
|
+
.iter()
|
|
287
|
+
.all(|&ret| lower_list(&mut guest, b"answer", ret).is_err());
|
|
288
|
+
|
|
289
|
+
assert_eq!(
|
|
290
|
+
(
|
|
291
|
+
refused,
|
|
292
|
+
guest.given,
|
|
293
|
+
guest.memory.iter().all(|&byte| byte == 0)
|
|
294
|
+
),
|
|
295
|
+
(true, 0, true),
|
|
296
|
+
"an answer written for a return area at 1 (unaligned), 60 (past 64 bytes), or \
|
|
297
|
+
u32::MAX - 3 must be refused before the guest's allocator gives it room or any byte \
|
|
298
|
+
lands in guest memory"
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
}
|