kobako 0.30.0 → 0.32.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/.githooks/linux-tests.sh +29 -0
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +460 -0
- data/Cargo.lock +868 -447
- data/README.md +43 -4
- data/ROADMAP.md +1 -2
- data/crates/kobako-runtime/CHANGELOG.md +309 -0
- data/crates/kobako-runtime/Cargo.toml +58 -11
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +136 -0
- data/crates/kobako-runtime/src/dispatch.rs +4 -5
- data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
- data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
- data/crates/kobako-runtime/src/endpoint.rs +137 -36
- 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 +300 -22
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +101 -29
- data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +52 -34
- data/crates/kobako-runtime/src/filesystem/bind.rs +812 -447
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +11 -16
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +120 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +578 -388
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +14 -50
- data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +219 -173
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +8 -3
- data/crates/kobako-runtime/src/fork.rs +319 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +4 -2
- data/crates/kobako-runtime/src/lib.rs +18 -7
- data/crates/kobako-runtime/src/limits.rs +171 -0
- data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
- data/crates/kobako-runtime/src/locking.rs +518 -113
- data/crates/kobako-runtime/src/memcg.rs +306 -0
- data/crates/kobako-runtime/src/mount.rs +37 -9
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +219 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +180 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +3165 -0
- data/crates/kobako-runtime/src/net/lookup.rs +385 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1368 -0
- data/crates/kobako-runtime/src/net/reactor.rs +626 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +280 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +519 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +542 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +218 -0
- data/crates/kobako-runtime/src/net/resolv.rs +251 -0
- data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
- data/crates/kobako-runtime/src/net/socket.rs +869 -0
- data/crates/kobako-runtime/src/net/task.rs +223 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1840 -0
- data/crates/kobako-runtime/src/net/tls.rs +120 -0
- data/crates/kobako-runtime/src/net/transport.rs +304 -0
- data/crates/kobako-runtime/src/net/udp.rs +1105 -0
- data/crates/kobako-runtime/src/net.rs +45 -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 +29 -144
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +338 -51
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +125 -209
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
- data/crates/kobako-runtime/src/vfs/dentry.rs +210 -117
- data/crates/kobako-runtime/src/vfs/file.rs +243 -248
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +62 -53
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +1162 -818
- data/crates/kobako-runtime/src/vfs/namespace.rs +245 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
- data/crates/kobako-runtime/src/vfs/path.rs +6 -6
- data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
- data/crates/kobako-runtime/src/vfs/stat.rs +248 -23
- data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
- data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
- data/crates/kobako-runtime/src/vfs.rs +10 -6
- data/crates/kobako-runtime/src/wait.rs +381 -0
- data/crates/kobako-transport/CHANGELOG.md +38 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +3 -4
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
- data/crates/kobako-transport/src/envelope/call.rs +32 -4
- data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
- data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
- data/crates/kobako-transport/src/envelope/reply.rs +27 -27
- data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
- data/crates/kobako-transport/src/envelope.rs +13 -8
- data/crates/kobako-wasmtime/CHANGELOG.md +208 -0
- data/crates/kobako-wasmtime/Cargo.toml +47 -7
- data/crates/kobako-wasmtime/README.md +4 -3
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +18 -37
- data/crates/kobako-wasmtime/src/ambient.rs +43 -19
- data/crates/kobako-wasmtime/src/cache/unix.rs +95 -0
- data/crates/kobako-wasmtime/src/cache/windows.rs +359 -0
- data/crates/kobako-wasmtime/src/cache.rs +106 -113
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +80 -82
- data/crates/kobako-wasmtime/src/exports.rs +143 -17
- data/crates/kobako-wasmtime/src/guest.rs +12 -6
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +42 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
- data/crates/kobako-wasmtime/src/invocation.rs +91 -15
- data/crates/kobako-wasmtime/src/lib.rs +7 -3
- data/crates/kobako-wasmtime/src/limiter.rs +130 -12
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +305 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +9 -20
- data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
- data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
- data/crates/kobako-wasmtime/src/preview1/fd.rs +347 -312
- data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +335 -388
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +255 -125
- data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +131 -51
- 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 +4319 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1587 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +328 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +257 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +88 -28
- data/crates/kobako-wasmtime/src/waits.rs +59 -0
- data/crates/kobako-wasmtime/src/wasi.rs +291 -81
- 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/wasi_snapshot_preview1.witx +13 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +6 -2
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/escape.rs +404 -0
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +34 -32
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +158 -170
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +71 -23
- data/ext/kobako/src/fork.rs +72 -0
- data/ext/kobako/src/gvl.rs +729 -0
- data/ext/kobako/src/handoff.rs +490 -0
- data/ext/kobako/src/lib.rs +74 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +593 -0
- data/ext/kobako/src/pinned_value.rs +44 -0
- data/ext/kobako/src/runtime/bridge.rs +58 -50
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +272 -163
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +14 -2
- data/lib/kobako/catalog/flags.rb +3 -5
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +14 -32
- data/lib/kobako/catalog/mount.rb +11 -3
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +5 -19
- data/lib/kobako/catalog/snippets.rb +3 -18
- data/lib/kobako/catalog.rb +3 -0
- data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
- data/lib/kobako/codec/decoder.rb +5 -5
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/state.rb +2 -18
- data/lib/kobako/codec/value_budget.rb +133 -41
- data/lib/kobako/codec.rb +6 -7
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +18 -18
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +10 -3
- data/lib/kobako/fork.rb +42 -0
- data/lib/kobako/handle.rb +2 -3
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +73 -35
- data/lib/kobako/sandbox_options.rb +42 -109
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +6 -6
- data/lib/kobako/transport/exposure.rb +26 -15
- data/lib/kobako/transport/reflection.rb +21 -4
- data/lib/kobako/transport/run.rb +8 -23
- data/lib/kobako/transport/yielder.rb +2 -9
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/usage.rb +4 -2
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +8 -4
- data/release-please-config.json +15 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +2 -2
- data/sig/kobako/catalog/mount.rbs +3 -1
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +0 -4
- data/sig/kobako/catalog/snippets.rbs +0 -2
- data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/state.rbs +0 -4
- data/sig/kobako/codec/value_budget.rbs +48 -5
- data/sig/kobako/codec.rbs +2 -2
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -7
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/fork.rbs +17 -0
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +10 -2
- data/sig/kobako/sandbox_options.rbs +29 -40
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +2 -4
- data/sig/kobako/transport/reflection.rbs +10 -0
- data/sig/kobako/transport/run.rbs +0 -2
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +1 -1
- data/sig/kobako.rbs +13 -0
- metadata +97 -37
- data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
- data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
- data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
- data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
- data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
- data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
- data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
- data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
- data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
- data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
- data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
- data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
- data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/escape.rs +0 -67
- data/ext/kobako/src/runtime/gvl.rs +0 -147
- data/ext/kobako/src/runtime/pinned_value.rs +0 -31
- data/lib/kobako/constant_name.rb +0 -8
- data/lib/kobako/pool.rb +0 -140
- data/sig/kobako/constant_name.rbs +0 -3
- data/sig/kobako/pool.rbs +0 -42
|
@@ -11,14 +11,16 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
11
11
|
use kobako_runtime::filesystem::Bind;
|
|
12
12
|
use kobako_runtime::filesystem::Filesystem;
|
|
13
13
|
use kobako_runtime::filesystem::{
|
|
14
|
-
FileOperations, FileSystemType, FileType,
|
|
15
|
-
|
|
14
|
+
FileOperations, FileSystemType, FileType, InodeOperations, Kiocb, Kstat, Lookup, OpenHow,
|
|
15
|
+
Overlay, RenameFlag, Tmpfs,
|
|
16
16
|
};
|
|
17
17
|
use kobako_runtime::grant::Grant;
|
|
18
|
-
use kobako_runtime::mount::{Access, Mount,
|
|
18
|
+
use kobako_runtime::mount::{Access, Mount, MountRequest};
|
|
19
|
+
use kobako_runtime::policy::Policy;
|
|
19
20
|
use kobako_runtime::profile::Profile;
|
|
20
|
-
use kobako_runtime::security::
|
|
21
|
-
use kobako_runtime::vfs::{self, Dentry, Inode, Path,
|
|
21
|
+
use kobako_runtime::security::{prepare_creds, SecurityOperations, SecurityPath};
|
|
22
|
+
use kobako_runtime::vfs::{self, Dentry, Inode, Path, PATH_MAX};
|
|
23
|
+
use kobako_runtime::Errno;
|
|
22
24
|
use wasmtime::{Instance, Module, Store};
|
|
23
25
|
|
|
24
26
|
use crate::cache::load_engine;
|
|
@@ -42,14 +44,14 @@ fn host<F: FileSystemType>(filesystem: &Arc<F>) -> Path {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
/// The names `filesystem`'s root holds, as the host lists them.
|
|
45
|
-
fn host_entries<F: FileSystemType>(filesystem: &Arc<F>) -> Result<Vec<String>,
|
|
47
|
+
fn host_entries<F: FileSystemType>(filesystem: &Arc<F>) -> Result<Vec<String>, Errno> {
|
|
46
48
|
let mount = Mount::new(
|
|
47
49
|
"/data",
|
|
48
50
|
Filesystem::new(filesystem.clone()).expect("the instance must stand"),
|
|
49
51
|
Access::ReadWrite,
|
|
50
52
|
)
|
|
51
53
|
.expect("/data is a guest path");
|
|
52
|
-
let mut root = vfs::File::root(mount.mnt(), &
|
|
54
|
+
let mut root = vfs::File::root(mount.mnt(), &prepare_creds(&[], None))?;
|
|
53
55
|
let mut names = Vec::new();
|
|
54
56
|
root.llseek(2, vfs::Whence::Set)?;
|
|
55
57
|
root.iterate_dir(&mut vfs::DirContext::new(0, &mut |emit| {
|
|
@@ -66,10 +68,9 @@ const ERRNO_MFILE: i32 = 33;
|
|
|
66
68
|
const ERRNO_INVAL: i32 = 28;
|
|
67
69
|
const ERRNO_IO: i32 = 29;
|
|
68
70
|
const ERRNO_ISDIR: i32 = 31;
|
|
69
|
-
#[cfg(unix)]
|
|
70
71
|
const ERRNO_LOOP: i32 = 32;
|
|
71
72
|
const ERRNO_NOENT: i32 = 44;
|
|
72
|
-
const
|
|
73
|
+
const ERRNO_OVERFLOW: i32 = 61;
|
|
73
74
|
const ERRNO_NOTDIR: i32 = 54;
|
|
74
75
|
const ERRNO_NOTEMPTY: i32 = 55;
|
|
75
76
|
const ERRNO_NOSPC: i32 = 51;
|
|
@@ -91,6 +92,7 @@ const PROBE_WAT: &str = r#"
|
|
|
91
92
|
(import "wasi_snapshot_preview1" "path_filestat_get" (func $stat (param i32 i32 i32 i32 i32) (result i32)))
|
|
92
93
|
(import "wasi_snapshot_preview1" "fd_filestat_get" (func $fstat (param i32 i32) (result i32)))
|
|
93
94
|
(import "wasi_snapshot_preview1" "fd_read" (func $read (param i32 i32 i32 i32) (result i32)))
|
|
95
|
+
(import "wasi_snapshot_preview1" "fd_close" (func $close (param i32) (result i32)))
|
|
94
96
|
(import "wasi_snapshot_preview1" "fd_write" (func $write (param i32 i32 i32 i32) (result i32)))
|
|
95
97
|
(import "wasi_snapshot_preview1" "path_remove_directory" (func $rmdir (param i32 i32 i32) (result i32)))
|
|
96
98
|
(import "wasi_snapshot_preview1" "path_rename" (func $rename (param i32 i32 i32 i32 i32 i32) (result i32)))
|
|
@@ -152,11 +154,12 @@ const PROBE_WAT: &str = r#"
|
|
|
152
154
|
(data (i32.const 700) "file.txt")
|
|
153
155
|
(data (i32.const 720) "../file.txt")
|
|
154
156
|
|
|
155
|
-
|
|
157
|
+
;; The name of the preopen at the descriptor into 512.
|
|
158
|
+
(func (export "preopen_name") (param $fd i32) (result i32)
|
|
156
159
|
(local $errno i32)
|
|
157
|
-
(local.set $errno (call $prestat (
|
|
160
|
+
(local.set $errno (call $prestat (local.get $fd) (i32.const 256)))
|
|
158
161
|
(if (local.get $errno) (then (return (local.get $errno))))
|
|
159
|
-
(call $prestat_name (
|
|
162
|
+
(call $prestat_name (local.get $fd) (i32.const 512) (i32.load (i32.const 260))))
|
|
160
163
|
|
|
161
164
|
;; Open the path read-only and read it into 512.
|
|
162
165
|
(func (export "read_file") (param $path i32) (param $len i32) (result i32)
|
|
@@ -166,6 +169,14 @@ const PROBE_WAT: &str = r#"
|
|
|
166
169
|
(if (local.get $errno) (then (return (local.get $errno))))
|
|
167
170
|
(call $read (i32.load (i32.const 128)) (i32.const 64) (i32.const 1) (i32.const 132)))
|
|
168
171
|
|
|
172
|
+
;; Open the path read-only and close it again.
|
|
173
|
+
(func (export "open_close") (param $path i32) (param $len i32) (result i32)
|
|
174
|
+
(local $errno i32)
|
|
175
|
+
(local.set $errno (call $open (i32.const 3) (i32.const 0) (local.get $path) (local.get $len)
|
|
176
|
+
(i32.const 0) (i64.const 2) (i64.const 0) (i32.const 0) (i32.const 128)))
|
|
177
|
+
(if (local.get $errno) (then (return (local.get $errno))))
|
|
178
|
+
(call $close (i32.load (i32.const 128))))
|
|
179
|
+
|
|
169
180
|
;; Open the path asking no right, with the given oflags, and read from it.
|
|
170
181
|
(func (export "read_unasked") (param $path i32) (param $len i32) (param $oflags i32) (result i32)
|
|
171
182
|
(local $errno i32)
|
|
@@ -445,7 +456,6 @@ const THROUGH_MISSING: (i32, i32) = (760, 19);
|
|
|
445
456
|
const OUT_OF_FILE: (i32, i32) = (780, 11);
|
|
446
457
|
const FILE_AS_DIRECTORY: (i32, i32) = (800, 9);
|
|
447
458
|
const NEW_AS_DIRECTORY: (i32, i32) = (820, 8);
|
|
448
|
-
#[cfg(unix)]
|
|
449
459
|
const THROUGH_FILE: (i32, i32) = (860, 12);
|
|
450
460
|
const DIR_DOT: (i32, i32) = (880, 5);
|
|
451
461
|
const DIR_DOT_DOT: (i32, i32) = (890, 6);
|
|
@@ -453,16 +463,12 @@ const BENEATH_FILE: (i32, i32) = (900, 10);
|
|
|
453
463
|
const MOVED: (i32, i32) = (920, 5);
|
|
454
464
|
const DIR: (i32, i32) = (930, 3);
|
|
455
465
|
const MISSING_DOT: (i32, i32) = (940, 9);
|
|
456
|
-
#[cfg(unix)]
|
|
457
466
|
const LINK_DOT: (i32, i32) = (970, 10);
|
|
458
|
-
#[cfg(unix)]
|
|
459
467
|
const OUT_OF_LINK: (i32, i32) = (990, 20);
|
|
460
468
|
const HOLDING_NUL: (i32, i32) = (1010, 9);
|
|
461
469
|
const NOT_UTF8: (i32, i32) = (1440, 1);
|
|
462
470
|
const DIR_FILE: (i32, i32) = (1030, 12);
|
|
463
|
-
#[cfg(unix)]
|
|
464
471
|
const DIR_AS_DIRECTORY: (i32, i32) = (1050, 4);
|
|
465
|
-
#[cfg(unix)]
|
|
466
472
|
const GONE_AS_DIRECTORY: (i32, i32) = (1060, 5);
|
|
467
473
|
const ERRNO_EXIST: i32 = 20;
|
|
468
474
|
const OFLAGS_EXCL: i32 = 1 << 2;
|
|
@@ -477,14 +483,14 @@ fn build_how(set: impl FnOnce(&mut OpenHow)) -> OpenHow {
|
|
|
477
483
|
fn grant(
|
|
478
484
|
filesystem: Arc<dyn FileSystemType>,
|
|
479
485
|
access: Access,
|
|
480
|
-
policy: Option<Arc<dyn Policy
|
|
486
|
+
policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
|
|
481
487
|
) -> Grant {
|
|
482
488
|
let mount = Mount::new(
|
|
483
|
-
"/
|
|
489
|
+
"/",
|
|
484
490
|
Filesystem::new(filesystem).expect("the instance must stand"),
|
|
485
491
|
access,
|
|
486
492
|
)
|
|
487
|
-
.expect("/
|
|
493
|
+
.expect("/ is a guest path");
|
|
488
494
|
Grant::Mount(match policy {
|
|
489
495
|
Some(policy) => mount.with_policy(policy),
|
|
490
496
|
None => mount,
|
|
@@ -504,51 +510,31 @@ impl Guest {
|
|
|
504
510
|
|
|
505
511
|
/// A guest holding at most `open_file_limit` descriptors at once.
|
|
506
512
|
fn with_open_file_limit(open_file_limit: Option<usize>, grants: &[Grant]) -> Self {
|
|
507
|
-
Self::build(open_file_limit,
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/// A guest allotted `memory_limit` bytes.
|
|
511
|
-
fn with_memory_limit(memory_limit: usize, grants: &[Grant]) -> Self {
|
|
512
|
-
Self::build(
|
|
513
|
-
None,
|
|
514
|
-
Some(memory_limit),
|
|
515
|
-
Profile::Hermetic,
|
|
516
|
-
Vec::new(),
|
|
517
|
-
grants,
|
|
518
|
-
)
|
|
513
|
+
Self::build(open_file_limit, Profile::Hermetic, Vec::new(), grants)
|
|
519
514
|
}
|
|
520
515
|
|
|
521
516
|
/// A guest on `profile`.
|
|
522
|
-
fn
|
|
523
|
-
Self::build(None,
|
|
517
|
+
fn for_profile(profile: Profile, grants: &[Grant]) -> Self {
|
|
518
|
+
Self::build(None, profile, Vec::new(), grants)
|
|
524
519
|
}
|
|
525
520
|
|
|
526
521
|
/// A guest whose Driver was built with `security`.
|
|
527
522
|
fn with_security(security: Vec<Arc<dyn SecurityOperations>>, grants: &[Grant]) -> Self {
|
|
528
|
-
Self::build(None,
|
|
523
|
+
Self::build(None, Profile::Hermetic, security, grants)
|
|
529
524
|
}
|
|
530
525
|
|
|
531
526
|
fn build(
|
|
532
527
|
open_file_limit: Option<usize>,
|
|
533
|
-
memory_limit: Option<usize>,
|
|
534
528
|
profile: Profile,
|
|
535
529
|
security: Vec<Arc<dyn SecurityOperations>>,
|
|
536
530
|
grants: &[Grant],
|
|
537
531
|
) -> Self {
|
|
538
532
|
let engine = load_engine().expect("shared engine must be constructible");
|
|
539
|
-
let config = Config
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
stderr_limit: None,
|
|
545
|
-
open_file_limit,
|
|
546
|
-
profile,
|
|
547
|
-
security,
|
|
548
|
-
};
|
|
549
|
-
let wasi =
|
|
550
|
-
Wasi::for_invocation(&config, Vec::new(), grants).expect("WASI context must build");
|
|
551
|
-
let mut store = Store::new(engine, Invocation::new(None, wasi));
|
|
533
|
+
let mut config = Config::for_profile(profile);
|
|
534
|
+
config.limits.open_file_limit = open_file_limit;
|
|
535
|
+
config.security = security;
|
|
536
|
+
let wasi = Wasi::for_invocation(&config, grants).expect("WASI context must build");
|
|
537
|
+
let mut store = Store::new(engine, Invocation::new(wasi));
|
|
552
538
|
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
553
539
|
let module = Module::new(engine, PROBE_WAT).expect("probe module must compile");
|
|
554
540
|
let instance = imports::linker()
|
|
@@ -620,6 +606,15 @@ impl Guest {
|
|
|
620
606
|
.expect("probe call must not trap")
|
|
621
607
|
}
|
|
622
608
|
|
|
609
|
+
/// Call the probe's export `name` on the descriptor `fd`.
|
|
610
|
+
fn call_fd(&mut self, name: &str, fd: i32) -> i32 {
|
|
611
|
+
self.instance
|
|
612
|
+
.get_typed_func::<i32, i32>(&mut self.store, name)
|
|
613
|
+
.expect("probe export must resolve")
|
|
614
|
+
.call(&mut self.store, fd)
|
|
615
|
+
.expect("probe call must not trap")
|
|
616
|
+
}
|
|
617
|
+
|
|
623
618
|
/// Stat `file.txt`, without following a link, into 384.
|
|
624
619
|
fn call_flagged_stat(&mut self) -> i32 {
|
|
625
620
|
self.instance
|
|
@@ -711,12 +706,8 @@ fn flags_of(how: &OpenHow) -> vfs::OpenFlags {
|
|
|
711
706
|
fn contents(root: &Path, path: &str) -> Option<Vec<u8>> {
|
|
712
707
|
let mut how = OpenHow::default();
|
|
713
708
|
how.read = true;
|
|
714
|
-
let Ok(mut file) = vfs::do_file_open(
|
|
715
|
-
|
|
716
|
-
root,
|
|
717
|
-
path,
|
|
718
|
-
&flags_of(&how),
|
|
719
|
-
) else {
|
|
709
|
+
let Ok(mut file) = vfs::do_file_open(&prepare_creds(&[], None), root, path, &flags_of(&how))
|
|
710
|
+
else {
|
|
720
711
|
return None;
|
|
721
712
|
};
|
|
722
713
|
let mut buf = vec![0; 64];
|
|
@@ -730,29 +721,23 @@ fn overwrite(root: &Path, path: &str) {
|
|
|
730
721
|
let mut how = OpenHow::default();
|
|
731
722
|
(how.write, how.create) = (true, true);
|
|
732
723
|
assert!(
|
|
733
|
-
vfs::do_file_open(
|
|
734
|
-
&prepare_creds_within(&[], None),
|
|
735
|
-
root,
|
|
736
|
-
path,
|
|
737
|
-
&flags_of(&how)
|
|
738
|
-
)
|
|
739
|
-
.is_ok(),
|
|
724
|
+
vfs::do_file_open(&prepare_creds(&[], None), root, path, &flags_of(&how)).is_ok(),
|
|
740
725
|
"the file must be made"
|
|
741
726
|
);
|
|
742
727
|
}
|
|
743
728
|
|
|
744
729
|
struct Refuses(&'static str);
|
|
745
730
|
|
|
746
|
-
impl Policy for Refuses {
|
|
747
|
-
fn allows(&self,
|
|
748
|
-
path != self.0
|
|
731
|
+
impl Policy<MountRequest<'_>> for Refuses {
|
|
732
|
+
fn allows(&self, request: &MountRequest<'_>) -> bool {
|
|
733
|
+
request.path != self.0
|
|
749
734
|
}
|
|
750
735
|
}
|
|
751
736
|
|
|
752
737
|
struct AllowsAll;
|
|
753
738
|
|
|
754
|
-
impl Policy for AllowsAll {
|
|
755
|
-
fn allows(&self,
|
|
739
|
+
impl Policy<MountRequest<'_>> for AllowsAll {
|
|
740
|
+
fn allows(&self, _request: &MountRequest<'_>) -> bool {
|
|
756
741
|
true
|
|
757
742
|
}
|
|
758
743
|
}
|
|
@@ -784,7 +769,7 @@ impl StoresUpperCase {
|
|
|
784
769
|
}
|
|
785
770
|
|
|
786
771
|
impl FileSystemType for StoresUpperCase {
|
|
787
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
772
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
788
773
|
sb.d_make_root(vfs::Inode::new(
|
|
789
774
|
&vfs::Kstat::new(vfs::FileType::Dir, 0),
|
|
790
775
|
self,
|
|
@@ -794,12 +779,11 @@ impl FileSystemType for StoresUpperCase {
|
|
|
794
779
|
}
|
|
795
780
|
|
|
796
781
|
impl InodeOperations for StoresUpperCase {
|
|
797
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
798
|
-
self.stat(&dentry.path_raw()[1..])
|
|
799
|
-
.ok_or(FilesystemError::NotFound)
|
|
782
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
783
|
+
self.stat(&dentry.path_raw()[1..]).ok_or(Errno::NotFound)
|
|
800
784
|
}
|
|
801
785
|
|
|
802
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
786
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
803
787
|
let Some(found) = self.stat(&dentry.path_raw()[1..]) else {
|
|
804
788
|
return Ok(Lookup::Absent);
|
|
805
789
|
};
|
|
@@ -817,7 +801,7 @@ impl InodeOperations for StoresUpperCase {
|
|
|
817
801
|
// @behavior RT-120
|
|
818
802
|
#[test]
|
|
819
803
|
fn a_policy_judges_a_path_as_its_filesystem_stores_it() {
|
|
820
|
-
let policy: Arc<dyn
|
|
804
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/FILE.TXT"));
|
|
821
805
|
let mut guest = Guest::new(&[grant(
|
|
822
806
|
Arc::new(StoresUpperCase(&["FILE.TXT"])),
|
|
823
807
|
Access::Read,
|
|
@@ -826,18 +810,18 @@ fn a_policy_judges_a_path_as_its_filesystem_stores_it() {
|
|
|
826
810
|
assert_eq!(
|
|
827
811
|
guest.call("read_file", FILE),
|
|
828
812
|
ERRNO_ACCES,
|
|
829
|
-
"path_open of `file.txt` beneath a Mount whose Policy refuses `/
|
|
813
|
+
"path_open of `file.txt` beneath a Mount whose Policy refuses `/FILE.TXT`, over a \
|
|
830
814
|
Filesystem storing that name as `FILE.TXT`, through preview1 must answer EACCES"
|
|
831
815
|
);
|
|
832
816
|
}
|
|
833
817
|
|
|
834
818
|
// A Policy handed the descriptor's path as the guest spelled it would see
|
|
835
|
-
// `/
|
|
819
|
+
// `/dir/inner` and let the read through.
|
|
836
820
|
// @behavior RT-120
|
|
837
821
|
#[test]
|
|
838
822
|
fn a_policy_judges_a_path_beneath_an_opened_directory_as_its_filesystem_stores_it() {
|
|
839
823
|
const INNER: (i32, i32) = (960, 5);
|
|
840
|
-
let policy: Arc<dyn
|
|
824
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/DIR/INNER"));
|
|
841
825
|
let mut guest = Guest::new(&[grant(
|
|
842
826
|
Arc::new(StoresUpperCase(&["DIR/INNER"])),
|
|
843
827
|
Access::Read,
|
|
@@ -847,35 +831,44 @@ fn a_policy_judges_a_path_beneath_an_opened_directory_as_its_filesystem_stores_i
|
|
|
847
831
|
guest.call("open_beneath_dir", INNER),
|
|
848
832
|
ERRNO_ACCES,
|
|
849
833
|
"path_open of `inner` through `dir` opened beneath a Mount whose Policy refuses \
|
|
850
|
-
`/
|
|
834
|
+
`/DIR/INNER`, over a Filesystem storing both names in upper case, through \
|
|
851
835
|
preview1 must answer EACCES"
|
|
852
836
|
);
|
|
853
837
|
}
|
|
854
838
|
|
|
855
839
|
// @behavior RT-075
|
|
856
840
|
#[test]
|
|
857
|
-
fn
|
|
858
|
-
let
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
841
|
+
fn a_guest_holding_a_mount_holds_one_preopen_the_root() {
|
|
842
|
+
let at = |path: &str| {
|
|
843
|
+
let mount = Mount::new(
|
|
844
|
+
path,
|
|
845
|
+
Filesystem::new(Tmpfs::new()).expect("the instance must stand"),
|
|
846
|
+
Access::Read,
|
|
847
|
+
)
|
|
848
|
+
.expect("the path is a guest path");
|
|
849
|
+
Grant::Mount(mount)
|
|
850
|
+
};
|
|
851
|
+
let mut guest = Guest::new(&[at("/data"), at("/tmp")]);
|
|
852
|
+
let names = (
|
|
853
|
+
guest.call_fd("preopen_name", 3),
|
|
854
|
+
guest.call_fd("preopen_name", 4),
|
|
863
855
|
);
|
|
864
856
|
let memory = guest
|
|
865
857
|
.instance
|
|
866
858
|
.get_memory(&mut guest.store, "memory")
|
|
867
859
|
.expect("probe exports its memory");
|
|
860
|
+
let data = memory.data(&guest.store);
|
|
868
861
|
assert_eq!(
|
|
869
|
-
&
|
|
870
|
-
b"/
|
|
871
|
-
"
|
|
862
|
+
(names, &data[260..264], &data[512..513]),
|
|
863
|
+
((0, ERRNO_BADF), &1u32.to_le_bytes()[..], &b"/"[..]),
|
|
864
|
+
"Mounts at /data and /tmp through Runtime::invoke must preopen / alone as descriptor 3"
|
|
872
865
|
);
|
|
873
866
|
}
|
|
874
867
|
|
|
875
868
|
/// The inode number the guest reads for `file.txt` from a stat and from a
|
|
876
869
|
/// listing, and for the Mount's root from `.`.
|
|
877
870
|
fn inodes_seen(profile: Profile) -> (u64, u64, u64) {
|
|
878
|
-
let mut guest = Guest::
|
|
871
|
+
let mut guest = Guest::for_profile(
|
|
879
872
|
profile,
|
|
880
873
|
&[grant(file_and_directory(), Access::ReadWrite, None)],
|
|
881
874
|
);
|
|
@@ -928,16 +921,21 @@ fn a_permissive_guest_tells_entries_apart_by_their_inode_numbers() {
|
|
|
928
921
|
);
|
|
929
922
|
}
|
|
930
923
|
|
|
931
|
-
// A Tmpfs's device number depends on how many came before it, so
|
|
932
|
-
//
|
|
933
|
-
// @behavior RT-183
|
|
924
|
+
// A Tmpfs's device number depends on how many came before it, so the numbers
|
|
925
|
+
// are the Invocation's own, handed out in the order it meets each entry.
|
|
926
|
+
// @behavior RT-183 RT-428
|
|
934
927
|
#[test]
|
|
935
|
-
fn
|
|
928
|
+
fn a_hermetic_guest_tells_entries_apart_by_numbers_of_its_own() {
|
|
929
|
+
let (stat, listed, dot) = inodes_seen(Profile::Hermetic);
|
|
936
930
|
assert_eq!(
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
931
|
+
stat, listed,
|
|
932
|
+
"fd_readdir and path_filestat_get of a file beneath a Mount through a hermetic guest's \
|
|
933
|
+
preview1 must answer the same inode number"
|
|
934
|
+
);
|
|
935
|
+
assert!(
|
|
936
|
+
stat != 0 && dot != 0 && dot != stat && stat.max(dot) <= 3,
|
|
937
|
+
"a hermetic guest's inode numbers for a file and its directory must differ and be the \
|
|
938
|
+
first numbers its Invocation hands out, not {stat} and {dot}"
|
|
941
939
|
);
|
|
942
940
|
}
|
|
943
941
|
|
|
@@ -999,67 +997,40 @@ fn a_listing_goes_on_over_the_entries_it_began_with() {
|
|
|
999
997
|
);
|
|
1000
998
|
}
|
|
1001
999
|
|
|
1002
|
-
// A buffer of 51 takes only the dots, one of 4096 the whole listing; the limit
|
|
1003
|
-
// the listing is held against is the memory the guest was allotted, counted
|
|
1004
|
-
// from the moment the listing is read.
|
|
1005
|
-
// @behavior RT-237
|
|
1006
|
-
#[test]
|
|
1007
|
-
fn a_listing_it_cannot_hold_within_a_guests_memory_answers_enomem() {
|
|
1008
|
-
let dir = host_dir_with_a_file("holds");
|
|
1009
|
-
let answer = |memory_limit, len| {
|
|
1010
|
-
let bind = Arc::new(Bind::new(&dir).expect("the host directory must open"));
|
|
1011
|
-
let mut guest =
|
|
1012
|
-
Guest::with_memory_limit(memory_limit, &[grant(bind, Access::ReadWrite, None)]);
|
|
1013
|
-
let errno = guest.call_list(0, len);
|
|
1014
|
-
let memory = guest
|
|
1015
|
-
.instance
|
|
1016
|
-
.get_memory(&mut guest.store, "memory")
|
|
1017
|
-
.expect("probe exports its memory");
|
|
1018
|
-
let used = u32::from_le_bytes(memory.data(&guest.store)[136..140].try_into().unwrap());
|
|
1019
|
-
(errno, used)
|
|
1020
|
-
};
|
|
1021
|
-
assert_eq!(
|
|
1022
|
-
[answer(1, 51), answer(1, 4096), answer(1 << 20, 51)],
|
|
1023
|
-
[(ERRNO_NOMEM, 0), (ERRNO_NOMEM, 0), (0, 51)],
|
|
1024
|
-
"fd_readdir through preview1, with more to hold than the guest's memory_limit, must \
|
|
1025
|
-
answer ENOMEM before it hands any entry, read part way or whole, and within it succeed"
|
|
1026
|
-
);
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
1000
|
/// A root whose listing hands `.` and `..`, then fails as a host read would.
|
|
1030
1001
|
struct FailsPastTheDots;
|
|
1031
1002
|
|
|
1032
1003
|
struct FailsPastTheDotsDir;
|
|
1033
1004
|
|
|
1034
1005
|
impl FileOperations for FailsPastTheDotsDir {
|
|
1006
|
+
fn has_iterate_shared(&self) -> bool {
|
|
1007
|
+
true
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1035
1010
|
fn iterate_shared(
|
|
1036
1011
|
&mut self,
|
|
1037
1012
|
dentry: &Dentry,
|
|
1038
1013
|
ctx: &mut vfs::DirContext<'_>,
|
|
1039
|
-
) -> Result<(),
|
|
1014
|
+
) -> Result<(), Errno> {
|
|
1040
1015
|
if !vfs::dir_emit_dots(dentry, ctx) {
|
|
1041
1016
|
return Ok(());
|
|
1042
1017
|
}
|
|
1043
|
-
Err(
|
|
1018
|
+
Err(Errno::Other("the host read failed".into()))
|
|
1044
1019
|
}
|
|
1045
1020
|
}
|
|
1046
1021
|
|
|
1047
1022
|
impl InodeOperations for FailsPastTheDots {
|
|
1048
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
1023
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
1049
1024
|
Ok(Kstat::new(FileType::Dir, 0))
|
|
1050
1025
|
}
|
|
1051
1026
|
|
|
1052
|
-
fn open(
|
|
1053
|
-
&self,
|
|
1054
|
-
_dentry: &Dentry,
|
|
1055
|
-
_how: &OpenHow,
|
|
1056
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
1027
|
+
fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
1057
1028
|
Ok(Box::new(FailsPastTheDotsDir))
|
|
1058
1029
|
}
|
|
1059
1030
|
}
|
|
1060
1031
|
|
|
1061
1032
|
impl FileSystemType for FailsPastTheDots {
|
|
1062
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
1033
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
1063
1034
|
sb.d_make_root(vfs::Inode::new(
|
|
1064
1035
|
&vfs::Kstat::new(vfs::FileType::Dir, 0),
|
|
1065
1036
|
self,
|
|
@@ -1172,7 +1143,10 @@ fn a_path_above_the_directory_it_is_opened_beneath_is_refused() {
|
|
|
1172
1143
|
/// What `stat_inner` answers through `dir` opened, beneath a Mount with
|
|
1173
1144
|
/// `policy`, before `change` runs on the host's root of the Tmpfs
|
|
1174
1145
|
/// holding it.
|
|
1175
|
-
fn stat_after(
|
|
1146
|
+
fn stat_after(
|
|
1147
|
+
policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
|
|
1148
|
+
change: impl FnOnce(&Path),
|
|
1149
|
+
) -> i32 {
|
|
1176
1150
|
let tmpfs = file_and_directory();
|
|
1177
1151
|
let mut guest = Guest::new(&[grant(tmpfs.clone(), Access::ReadWrite, policy)]);
|
|
1178
1152
|
assert_eq!(
|
|
@@ -1188,8 +1162,8 @@ fn stat_after(policy: Option<Arc<dyn Policy>>, change: impl FnOnce(&Path)) -> i3
|
|
|
1188
1162
|
/// an `inner` of its own, so only where the descriptor reaches decides
|
|
1189
1163
|
/// whether the lookup finds one.
|
|
1190
1164
|
fn move_and_replace(root: &Path) {
|
|
1191
|
-
vfs::filename_renameat2(&
|
|
1192
|
-
vfs::filename_mkdirat(&
|
|
1165
|
+
vfs::filename_renameat2(&prepare_creds(&[], None), root, "dir", root, "moved").unwrap();
|
|
1166
|
+
vfs::filename_mkdirat(&prepare_creds(&[], None), root, "dir").unwrap();
|
|
1193
1167
|
overwrite(root, "dir/inner");
|
|
1194
1168
|
}
|
|
1195
1169
|
|
|
@@ -1199,9 +1173,9 @@ fn move_and_replace(root: &Path) {
|
|
|
1199
1173
|
#[test]
|
|
1200
1174
|
fn a_directory_made_in_a_removed_directorys_place_is_not_reached_through_it() {
|
|
1201
1175
|
let answer = stat_after(None, |root| {
|
|
1202
|
-
vfs::filename_unlinkat(&
|
|
1203
|
-
vfs::filename_rmdir(&
|
|
1204
|
-
vfs::filename_mkdirat(&
|
|
1176
|
+
vfs::filename_unlinkat(&prepare_creds(&[], None), root, "dir/inner").unwrap();
|
|
1177
|
+
vfs::filename_rmdir(&prepare_creds(&[], None), root, "dir").unwrap();
|
|
1178
|
+
vfs::filename_mkdirat(&prepare_creds(&[], None), root, "dir").unwrap();
|
|
1205
1179
|
overwrite(root, "dir/inner");
|
|
1206
1180
|
});
|
|
1207
1181
|
assert_eq!(
|
|
@@ -1304,29 +1278,23 @@ fn a_descriptor_moved_beneath_a_policy_still_lists_itself() {
|
|
|
1304
1278
|
// @behavior RT-170
|
|
1305
1279
|
#[test]
|
|
1306
1280
|
fn a_directory_moved_beneath_another_mount_of_its_instance_is_reached_beneath_a_policy() {
|
|
1307
|
-
let open_after_move = |policy: Arc<dyn Policy
|
|
1281
|
+
let open_after_move = |policy: Arc<dyn for<'a> Policy<MountRequest<'a>>>| {
|
|
1308
1282
|
let instance = Filesystem::new(file_and_directory()).expect("the instance must stand");
|
|
1309
|
-
let mount =
|
|
1310
|
-
.expect("/
|
|
1283
|
+
let mount =
|
|
1284
|
+
Mount::new("/", instance.clone(), Access::ReadWrite).expect("/ is a guest path");
|
|
1311
1285
|
let mut guest = Guest::new(&[Grant::Mount(mount.clone().with_policy(policy))]);
|
|
1312
1286
|
assert_eq!(guest.call_bare("open_dir"), 0, "dir must open");
|
|
1313
1287
|
let other = Path::root(mount.mnt());
|
|
1314
|
-
vfs::filename_renameat2(
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
"dir",
|
|
1318
|
-
&other,
|
|
1319
|
-
"moved",
|
|
1320
|
-
)
|
|
1321
|
-
.expect("the directory must move");
|
|
1322
|
-
vfs::filename_mkdirat(&prepare_creds_within(&[], None), &other, "dir")
|
|
1288
|
+
vfs::filename_renameat2(&prepare_creds(&[], None), &other, "dir", &other, "moved")
|
|
1289
|
+
.expect("the directory must move");
|
|
1290
|
+
vfs::filename_mkdirat(&prepare_creds(&[], None), &other, "dir")
|
|
1323
1291
|
.expect("another directory must be made");
|
|
1324
1292
|
guest.call_bare("open_inner")
|
|
1325
1293
|
};
|
|
1326
1294
|
assert_eq!(
|
|
1327
1295
|
(
|
|
1328
1296
|
open_after_move(Arc::new(AllowsAll)),
|
|
1329
|
-
open_after_move(Arc::new(Refuses("/
|
|
1297
|
+
open_after_move(Arc::new(Refuses("/moved/inner")))
|
|
1330
1298
|
),
|
|
1331
1299
|
(0, ERRNO_ACCES),
|
|
1332
1300
|
"path_open of inner through a directory descriptor beneath a Mount with a Policy, \
|
|
@@ -1353,11 +1321,7 @@ impl ReusesInodes {
|
|
|
1353
1321
|
}
|
|
1354
1322
|
|
|
1355
1323
|
impl Hook for ReusesInodes {
|
|
1356
|
-
fn getattr(
|
|
1357
|
-
&self,
|
|
1358
|
-
inner: &dyn InodeOperations,
|
|
1359
|
-
dentry: &Dentry,
|
|
1360
|
-
) -> Result<Kstat, FilesystemError> {
|
|
1324
|
+
fn getattr(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
1361
1325
|
let found = inner.getattr(dentry)?;
|
|
1362
1326
|
Ok(match dentry.name().as_str() {
|
|
1363
1327
|
"dir" => self.dir_kstat(found),
|
|
@@ -1365,11 +1329,7 @@ impl Hook for ReusesInodes {
|
|
|
1365
1329
|
})
|
|
1366
1330
|
}
|
|
1367
1331
|
|
|
1368
|
-
fn lookup(
|
|
1369
|
-
&self,
|
|
1370
|
-
inner: &dyn InodeOperations,
|
|
1371
|
-
dentry: &Dentry,
|
|
1372
|
-
) -> Result<Lookup, FilesystemError> {
|
|
1332
|
+
fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
1373
1333
|
Ok(match inner.lookup(dentry)? {
|
|
1374
1334
|
Lookup::Found(inode) if dentry.name() == "dir" => {
|
|
1375
1335
|
self.found.lock().unwrap().push(Arc::downgrade(inode.ops()));
|
|
@@ -1381,16 +1341,12 @@ impl Hook for ReusesInodes {
|
|
|
1381
1341
|
}
|
|
1382
1342
|
|
|
1383
1343
|
/// Its root answers as the Filesystem's and sets up nothing of it.
|
|
1384
|
-
fn fill_super(
|
|
1385
|
-
&self,
|
|
1386
|
-
fs: Arc<dyn FileSystemType>,
|
|
1387
|
-
sb: &mut Filesystem,
|
|
1388
|
-
) -> Result<(), FilesystemError> {
|
|
1344
|
+
fn fill_super(&self, fs: Arc<dyn FileSystemType>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
1389
1345
|
let beneath = Filesystem::new(fs)?;
|
|
1390
1346
|
let root = beneath
|
|
1391
1347
|
.root()
|
|
1392
1348
|
.and_then(|root| root.inode())
|
|
1393
|
-
.ok_or(
|
|
1349
|
+
.ok_or(Errno::NotFound)?;
|
|
1394
1350
|
sb.d_make_root(vfs::Inode::new(
|
|
1395
1351
|
&vfs::Kstat::new(vfs::FileType::Dir, 0),
|
|
1396
1352
|
root.ops().clone(),
|
|
@@ -1400,7 +1356,7 @@ impl Hook for ReusesInodes {
|
|
|
1400
1356
|
|
|
1401
1357
|
/// The call removing it holds what it looked up, so `dir` is open
|
|
1402
1358
|
/// beyond that only where a descriptor holds it too.
|
|
1403
|
-
fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(),
|
|
1359
|
+
fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
|
|
1404
1360
|
let removed = inner.rmdir(dentry);
|
|
1405
1361
|
let held = self
|
|
1406
1362
|
.found
|
|
@@ -1436,9 +1392,9 @@ fn a_directory_descriptor_holds_its_directory_while_open() {
|
|
|
1436
1392
|
"dir must open as a directory"
|
|
1437
1393
|
);
|
|
1438
1394
|
let outside = host(&reuses);
|
|
1439
|
-
vfs::filename_unlinkat(&
|
|
1440
|
-
vfs::filename_rmdir(&
|
|
1441
|
-
vfs::filename_mkdirat(&
|
|
1395
|
+
vfs::filename_unlinkat(&prepare_creds(&[], None), &outside, "dir/inner").unwrap();
|
|
1396
|
+
vfs::filename_rmdir(&prepare_creds(&[], None), &outside, "dir").unwrap();
|
|
1397
|
+
vfs::filename_mkdirat(&prepare_creds(&[], None), &outside, "dir").unwrap();
|
|
1442
1398
|
overwrite(&host(&tmpfs), "dir/inner");
|
|
1443
1399
|
assert_eq!(
|
|
1444
1400
|
guest.call_bare("stat_inner"),
|
|
@@ -1454,11 +1410,7 @@ fn a_directory_descriptor_holds_its_directory_while_open() {
|
|
|
1454
1410
|
struct NamesNoIdentity;
|
|
1455
1411
|
|
|
1456
1412
|
impl Hook for NamesNoIdentity {
|
|
1457
|
-
fn lookup(
|
|
1458
|
-
&self,
|
|
1459
|
-
inner: &dyn InodeOperations,
|
|
1460
|
-
dentry: &Dentry,
|
|
1461
|
-
) -> Result<Lookup, FilesystemError> {
|
|
1413
|
+
fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
1462
1414
|
Ok(match inner.lookup(dentry)? {
|
|
1463
1415
|
Lookup::Found(inode) => {
|
|
1464
1416
|
let found = inode.ops().getattr(dentry)?;
|
|
@@ -1527,31 +1479,54 @@ fn a_full_table_answers_emfile_whatever_the_path_names() {
|
|
|
1527
1479
|
);
|
|
1528
1480
|
}
|
|
1529
1481
|
|
|
1530
|
-
// The three standard descriptors and the preopen leave room for
|
|
1482
|
+
// The three standard descriptors and the preopen leave room for two more,
|
|
1531
1483
|
// so a directory spanning both Layers taking more than one leaves none
|
|
1532
1484
|
// for the file.
|
|
1533
1485
|
// @behavior RT-152
|
|
1534
1486
|
#[test]
|
|
1535
1487
|
fn an_overlay_directory_takes_one_descriptor_however_many_layers_it_spans() {
|
|
1536
|
-
let
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
)
|
|
1540
|
-
.expect("
|
|
1541
|
-
let
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
);
|
|
1545
|
-
|
|
1488
|
+
let host = std::env::temp_dir().join(format!("kobako-bind-lower-{}", std::process::id()));
|
|
1489
|
+
let _ = std::fs::remove_dir_all(&host);
|
|
1490
|
+
std::fs::create_dir_all(host.join("dir")).expect("the host directory must be created");
|
|
1491
|
+
std::fs::write(host.join("file.txt"), "granted").expect("the host file must be written");
|
|
1492
|
+
std::fs::write(host.join("dir/inner"), "x").expect("the host file must be written");
|
|
1493
|
+
let lower = std::env::temp_dir().join(format!("kobako-bind-lowest-{}", std::process::id()));
|
|
1494
|
+
let _ = std::fs::remove_dir_all(&lower);
|
|
1495
|
+
std::fs::create_dir_all(lower.join("dir")).expect("the host directory must be created");
|
|
1496
|
+
std::fs::write(lower.join("dir/lower"), "l").expect("the host file must be written");
|
|
1497
|
+
// Each Bind Layer holds a host directory behind the descriptor, which the
|
|
1498
|
+
// cap leaves uncounted as Linux's RLIMIT_NOFILE does.
|
|
1499
|
+
let bind = |at: &std::path::Path| {
|
|
1500
|
+
Filesystem::new(Bind::new(at).expect("the host directory must open"))
|
|
1501
|
+
.expect("the instance must stand")
|
|
1502
|
+
};
|
|
1503
|
+
let stacks = [
|
|
1546
1504
|
(
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1505
|
+
"Tmpfs over a Tmpfs",
|
|
1506
|
+
Filesystem::new(file_and_directory()).expect("the instance must stand"),
|
|
1507
|
+
Filesystem::new(tmpfs_with("dir/lower", "l")).expect("the instance must stand"),
|
|
1550
1508
|
),
|
|
1551
|
-
(
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1509
|
+
("Bind over a Bind", bind(&host), bind(&lower)),
|
|
1510
|
+
];
|
|
1511
|
+
for (kind, top, beneath) in stacks {
|
|
1512
|
+
let overlay =
|
|
1513
|
+
Overlay::new(vec![top, beneath], None).expect("two lower Layers must make a view");
|
|
1514
|
+
let mut guest =
|
|
1515
|
+
Guest::with_open_file_limit(Some(6), &[grant(Arc::new(overlay), Access::Read, None)]);
|
|
1516
|
+
assert_eq!(
|
|
1517
|
+
(
|
|
1518
|
+
guest.call_bare("open_dir"),
|
|
1519
|
+
guest.call("read_file", FILE),
|
|
1520
|
+
guest.call("read_file", FILE)
|
|
1521
|
+
),
|
|
1522
|
+
(0, 0, ERRNO_MFILE),
|
|
1523
|
+
"path_open of a directory the Layers of an Overlay of a {kind} hold, then of files, \
|
|
1524
|
+
beneath a Mount through preview1 with room for two descriptors must take one \
|
|
1525
|
+
descriptor for each, however many Layers hold the directory"
|
|
1526
|
+
);
|
|
1527
|
+
}
|
|
1528
|
+
std::fs::remove_dir_all(&host).expect("the host directory must be removed");
|
|
1529
|
+
std::fs::remove_dir_all(&lower).expect("the host directory must be removed");
|
|
1555
1530
|
}
|
|
1556
1531
|
|
|
1557
1532
|
// The open looks the directory up without following a link at its end, so
|
|
@@ -1577,10 +1552,8 @@ fn a_directory_two_layers_hold_is_reached_through_its_descriptor() {
|
|
|
1577
1552
|
#[test]
|
|
1578
1553
|
fn a_directory_moved_back_to_its_path_is_reached_through_its_descriptor_again() {
|
|
1579
1554
|
let answer = stat_after(None, |root| {
|
|
1580
|
-
vfs::filename_renameat2(&
|
|
1581
|
-
|
|
1582
|
-
vfs::filename_renameat2(&prepare_creds_within(&[], None), root, "moved", root, "dir")
|
|
1583
|
-
.unwrap();
|
|
1555
|
+
vfs::filename_renameat2(&prepare_creds(&[], None), root, "dir", root, "moved").unwrap();
|
|
1556
|
+
vfs::filename_renameat2(&prepare_creds(&[], None), root, "moved", root, "dir").unwrap();
|
|
1584
1557
|
});
|
|
1585
1558
|
assert_eq!(
|
|
1586
1559
|
answer, 0,
|
|
@@ -1593,7 +1566,7 @@ fn a_directory_moved_back_to_its_path_is_reached_through_its_descriptor_again()
|
|
|
1593
1566
|
#[test]
|
|
1594
1567
|
fn a_policy_refusing_an_open_answers_access_denied() {
|
|
1595
1568
|
let tmpfs: Tmpfs = [("file.txt", "granted")].into_iter().collect();
|
|
1596
|
-
let policy: Arc<dyn
|
|
1569
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/file.txt"));
|
|
1597
1570
|
let mut guest = Guest::new(&[grant(Arc::new(tmpfs), Access::Read, Some(policy))]);
|
|
1598
1571
|
assert_eq!(
|
|
1599
1572
|
guest.call("read_file", FILE),
|
|
@@ -1606,7 +1579,7 @@ fn a_policy_refusing_an_open_answers_access_denied() {
|
|
|
1606
1579
|
#[test]
|
|
1607
1580
|
fn a_policy_cannot_widen_a_mounts_access() {
|
|
1608
1581
|
let tmpfs = Arc::new(Tmpfs::new());
|
|
1609
|
-
let policy: Arc<dyn
|
|
1582
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
|
|
1610
1583
|
let mut guest = Guest::new(&[grant(tmpfs.clone(), Access::Read, Some(policy))]);
|
|
1611
1584
|
assert_eq!(
|
|
1612
1585
|
(
|
|
@@ -1663,17 +1636,17 @@ impl ChangeCounter {
|
|
|
1663
1636
|
}
|
|
1664
1637
|
|
|
1665
1638
|
impl Hook for ChangeCounter {
|
|
1666
|
-
fn mkdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(),
|
|
1639
|
+
fn mkdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
|
|
1667
1640
|
self.change();
|
|
1668
1641
|
inner.mkdir(dentry)
|
|
1669
1642
|
}
|
|
1670
1643
|
|
|
1671
|
-
fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(),
|
|
1644
|
+
fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
|
|
1672
1645
|
self.change();
|
|
1673
1646
|
inner.rmdir(dentry)
|
|
1674
1647
|
}
|
|
1675
1648
|
|
|
1676
|
-
fn unlink(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(),
|
|
1649
|
+
fn unlink(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
|
|
1677
1650
|
self.change();
|
|
1678
1651
|
inner.unlink(dentry)
|
|
1679
1652
|
}
|
|
@@ -1681,13 +1654,13 @@ impl Hook for ChangeCounter {
|
|
|
1681
1654
|
fn rename(
|
|
1682
1655
|
&self,
|
|
1683
1656
|
inner: &dyn InodeOperations,
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
) -> Result<(),
|
|
1657
|
+
old: &Dentry,
|
|
1658
|
+
new_dir: &dyn InodeOperations,
|
|
1659
|
+
new: &Dentry,
|
|
1660
|
+
flags: Option<RenameFlag>,
|
|
1661
|
+
) -> Result<(), Errno> {
|
|
1689
1662
|
self.change();
|
|
1690
|
-
inner.rename(
|
|
1663
|
+
inner.rename(old, new_dir, new, flags)
|
|
1691
1664
|
}
|
|
1692
1665
|
}
|
|
1693
1666
|
|
|
@@ -1697,13 +1670,13 @@ impl Hook for ChangeCounter {
|
|
|
1697
1670
|
#[test]
|
|
1698
1671
|
fn a_directory_beneath_a_mount_with_a_policy_does_not_move() {
|
|
1699
1672
|
let tmpfs = Arc::new([("dir/secret", "x")].into_iter().collect::<Tmpfs>());
|
|
1700
|
-
let policy: Arc<dyn
|
|
1673
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
|
|
1701
1674
|
let mut guest = Guest::new(&[grant(tmpfs.clone(), Access::ReadWrite, Some(policy))]);
|
|
1702
1675
|
assert_eq!(
|
|
1703
1676
|
(
|
|
1704
1677
|
guest.call_pair("rename_paths", DIR, MOVED),
|
|
1705
1678
|
vfs::vfs_fstatat(
|
|
1706
|
-
&
|
|
1679
|
+
&prepare_creds(&[], None),
|
|
1707
1680
|
&host(&tmpfs),
|
|
1708
1681
|
"dir/secret",
|
|
1709
1682
|
false
|
|
@@ -1727,21 +1700,21 @@ struct AppendedMeanwhileFile {
|
|
|
1727
1700
|
}
|
|
1728
1701
|
|
|
1729
1702
|
impl AppendedMeanwhileFile {
|
|
1730
|
-
fn other_appends(&self) -> Result<(),
|
|
1703
|
+
fn other_appends(&self) -> Result<(), Errno> {
|
|
1731
1704
|
self.other
|
|
1732
1705
|
.lock()
|
|
1733
1706
|
.expect("the other writer's lock must not be poisoned")
|
|
1734
|
-
.write_iter(&mut Kiocb::
|
|
1707
|
+
.write_iter(&mut Kiocb::new(0).with_append(), b"bbb")
|
|
1735
1708
|
.map(drop)
|
|
1736
1709
|
}
|
|
1737
1710
|
}
|
|
1738
1711
|
|
|
1739
1712
|
impl FileOperations for AppendedMeanwhileFile {
|
|
1740
|
-
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize,
|
|
1713
|
+
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
1741
1714
|
self.file.read_iter(iocb, buf)
|
|
1742
1715
|
}
|
|
1743
1716
|
|
|
1744
|
-
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
1717
|
+
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
1745
1718
|
if iocb.append {
|
|
1746
1719
|
self.other_appends()?;
|
|
1747
1720
|
}
|
|
@@ -1755,7 +1728,7 @@ impl Hook for AppendedMeanwhile {
|
|
|
1755
1728
|
inner: &dyn InodeOperations,
|
|
1756
1729
|
dentry: &Dentry,
|
|
1757
1730
|
how: &OpenHow,
|
|
1758
|
-
) -> Result<Box<dyn FileOperations>,
|
|
1731
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
1759
1732
|
let writes = build_how(|how| how.write = true);
|
|
1760
1733
|
let file = inner.open(dentry, how)?;
|
|
1761
1734
|
let other = inner.open(dentry, &writes)?;
|
|
@@ -1787,34 +1760,29 @@ fn an_append_lands_after_another_writers_append() {
|
|
|
1787
1760
|
|
|
1788
1761
|
#[cfg(unix)]
|
|
1789
1762
|
const FILETYPE_UNKNOWN: u8 = 0;
|
|
1790
|
-
#[cfg(unix)]
|
|
1791
1763
|
const FILETYPE_DIRECTORY: u8 = 3;
|
|
1792
|
-
#[cfg(unix)]
|
|
1793
1764
|
const FILETYPE_REGULAR_FILE: u8 = 4;
|
|
1794
|
-
#[cfg(unix)]
|
|
1795
1765
|
const FILETYPE_SYMBOLIC_LINK: u8 = 7;
|
|
1796
1766
|
|
|
1797
1767
|
/// A host directory of its own holding `file.txt` as a link to `target`,
|
|
1798
1768
|
/// made by `make_target`, and a guest handed it as a read-only Bind
|
|
1799
1769
|
/// Mount.
|
|
1800
|
-
#[cfg(unix)]
|
|
1801
1770
|
fn mount_link(name: &str, make_target: fn(&std::path::Path)) -> (std::path::PathBuf, Guest) {
|
|
1802
1771
|
mount_link_under(name, make_target, Access::Read, None)
|
|
1803
1772
|
}
|
|
1804
1773
|
|
|
1805
1774
|
/// As `linked`, the Mount taking `access` and `policy`.
|
|
1806
|
-
#[cfg(unix)]
|
|
1807
1775
|
fn mount_link_under(
|
|
1808
1776
|
name: &str,
|
|
1809
1777
|
make_target: fn(&std::path::Path),
|
|
1810
1778
|
access: Access,
|
|
1811
|
-
policy: Option<Arc<dyn Policy
|
|
1779
|
+
policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
|
|
1812
1780
|
) -> (std::path::PathBuf, Guest) {
|
|
1813
1781
|
let host = std::env::temp_dir().join(format!("kobako-granted-{name}-{}", std::process::id()));
|
|
1814
1782
|
let _ = std::fs::remove_dir_all(&host);
|
|
1815
1783
|
std::fs::create_dir_all(&host).expect("the host directory must be created");
|
|
1816
1784
|
make_target(&host.join("target"));
|
|
1817
|
-
|
|
1785
|
+
super::testing::symlink("target", host.join("file.txt"));
|
|
1818
1786
|
let directory = Bind::new(&host).expect("the host directory must open");
|
|
1819
1787
|
let guest = Guest::new(&[grant(Arc::new(directory), access, policy)]);
|
|
1820
1788
|
(host, guest)
|
|
@@ -1823,7 +1791,6 @@ fn mount_link_under(
|
|
|
1823
1791
|
/// What each stat of `path` with the given lookupflags answers, and the
|
|
1824
1792
|
/// filetype it wrote, beneath a Bind Mount whose host directory
|
|
1825
1793
|
/// holds `file.txt` as a link to `target`, made by `make_target`.
|
|
1826
|
-
#[cfg(unix)]
|
|
1827
1794
|
fn stat_link(
|
|
1828
1795
|
name: &str,
|
|
1829
1796
|
make_target: fn(&std::path::Path),
|
|
@@ -1911,7 +1878,6 @@ fn a_guest_sees_a_socket_as_one_and_cannot_open_it() {
|
|
|
1911
1878
|
// The link points at a regular file, so only a stat that follows none
|
|
1912
1879
|
// can answer a link.
|
|
1913
1880
|
// @behavior RT-097
|
|
1914
|
-
#[cfg(unix)]
|
|
1915
1881
|
#[test]
|
|
1916
1882
|
fn a_stat_following_no_link_reports_the_link_itself() {
|
|
1917
1883
|
let answers = stat_link(
|
|
@@ -1930,7 +1896,6 @@ fn a_stat_following_no_link_reports_the_link_itself() {
|
|
|
1930
1896
|
// A host link reports the length of where it points, so only what the runtime
|
|
1931
1897
|
// shows a guest keeps that length from it.
|
|
1932
1898
|
// @behavior RT-173
|
|
1933
|
-
#[cfg(unix)]
|
|
1934
1899
|
#[test]
|
|
1935
1900
|
fn a_link_reports_no_size_however_its_filesystem_sizes_it() {
|
|
1936
1901
|
let (host, mut guest) = mount_link("link-size", |target| {
|
|
@@ -1947,15 +1912,15 @@ fn a_link_reports_no_size_however_its_filesystem_sizes_it() {
|
|
|
1947
1912
|
);
|
|
1948
1913
|
}
|
|
1949
1914
|
|
|
1950
|
-
/// One Tmpfs read-write, as an invocation on each
|
|
1915
|
+
/// One Tmpfs read-write, as an invocation on each profile is handed it.
|
|
1951
1916
|
fn tmpfs_grant(tmpfs: &Arc<Tmpfs>) -> [Grant; 1] {
|
|
1952
1917
|
[grant(tmpfs.clone(), Access::ReadWrite, None)]
|
|
1953
1918
|
}
|
|
1954
1919
|
|
|
1955
1920
|
// @behavior RT-156
|
|
1956
1921
|
#[test]
|
|
1957
|
-
fn
|
|
1958
|
-
let mut guest = Guest::
|
|
1922
|
+
fn the_permissive_profile_sees_the_times_a_filesystem_keeps() {
|
|
1923
|
+
let mut guest = Guest::for_profile(Profile::Permissive, &tmpfs_grant(&Arc::new(Tmpfs::new())));
|
|
1959
1924
|
let before = SystemTime::now()
|
|
1960
1925
|
.duration_since(UNIX_EPOCH)
|
|
1961
1926
|
.expect("the host clock stands past the epoch")
|
|
@@ -1963,17 +1928,17 @@ fn the_weaker_posture_sees_the_times_a_filesystem_keeps() {
|
|
|
1963
1928
|
assert_eq!(guest.call("write_file", FILE), 0, "the write must succeed");
|
|
1964
1929
|
assert!(
|
|
1965
1930
|
guest.times_of_path(FILE)[1] >= before,
|
|
1966
|
-
"path_filestat_get of a file written beneath a Mount through preview1 on the
|
|
1967
|
-
|
|
1931
|
+
"path_filestat_get of a file written beneath a Mount through preview1 on the \
|
|
1932
|
+
permissive profile must report a modification time no earlier than the write"
|
|
1968
1933
|
);
|
|
1969
1934
|
}
|
|
1970
1935
|
|
|
1971
|
-
// A Tmpfs records the host's real time, so only the
|
|
1936
|
+
// A Tmpfs records the host's real time, so only the profile's view turns it
|
|
1972
1937
|
// into the epoch.
|
|
1973
1938
|
// @behavior RT-157
|
|
1974
1939
|
#[test]
|
|
1975
|
-
fn
|
|
1976
|
-
let mut guest = Guest::
|
|
1940
|
+
fn the_hermetic_profile_sees_every_time_at_the_unix_epoch() {
|
|
1941
|
+
let mut guest = Guest::for_profile(Profile::Hermetic, &tmpfs_grant(&Arc::new(Tmpfs::new())));
|
|
1977
1942
|
assert_eq!(guest.call("write_file", FILE), 0, "the write must succeed");
|
|
1978
1943
|
let path = guest.times_of_path(FILE);
|
|
1979
1944
|
assert_eq!(guest.call("stat_opened", FILE), 0, "the stat must succeed");
|
|
@@ -1981,29 +1946,84 @@ fn the_strongest_posture_sees_every_time_at_the_unix_epoch() {
|
|
|
1981
1946
|
(path, guest.stat_times()),
|
|
1982
1947
|
([0; 3], [0; 3]),
|
|
1983
1948
|
"path_filestat_get and fd_filestat_get of a written file through preview1 on the \
|
|
1984
|
-
|
|
1949
|
+
hermetic profile must report each time as the Unix epoch"
|
|
1985
1950
|
);
|
|
1986
1951
|
}
|
|
1987
1952
|
|
|
1988
1953
|
// @behavior RT-158
|
|
1989
1954
|
#[test]
|
|
1990
|
-
fn
|
|
1955
|
+
fn a_time_another_profile_wrote_reaches_the_hermetic_profile_as_the_epoch() {
|
|
1991
1956
|
let tmpfs = Arc::new(Tmpfs::new());
|
|
1992
|
-
let mut writer = Guest::
|
|
1957
|
+
let mut writer = Guest::for_profile(Profile::Permissive, &tmpfs_grant(&tmpfs));
|
|
1993
1958
|
assert_eq!(writer.call("write_file", FILE), 0, "the write must succeed");
|
|
1994
|
-
let mut reader = Guest::
|
|
1959
|
+
let mut reader = Guest::for_profile(Profile::Hermetic, &tmpfs_grant(&tmpfs));
|
|
1995
1960
|
assert_eq!(
|
|
1996
1961
|
reader.times_of_path(FILE),
|
|
1997
1962
|
[0; 3],
|
|
1998
|
-
"path_filestat_get through preview1 on the
|
|
1999
|
-
|
|
1963
|
+
"path_filestat_get through preview1 on the hermetic profile, of a file the permissive \
|
|
1964
|
+
profile wrote into the same Tmpfs, must report each time as the Unix epoch"
|
|
1965
|
+
);
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
/// A Filesystem holding `file.txt`, modified in the year 2600, more
|
|
1969
|
+
/// nanoseconds after the epoch than a `u64` counts. A guest sets a time in
|
|
1970
|
+
/// those nanoseconds, so only a Filesystem of its own can report one.
|
|
1971
|
+
struct ModifiedIn2600;
|
|
1972
|
+
|
|
1973
|
+
impl ModifiedIn2600 {
|
|
1974
|
+
fn stat(path: &str) -> Option<Kstat> {
|
|
1975
|
+
let year_2600 = std::time::UNIX_EPOCH + std::time::Duration::from_secs(19_880_879_760);
|
|
1976
|
+
match path {
|
|
1977
|
+
"" => Some(Kstat::new(FileType::Dir, 0)),
|
|
1978
|
+
"file.txt" => {
|
|
1979
|
+
Some(Kstat::new(FileType::RegFile, 0).with_times(None, Some(year_2600), None))
|
|
1980
|
+
}
|
|
1981
|
+
_ => None,
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
impl FileSystemType for ModifiedIn2600 {
|
|
1987
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
1988
|
+
sb.d_make_root(vfs::Inode::new(
|
|
1989
|
+
&vfs::Kstat::new(vfs::FileType::Dir, 0),
|
|
1990
|
+
self,
|
|
1991
|
+
));
|
|
1992
|
+
Ok(())
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
impl InodeOperations for ModifiedIn2600 {
|
|
1997
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
1998
|
+
Self::stat(&dentry.path_raw()[1..]).ok_or(Errno::NotFound)
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
2002
|
+
Ok(match Self::stat(&dentry.path_raw()[1..]) {
|
|
2003
|
+
Some(found) => Lookup::Found(Inode::new(&found, Arc::new(Self))),
|
|
2004
|
+
None => Lookup::Absent,
|
|
2005
|
+
})
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
// @behavior RT-404
|
|
2010
|
+
#[test]
|
|
2011
|
+
fn a_file_time_past_what_a_timestamp_holds_answers_overflow() {
|
|
2012
|
+
let mut guest = Guest::for_profile(
|
|
2013
|
+
Profile::Permissive,
|
|
2014
|
+
&[grant(Arc::new(ModifiedIn2600), Access::Read, None)],
|
|
2015
|
+
);
|
|
2016
|
+
assert_eq!(
|
|
2017
|
+
guest.stat_flagged(FILE, 0),
|
|
2018
|
+
ERRNO_OVERFLOW,
|
|
2019
|
+
"path_filestat_get through preview1 of a file its Filesystem reports modified in the \
|
|
2020
|
+
year 2600 must answer OVERFLOW, as wasmtime-wasi does"
|
|
2000
2021
|
);
|
|
2001
2022
|
}
|
|
2002
2023
|
|
|
2003
2024
|
// The stat follows no link, so only the trailing `/` can make it reach
|
|
2004
2025
|
// the directory the link points at, as Linux's `lstat` does.
|
|
2005
2026
|
// @behavior RT-098
|
|
2006
|
-
#[cfg(unix)]
|
|
2007
2027
|
#[test]
|
|
2008
2028
|
fn a_stat_of_a_link_named_with_a_trailing_slash_reports_its_directory() {
|
|
2009
2029
|
let answers = stat_link(
|
|
@@ -2024,8 +2044,10 @@ fn a_stat_of_a_link_named_with_a_trailing_slash_reports_its_directory() {
|
|
|
2024
2044
|
/// `file.txt/` to a directory beneath a read-write Bind Mount taking
|
|
2025
2045
|
/// `policy`, and whether the link stays; `name` keeps its host directory
|
|
2026
2046
|
/// its own.
|
|
2027
|
-
|
|
2028
|
-
|
|
2047
|
+
fn change_link_named_as_directory(
|
|
2048
|
+
name: &str,
|
|
2049
|
+
policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
|
|
2050
|
+
) -> ([i32; 2], bool) {
|
|
2029
2051
|
let (host, mut guest) = mount_link_under(name, directory_with_key, Access::ReadWrite, policy);
|
|
2030
2052
|
let answers = [
|
|
2031
2053
|
guest.call("unlink_path", FILE_AS_DIRECTORY),
|
|
@@ -2040,7 +2062,6 @@ fn change_link_named_as_directory(name: &str, policy: Option<Arc<dyn Policy>>) -
|
|
|
2040
2062
|
// directory, so a Policy, refusing only a link a call follows, changes
|
|
2041
2063
|
// neither answer.
|
|
2042
2064
|
// @behavior RT-123
|
|
2043
|
-
#[cfg(unix)]
|
|
2044
2065
|
#[test]
|
|
2045
2066
|
fn a_link_named_with_a_trailing_slash_is_neither_removed_nor_moved() {
|
|
2046
2067
|
assert_eq!(
|
|
@@ -2058,7 +2079,6 @@ fn a_link_named_with_a_trailing_slash_is_neither_removed_nor_moved() {
|
|
|
2058
2079
|
// The link points at nothing, so only an unlink that follows no link
|
|
2059
2080
|
// finds it there to answer ENOTDIR rather than ENOENT.
|
|
2060
2081
|
// @behavior RT-134
|
|
2061
|
-
#[cfg(unix)]
|
|
2062
2082
|
#[test]
|
|
2063
2083
|
fn an_unlink_with_a_trailing_slash_answers_for_the_name_itself() {
|
|
2064
2084
|
let host = std::env::temp_dir().join(format!(
|
|
@@ -2068,7 +2088,7 @@ fn an_unlink_with_a_trailing_slash_answers_for_the_name_itself() {
|
|
|
2068
2088
|
let _ = std::fs::remove_dir_all(&host);
|
|
2069
2089
|
std::fs::create_dir_all(host.join("dir")).expect("the host directory must be created");
|
|
2070
2090
|
std::fs::write(host.join("file.txt"), "granted").expect("the host file must be written");
|
|
2071
|
-
|
|
2091
|
+
super::testing::symlink("nowhere", host.join("gone"));
|
|
2072
2092
|
let directory = Bind::new(&host).expect("the host directory must open");
|
|
2073
2093
|
let mut guest = Guest::new(&[grant(Arc::new(directory), Access::ReadWrite, None)]);
|
|
2074
2094
|
let answers = [
|
|
@@ -2103,7 +2123,7 @@ fn a_name_no_filesystem_makes_is_answered_by_what_stands() {
|
|
|
2103
2123
|
)
|
|
2104
2124
|
.expect("/data is a guest path");
|
|
2105
2125
|
let root = vfs::Path::root(mount.mnt());
|
|
2106
|
-
let cred =
|
|
2126
|
+
let cred = prepare_creds(&[], None);
|
|
2107
2127
|
let link = |old, new| vfs::filename_linkat(&cred, &root, old, &root, new, false);
|
|
2108
2128
|
let symlink = |new| vfs::filename_symlinkat(&cred, "target", &root, new);
|
|
2109
2129
|
let refused = Err;
|
|
@@ -2116,11 +2136,11 @@ fn a_name_no_filesystem_makes_is_answered_by_what_stands() {
|
|
|
2116
2136
|
symlink("new"),
|
|
2117
2137
|
),
|
|
2118
2138
|
(
|
|
2119
|
-
refused(
|
|
2120
|
-
refused(
|
|
2121
|
-
refused(
|
|
2122
|
-
refused(
|
|
2123
|
-
refused(
|
|
2139
|
+
refused(Errno::NotFound),
|
|
2140
|
+
refused(Errno::AlreadyExists),
|
|
2141
|
+
refused(Errno::NotPermitted),
|
|
2142
|
+
refused(Errno::AlreadyExists),
|
|
2143
|
+
refused(Errno::NotPermitted),
|
|
2124
2144
|
),
|
|
2125
2145
|
"vfs::filename_linkat and filename_symlinkat over a Filesystem making no links must \
|
|
2126
2146
|
answer ENOENT for a missing source, EEXIST for a name that stands, and otherwise EPERM"
|
|
@@ -2144,13 +2164,8 @@ fn an_allocation_grows_a_file_to_where_its_room_ends_and_shortens_none() {
|
|
|
2144
2164
|
let tmpfs = tmpfs_with("file.txt", seed);
|
|
2145
2165
|
let answer = Guest::new(&[grant(tmpfs.clone(), Access::ReadWrite, None)])
|
|
2146
2166
|
.call("allocate_file", FILE);
|
|
2147
|
-
let len = vfs::vfs_fstatat(
|
|
2148
|
-
|
|
2149
|
-
&host(&tmpfs),
|
|
2150
|
-
"file.txt",
|
|
2151
|
-
false,
|
|
2152
|
-
)
|
|
2153
|
-
.map(|stat| stat.size);
|
|
2167
|
+
let len = vfs::vfs_fstatat(&prepare_creds(&[], None), &host(&tmpfs), "file.txt", false)
|
|
2168
|
+
.map(|stat| stat.size);
|
|
2154
2169
|
let held = contents(&host(&tmpfs), "file.txt").map(|head| head[7]);
|
|
2155
2170
|
(answer, len.ok().map(|len| len as usize), held)
|
|
2156
2171
|
};
|
|
@@ -2209,7 +2224,6 @@ fn an_allocation_past_a_tmpfs_size_answers_enospc() {
|
|
|
2209
2224
|
// The probe's opens follow no link, so only the trailing `/` can make one
|
|
2210
2225
|
// reach the directory the link points at, as Linux's `open` does.
|
|
2211
2226
|
// @behavior RT-100
|
|
2212
|
-
#[cfg(unix)]
|
|
2213
2227
|
#[test]
|
|
2214
2228
|
fn an_open_following_no_link_refuses_a_link_to_a_directory() {
|
|
2215
2229
|
let (host, mut guest) = mount_link("open-nofollow", |target| {
|
|
@@ -2229,7 +2243,6 @@ fn an_open_following_no_link_refuses_a_link_to_a_directory() {
|
|
|
2229
2243
|
}
|
|
2230
2244
|
|
|
2231
2245
|
/// A host directory linked in as `file.txt`, holding `key`.
|
|
2232
|
-
#[cfg(unix)]
|
|
2233
2246
|
fn directory_with_key(target: &std::path::Path) {
|
|
2234
2247
|
std::fs::create_dir(target).expect("the host directory must be created");
|
|
2235
2248
|
std::fs::write(target.join("key"), "secret").expect("the host file must be written");
|
|
@@ -2238,10 +2251,9 @@ fn directory_with_key(target: &std::path::Path) {
|
|
|
2238
2251
|
// The link itself is allowed; only judging where it leads refuses the key, so
|
|
2239
2252
|
// a walk that took the link's own path for the answer would hand it over.
|
|
2240
2253
|
// @behavior RT-101
|
|
2241
|
-
#[cfg(unix)]
|
|
2242
2254
|
#[test]
|
|
2243
2255
|
fn a_path_through_a_link_beneath_a_mount_with_a_policy_is_judged_where_it_leads() {
|
|
2244
|
-
let refuses_key: Arc<dyn
|
|
2256
|
+
let refuses_key: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/target/key"));
|
|
2245
2257
|
let (host, mut guest) = mount_link_under(
|
|
2246
2258
|
"policy-link-refused",
|
|
2247
2259
|
directory_with_key,
|
|
@@ -2254,7 +2266,7 @@ fn a_path_through_a_link_beneath_a_mount_with_a_policy_is_judged_where_it_leads(
|
|
|
2254
2266
|
];
|
|
2255
2267
|
let kept = host.join("target/key").exists();
|
|
2256
2268
|
let _ = std::fs::remove_dir_all(&host);
|
|
2257
|
-
let allows: Arc<dyn
|
|
2269
|
+
let allows: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
|
|
2258
2270
|
let (host, mut guest) = mount_link_under(
|
|
2259
2271
|
"policy-link-allowed",
|
|
2260
2272
|
directory_with_key,
|
|
@@ -2279,7 +2291,6 @@ fn a_path_through_a_link_beneath_a_mount_with_a_policy_is_judged_where_it_leads(
|
|
|
2279
2291
|
// it and one into itself loops, as beneath a Mount without a Policy, and an unlink
|
|
2280
2292
|
// acts on the link itself.
|
|
2281
2293
|
// @behavior RT-125
|
|
2282
|
-
#[cfg(unix)]
|
|
2283
2294
|
#[test]
|
|
2284
2295
|
fn a_link_out_of_a_directory_or_into_a_loop_answers_as_without_a_policy() {
|
|
2285
2296
|
let outside = std::env::temp_dir().join(format!("kobako-outside-{}", std::process::id()));
|
|
@@ -2299,10 +2310,9 @@ fn a_link_out_of_a_directory_or_into_a_loop_answers_as_without_a_policy() {
|
|
|
2299
2310
|
));
|
|
2300
2311
|
let _ = std::fs::remove_dir_all(&host);
|
|
2301
2312
|
std::fs::create_dir_all(&host).expect("the host directory must be created");
|
|
2302
|
-
|
|
2303
|
-
.expect("the link must be made");
|
|
2313
|
+
super::testing::symlink(target, host.join("file.txt"));
|
|
2304
2314
|
let directory = Bind::new(&host).expect("the host directory must open");
|
|
2305
|
-
let policy: Arc<dyn
|
|
2315
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
|
|
2306
2316
|
let mut guest =
|
|
2307
2317
|
Guest::new(&[grant(Arc::new(directory), Access::ReadWrite, Some(policy))]);
|
|
2308
2318
|
let answers = [
|
|
@@ -2339,7 +2349,7 @@ fn a_link_out_of_a_directory_or_into_a_loop_answers_as_without_a_policy() {
|
|
|
2339
2349
|
fn a_lookup_that_fails_fails_the_call_beneath_a_policy() {
|
|
2340
2350
|
let tmpfs: Tmpfs = [("dir/file.txt", "granted")].into_iter().collect();
|
|
2341
2351
|
let failing = Wrap::new(Arc::new(tmpfs), Arc::new(FailsLookingUpDir));
|
|
2342
|
-
let policy: Arc<dyn
|
|
2352
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
|
|
2343
2353
|
let mut guest = Guest::new(&[grant(failing, Access::Read, Some(policy))]);
|
|
2344
2354
|
assert_eq!(
|
|
2345
2355
|
guest.call("read_file", DIR_FILE),
|
|
@@ -2354,13 +2364,9 @@ fn a_lookup_that_fails_fails_the_call_beneath_a_policy() {
|
|
|
2354
2364
|
struct FailsLookingUpDir;
|
|
2355
2365
|
|
|
2356
2366
|
impl Hook for FailsLookingUpDir {
|
|
2357
|
-
fn lookup(
|
|
2358
|
-
&self,
|
|
2359
|
-
inner: &dyn InodeOperations,
|
|
2360
|
-
dentry: &Dentry,
|
|
2361
|
-
) -> Result<Lookup, FilesystemError> {
|
|
2367
|
+
fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
2362
2368
|
match dentry.name().as_str() {
|
|
2363
|
-
"dir" => Err(
|
|
2369
|
+
"dir" => Err(Errno::Other("unreadable".into())),
|
|
2364
2370
|
_ => inner.lookup(dentry),
|
|
2365
2371
|
}
|
|
2366
2372
|
}
|
|
@@ -2369,7 +2375,6 @@ impl Hook for FailsLookingUpDir {
|
|
|
2369
2375
|
// Each path lands on what the link's target or its parent holds, so only a
|
|
2370
2376
|
// walk taking `.` and `..` from where the link led answers.
|
|
2371
2377
|
// @behavior RT-119
|
|
2372
|
-
#[cfg(unix)]
|
|
2373
2378
|
#[test]
|
|
2374
2379
|
fn a_step_out_of_a_link_lands_where_it_leads() {
|
|
2375
2380
|
assert_eq!(
|
|
@@ -2404,8 +2409,8 @@ fn file_and_directory() -> Arc<Tmpfs> {
|
|
|
2404
2409
|
struct RefusesMkdir;
|
|
2405
2410
|
|
|
2406
2411
|
impl SecurityOperations for RefusesMkdir {
|
|
2407
|
-
fn path_mkdir(&self, _path: SecurityPath<'_>) -> Result<(),
|
|
2408
|
-
Err(
|
|
2412
|
+
fn path_mkdir(&self, _path: SecurityPath<'_>) -> Result<(), Errno> {
|
|
2413
|
+
Err(Errno::PermissionDenied)
|
|
2409
2414
|
}
|
|
2410
2415
|
}
|
|
2411
2416
|
|
|
@@ -2422,13 +2427,7 @@ fn a_security_module_the_driver_was_built_with_judges_the_guest() {
|
|
|
2422
2427
|
assert_eq!(
|
|
2423
2428
|
(
|
|
2424
2429
|
guest.call("make_dir", NEW_AS_DIRECTORY),
|
|
2425
|
-
vfs::vfs_fstatat(
|
|
2426
|
-
&prepare_creds_within(&[], None),
|
|
2427
|
-
&host(&tmpfs),
|
|
2428
|
-
"new.txt",
|
|
2429
|
-
false
|
|
2430
|
-
)
|
|
2431
|
-
.is_err()
|
|
2430
|
+
vfs::vfs_fstatat(&prepare_creds(&[], None), &host(&tmpfs), "new.txt", false).is_err()
|
|
2432
2431
|
),
|
|
2433
2432
|
(ERRNO_ACCES, true),
|
|
2434
2433
|
"path_create_directory beneath a Mount through preview1, the Driver built with a \
|
|
@@ -2451,13 +2450,7 @@ fn a_path_ending_in_a_dot_makes_nothing_where_no_directory_stands() {
|
|
|
2451
2450
|
assert_eq!(
|
|
2452
2451
|
(
|
|
2453
2452
|
answers,
|
|
2454
|
-
vfs::vfs_fstatat(
|
|
2455
|
-
&prepare_creds_within(&[], None),
|
|
2456
|
-
&host(&tmpfs),
|
|
2457
|
-
"missing",
|
|
2458
|
-
false
|
|
2459
|
-
)
|
|
2460
|
-
.is_err()
|
|
2453
|
+
vfs::vfs_fstatat(&prepare_creds(&[], None), &host(&tmpfs), "missing", false).is_err()
|
|
2461
2454
|
),
|
|
2462
2455
|
([ERRNO_NOENT, ERRNO_NOENT], true),
|
|
2463
2456
|
"path_create_directory and path_open with O_CREAT of missing/. beneath a Mount through \
|
|
@@ -2483,13 +2476,7 @@ fn a_path_ending_in_a_dot_is_neither_removed_nor_moved() {
|
|
|
2483
2476
|
assert_eq!(
|
|
2484
2477
|
(
|
|
2485
2478
|
answers,
|
|
2486
|
-
vfs::vfs_fstatat(
|
|
2487
|
-
&prepare_creds_within(&[], None),
|
|
2488
|
-
&host(&tmpfs),
|
|
2489
|
-
"dir/inner",
|
|
2490
|
-
false
|
|
2491
|
-
)
|
|
2492
|
-
.is_ok()
|
|
2479
|
+
vfs::vfs_fstatat(&prepare_creds(&[], None), &host(&tmpfs), "dir/inner", false).is_ok()
|
|
2493
2480
|
),
|
|
2494
2481
|
(
|
|
2495
2482
|
[
|
|
@@ -2530,19 +2517,18 @@ fn a_create_of_what_already_stands_changes_nothing() {
|
|
|
2530
2517
|
// The host file only reads, so a host open asking to create, and so to
|
|
2531
2518
|
// write, would be refused where the guest asked only to read.
|
|
2532
2519
|
// @behavior RT-103
|
|
2533
|
-
#[cfg(unix)]
|
|
2534
2520
|
#[test]
|
|
2535
2521
|
fn a_create_of_a_host_file_that_only_reads_opens_it() {
|
|
2536
|
-
use std::os::unix::fs::PermissionsExt;
|
|
2537
2522
|
let host = std::env::temp_dir().join(format!("kobako-granted-creat-{}", std::process::id()));
|
|
2538
2523
|
let _ = std::fs::remove_dir_all(&host);
|
|
2539
2524
|
std::fs::create_dir_all(&host).expect("the host directory must be created");
|
|
2540
|
-
|
|
2541
|
-
std::fs::
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
.
|
|
2525
|
+
let file = host.join("file.txt");
|
|
2526
|
+
std::fs::write(&file, "granted").expect("the host file must be written");
|
|
2527
|
+
let mut read_only = std::fs::metadata(&file)
|
|
2528
|
+
.expect("the host file must stand")
|
|
2529
|
+
.permissions();
|
|
2530
|
+
read_only.set_readonly(true);
|
|
2531
|
+
std::fs::set_permissions(&file, read_only).expect("the host file must become read-only");
|
|
2546
2532
|
let directory = Bind::new(&host).expect("the host directory must open");
|
|
2547
2533
|
let answer = Guest::new(&[grant(Arc::new(directory), Access::ReadWrite, None)]).call_flagged(
|
|
2548
2534
|
FILE,
|
|
@@ -2560,17 +2546,15 @@ fn a_create_of_a_host_file_that_only_reads_opens_it() {
|
|
|
2560
2546
|
/// A host directory of the test's own beneath a read-write Bind Mount,
|
|
2561
2547
|
/// `dir` a link to the directory `real` and `gone` a link to nothing,
|
|
2562
2548
|
/// removed when it drops.
|
|
2563
|
-
#[cfg(unix)]
|
|
2564
2549
|
struct LinkedHost(std::path::PathBuf);
|
|
2565
2550
|
|
|
2566
|
-
#[cfg(unix)]
|
|
2567
2551
|
impl LinkedHost {
|
|
2568
2552
|
fn new(name: &str) -> Self {
|
|
2569
2553
|
let host = std::env::temp_dir().join(format!("kobako-{name}-{}", std::process::id()));
|
|
2570
2554
|
let _ = std::fs::remove_dir_all(&host);
|
|
2571
2555
|
std::fs::create_dir_all(host.join("real/inner")).expect("the host tree must be made");
|
|
2572
|
-
|
|
2573
|
-
|
|
2556
|
+
super::testing::symlink("real", host.join("dir"));
|
|
2557
|
+
super::testing::symlink("nowhere", host.join("gone"));
|
|
2574
2558
|
Self(host)
|
|
2575
2559
|
}
|
|
2576
2560
|
|
|
@@ -2580,7 +2564,6 @@ impl LinkedHost {
|
|
|
2580
2564
|
}
|
|
2581
2565
|
}
|
|
2582
2566
|
|
|
2583
|
-
#[cfg(unix)]
|
|
2584
2567
|
impl Drop for LinkedHost {
|
|
2585
2568
|
fn drop(&mut self) {
|
|
2586
2569
|
let _ = std::fs::remove_dir_all(&self.0);
|
|
@@ -2591,7 +2574,6 @@ impl Drop for LinkedHost {
|
|
|
2591
2574
|
// link that is not the last name, and the dot answers as one through a
|
|
2592
2575
|
// directory does.
|
|
2593
2576
|
// @behavior RT-161
|
|
2594
|
-
#[cfg(unix)]
|
|
2595
2577
|
#[test]
|
|
2596
2578
|
fn a_path_ending_in_a_dot_through_a_link_is_neither_removed_nor_moved() {
|
|
2597
2579
|
let host = LinkedHost::new("dot-link");
|
|
@@ -2614,7 +2596,6 @@ fn a_path_ending_in_a_dot_through_a_link_is_neither_removed_nor_moved() {
|
|
|
2614
2596
|
// The dot is the last name, which these act on rather than land on, so
|
|
2615
2597
|
// nothing of where the link points shows, and the answers are Linux's.
|
|
2616
2598
|
// @behavior RT-219
|
|
2617
|
-
#[cfg(unix)]
|
|
2618
2599
|
#[test]
|
|
2619
2600
|
fn a_change_naming_a_dot_through_a_link_answers_as_linux() {
|
|
2620
2601
|
let host = LinkedHost::new("dot-change");
|
|
@@ -2633,12 +2614,11 @@ fn a_change_naming_a_dot_through_a_link_answers_as_linux() {
|
|
|
2633
2614
|
}
|
|
2634
2615
|
|
|
2635
2616
|
/// The root of `host` beneath a Bind Mount, as the VFS walks it.
|
|
2636
|
-
#[cfg(unix)]
|
|
2637
2617
|
fn bind_root(host: &std::path::Path) -> Path {
|
|
2638
2618
|
let directory = Bind::new(host).expect("the host directory must open");
|
|
2639
2619
|
let mount = Mount::new(
|
|
2640
2620
|
"/data",
|
|
2641
|
-
Filesystem::new(
|
|
2621
|
+
Filesystem::new(directory).expect("the instance must stand"),
|
|
2642
2622
|
Access::ReadWrite,
|
|
2643
2623
|
)
|
|
2644
2624
|
.expect("/data is a guest path");
|
|
@@ -2648,7 +2628,6 @@ fn bind_root(host: &std::path::Path) -> Path {
|
|
|
2648
2628
|
// No security module is registered, so were the link followed the file would
|
|
2649
2629
|
// be made where it points, and only `O_EXCL` keeps that from happening.
|
|
2650
2630
|
// @behavior RT-220
|
|
2651
|
-
#[cfg(unix)]
|
|
2652
2631
|
#[test]
|
|
2653
2632
|
fn an_exclusive_create_follows_no_link_at_the_end() {
|
|
2654
2633
|
let host = LinkedHost::new("excl-link");
|
|
@@ -2658,14 +2637,14 @@ fn an_exclusive_create_follows_no_link_at_the_end() {
|
|
|
2658
2637
|
how.exclusive = true;
|
|
2659
2638
|
how.follow = true;
|
|
2660
2639
|
let answer = vfs::do_file_open(
|
|
2661
|
-
&
|
|
2640
|
+
&prepare_creds(&[], None),
|
|
2662
2641
|
&bind_root(&host.0),
|
|
2663
2642
|
"gone",
|
|
2664
2643
|
&flags_of(&how),
|
|
2665
2644
|
);
|
|
2666
2645
|
assert_eq!(
|
|
2667
2646
|
(answer.err(), host.0.join("nowhere").exists()),
|
|
2668
|
-
(Some(
|
|
2647
|
+
(Some(Errno::AlreadyExists), false),
|
|
2669
2648
|
"vfs::do_file_open with create and exclusive of a link to nothing, asking to follow it, \
|
|
2670
2649
|
must answer EEXIST, as Linux's O_EXCL does, and make nothing"
|
|
2671
2650
|
);
|
|
@@ -2674,18 +2653,12 @@ fn an_exclusive_create_follows_no_link_at_the_end() {
|
|
|
2674
2653
|
// The trailing `/` follows the link, so what is read stands at the directory,
|
|
2675
2654
|
// where the walk that reports a link as itself would answer ENOTDIR.
|
|
2676
2655
|
// @behavior RT-221
|
|
2677
|
-
#[cfg(unix)]
|
|
2678
2656
|
#[test]
|
|
2679
2657
|
fn a_trailing_slash_on_a_link_to_a_directory_reads_no_link() {
|
|
2680
2658
|
let host = LinkedHost::new("readlink-slash");
|
|
2681
2659
|
assert_eq!(
|
|
2682
|
-
vfs::do_readlinkat(
|
|
2683
|
-
|
|
2684
|
-
&bind_root(&host.0),
|
|
2685
|
-
"dir/"
|
|
2686
|
-
)
|
|
2687
|
-
.err(),
|
|
2688
|
-
Some(FilesystemError::InvalidInput),
|
|
2660
|
+
vfs::do_readlinkat(&prepare_creds(&[], None), &bind_root(&host.0), "dir/").err(),
|
|
2661
|
+
Some(Errno::InvalidInput),
|
|
2689
2662
|
"vfs::do_readlinkat of dir/, dir a host link to a directory beneath a Bind Mount, must \
|
|
2690
2663
|
answer EINVAL, as Linux's does"
|
|
2691
2664
|
);
|
|
@@ -2694,7 +2667,6 @@ fn a_trailing_slash_on_a_link_to_a_directory_reads_no_link() {
|
|
|
2694
2667
|
// Linux answers the trailing slash of a create before it would follow the
|
|
2695
2668
|
// link, which points at nothing a create could make.
|
|
2696
2669
|
// @behavior RT-162
|
|
2697
|
-
#[cfg(unix)]
|
|
2698
2670
|
#[test]
|
|
2699
2671
|
fn a_create_through_a_trailing_slash_answers_eisdir_before_following_a_link() {
|
|
2700
2672
|
let host = LinkedHost::new("slash-link");
|
|
@@ -2803,15 +2775,18 @@ fn sizing_a_file_opened_only_to_read_answers_by_its_mount_then_as_linux_does() {
|
|
|
2803
2775
|
#[derive(Default)]
|
|
2804
2776
|
struct RecordsAsks(std::sync::Mutex<Vec<(String, Access)>>);
|
|
2805
2777
|
|
|
2806
|
-
impl Policy for RecordsAsks {
|
|
2807
|
-
fn allows(&self,
|
|
2808
|
-
self.0
|
|
2778
|
+
impl Policy<MountRequest<'_>> for RecordsAsks {
|
|
2779
|
+
fn allows(&self, request: &MountRequest<'_>) -> bool {
|
|
2780
|
+
self.0
|
|
2781
|
+
.lock()
|
|
2782
|
+
.unwrap()
|
|
2783
|
+
.push((request.path.to_owned(), request.access));
|
|
2809
2784
|
true
|
|
2810
2785
|
}
|
|
2811
2786
|
}
|
|
2812
2787
|
|
|
2813
|
-
// The Mount is made read-only,
|
|
2814
|
-
//
|
|
2788
|
+
// The Mount is made read-only, so only a Mount allowing writes lets either
|
|
2789
|
+
// through.
|
|
2815
2790
|
// Each Policy is asked only by the open before the call, so a wait or a size
|
|
2816
2791
|
// asking it as well adds an ask the literal lists below do not hold.
|
|
2817
2792
|
// @behavior RT-139
|
|
@@ -2822,7 +2797,7 @@ fn a_mount_whose_policy_decides_may_be_written() {
|
|
|
2822
2797
|
let errno = Guest::new(&[grant(
|
|
2823
2798
|
file_and_directory(),
|
|
2824
2799
|
Access::ReadWrite,
|
|
2825
|
-
Some(policy.clone() as Arc<dyn Policy
|
|
2800
|
+
Some(policy.clone() as Arc<dyn for<'a> Policy<MountRequest<'a>>>),
|
|
2826
2801
|
)])
|
|
2827
2802
|
.call_at(name, rights);
|
|
2828
2803
|
let asked = policy.0.lock().unwrap().clone();
|
|
@@ -2834,8 +2809,8 @@ fn a_mount_whose_policy_decides_may_be_written() {
|
|
|
2834
2809
|
call("size_with", RIGHTS_FD_WRITE),
|
|
2835
2810
|
),
|
|
2836
2811
|
(
|
|
2837
|
-
(0, vec![("/
|
|
2838
|
-
(0, vec![("/
|
|
2812
|
+
(0, vec![("/file.txt".to_owned(), Access::Read)]),
|
|
2813
|
+
(0, vec![("/file.txt".to_owned(), Access::ReadWrite)]),
|
|
2839
2814
|
),
|
|
2840
2815
|
"through preview1 beneath a read-write Mount whose Policy allows every change, \
|
|
2841
2816
|
poll_oneoff waiting to write a file opened only to read must be ready, and \
|
|
@@ -2855,7 +2830,7 @@ fn an_open_that_may_create_asks_to_make_the_file_before_it_finds_what_stands() {
|
|
|
2855
2830
|
let errno = Guest::new(&[grant(
|
|
2856
2831
|
file_and_directory(),
|
|
2857
2832
|
Access::ReadWrite,
|
|
2858
|
-
Some(policy.clone() as Arc<dyn Policy
|
|
2833
|
+
Some(policy.clone() as Arc<dyn for<'a> Policy<MountRequest<'a>>>),
|
|
2859
2834
|
)])
|
|
2860
2835
|
.call_flagged(path, OFLAGS_CREAT, 0);
|
|
2861
2836
|
let asked = policy.0.lock().unwrap().clone();
|
|
@@ -2864,12 +2839,12 @@ fn an_open_that_may_create_asks_to_make_the_file_before_it_finds_what_stands() {
|
|
|
2864
2839
|
assert_eq!(
|
|
2865
2840
|
(open(NEW), open(FILE)),
|
|
2866
2841
|
(
|
|
2867
|
-
(0, vec![("/
|
|
2842
|
+
(0, vec![("/new.txt".to_owned(), Access::ReadWrite)]),
|
|
2868
2843
|
(
|
|
2869
2844
|
0,
|
|
2870
2845
|
vec![
|
|
2871
|
-
("/
|
|
2872
|
-
("/
|
|
2846
|
+
("/file.txt".to_owned(), Access::ReadWrite),
|
|
2847
|
+
("/file.txt".to_owned(), Access::Read),
|
|
2873
2848
|
]
|
|
2874
2849
|
),
|
|
2875
2850
|
),
|
|
@@ -2884,10 +2859,10 @@ fn an_open_that_may_create_asks_to_make_the_file_before_it_finds_what_stands() {
|
|
|
2884
2859
|
#[derive(Default)]
|
|
2885
2860
|
struct RefusesTheRoot(std::sync::Mutex<Vec<String>>);
|
|
2886
2861
|
|
|
2887
|
-
impl Policy for RefusesTheRoot {
|
|
2888
|
-
fn allows(&self,
|
|
2889
|
-
self.0.lock().unwrap().push(path.to_owned());
|
|
2890
|
-
path != "/
|
|
2862
|
+
impl Policy<MountRequest<'_>> for RefusesTheRoot {
|
|
2863
|
+
fn allows(&self, request: &MountRequest<'_>) -> bool {
|
|
2864
|
+
self.0.lock().unwrap().push(request.path.to_owned());
|
|
2865
|
+
request.path != "/"
|
|
2891
2866
|
}
|
|
2892
2867
|
}
|
|
2893
2868
|
|
|
@@ -2901,13 +2876,13 @@ fn a_mount_whose_policy_refuses_its_root_still_reads_beneath_it() {
|
|
|
2901
2876
|
let mut guest = Guest::new(&[grant(
|
|
2902
2877
|
file_and_directory(),
|
|
2903
2878
|
Access::Read,
|
|
2904
|
-
Some(policy.clone() as Arc<dyn Policy
|
|
2879
|
+
Some(policy.clone() as Arc<dyn for<'a> Policy<MountRequest<'a>>>),
|
|
2905
2880
|
)]);
|
|
2906
2881
|
let read = guest.call("read_file", FILE);
|
|
2907
2882
|
let asked = policy.0.lock().unwrap().clone();
|
|
2908
2883
|
assert_eq!(
|
|
2909
2884
|
(read, asked),
|
|
2910
|
-
(0, vec!["/
|
|
2885
|
+
(0, vec!["/file.txt".to_owned()]),
|
|
2911
2886
|
"path_open of a file beneath a Mount whose Policy refuses its root, through preview1, \
|
|
2912
2887
|
must read the file and ask the Policy only about it, as a Linux task opens what it \
|
|
2913
2888
|
keeps before landlock_restrict_self"
|
|
@@ -2926,7 +2901,7 @@ fn an_open_of_a_missing_path_that_makes_nothing_answers_enoent() {
|
|
|
2926
2901
|
let policed = Guest::new(&[grant(
|
|
2927
2902
|
file_and_directory(),
|
|
2928
2903
|
Access::Read,
|
|
2929
|
-
Some(policy.clone() as Arc<dyn Policy
|
|
2904
|
+
Some(policy.clone() as Arc<dyn for<'a> Policy<MountRequest<'a>>>),
|
|
2930
2905
|
)])
|
|
2931
2906
|
.call("append_file", NEW);
|
|
2932
2907
|
let asked = policy.0.lock().unwrap().clone();
|
|
@@ -2996,7 +2971,7 @@ const ERRNO_PERM: i32 = 63;
|
|
|
2996
2971
|
struct ChangesNothing(Arc<dyn InodeOperations>);
|
|
2997
2972
|
|
|
2998
2973
|
impl FileSystemType for ChangesNothing {
|
|
2999
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
2974
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
3000
2975
|
sb.d_make_root(vfs::Inode::new(
|
|
3001
2976
|
&vfs::Kstat::new(vfs::FileType::Dir, 0),
|
|
3002
2977
|
self,
|
|
@@ -3006,11 +2981,11 @@ impl FileSystemType for ChangesNothing {
|
|
|
3006
2981
|
}
|
|
3007
2982
|
|
|
3008
2983
|
impl InodeOperations for ChangesNothing {
|
|
3009
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
2984
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
3010
2985
|
self.0.getattr(dentry)
|
|
3011
2986
|
}
|
|
3012
2987
|
|
|
3013
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
2988
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
3014
2989
|
Ok(match self.0.lookup(dentry)? {
|
|
3015
2990
|
Lookup::Found(inode) => {
|
|
3016
2991
|
Lookup::Found(inode.with_ops(Arc::new(Self(inode.ops().clone()))))
|
|
@@ -3019,11 +2994,7 @@ impl InodeOperations for ChangesNothing {
|
|
|
3019
2994
|
})
|
|
3020
2995
|
}
|
|
3021
2996
|
|
|
3022
|
-
fn open(
|
|
3023
|
-
&self,
|
|
3024
|
-
dentry: &Dentry,
|
|
3025
|
-
how: &OpenHow,
|
|
3026
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
2997
|
+
fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
3027
2998
|
self.0.open(dentry, how)
|
|
3028
2999
|
}
|
|
3029
3000
|
}
|
|
@@ -3237,7 +3208,6 @@ fn a_file_moved_beneath_itself_is_no_directory() {
|
|
|
3237
3208
|
// The link points at nothing, so only the link itself, not a file it
|
|
3238
3209
|
// would follow to, can be what each open finds there.
|
|
3239
3210
|
// @behavior RT-106
|
|
3240
|
-
#[cfg(unix)]
|
|
3241
3211
|
#[test]
|
|
3242
3212
|
fn an_open_following_no_link_finds_a_dangling_link_as_itself() {
|
|
3243
3213
|
let (host, mut guest) = mount_link_under("dangling", |_| {}, Access::ReadWrite, None);
|
|
@@ -3439,39 +3409,25 @@ fn an_open_of_a_directory_answers_its_other_flags_as_linux_does() {
|
|
|
3439
3409
|
);
|
|
3440
3410
|
}
|
|
3441
3411
|
|
|
3442
|
-
#[cfg(unix)]
|
|
3443
3412
|
const UP: (i32, i32) = (1070, 2);
|
|
3444
|
-
#[cfg(unix)]
|
|
3445
3413
|
const THROUGH_UPDIR: (i32, i32) = (1080, 7);
|
|
3446
|
-
#[cfg(unix)]
|
|
3447
3414
|
const IN_LINKED: (i32, i32) = (1090, 4);
|
|
3448
|
-
#[cfg(unix)]
|
|
3449
3415
|
const TWISTY: (i32, i32) = (1100, 6);
|
|
3450
|
-
#[cfg(unix)]
|
|
3451
3416
|
const DANGLE: (i32, i32) = (1110, 6);
|
|
3452
|
-
#[cfg(unix)]
|
|
3453
3417
|
const DIR_UP: (i32, i32) = (1120, 6);
|
|
3454
|
-
#[cfg(unix)]
|
|
3455
3418
|
const NOWHERE: (i32, i32) = (1130, 7);
|
|
3456
|
-
#[cfg(unix)]
|
|
3457
3419
|
const OUT_OF_IN: (i32, i32) = (1160, 20);
|
|
3458
|
-
#[cfg(unix)]
|
|
3459
3420
|
const LOOP: (i32, i32) = (1184, 4);
|
|
3460
|
-
#[cfg(unix)]
|
|
3461
3421
|
const DIR_SUB: (i32, i32) = (1190, 7);
|
|
3462
|
-
#[cfg(unix)]
|
|
3463
3422
|
const DIR_IN_Y: (i32, i32) = (1400, 8);
|
|
3464
|
-
#[cfg(unix)]
|
|
3465
3423
|
const DIR_SUB_Y: (i32, i32) = (1420, 9);
|
|
3466
3424
|
|
|
3467
3425
|
/// A host directory whose `dir` holds links staying within it (`in`,
|
|
3468
3426
|
/// `twisty`), links leading out of it (`up`, `updir`), links pointing at
|
|
3469
3427
|
/// nothing out of it (`dangle`) and within it (`nowhere`), and a link
|
|
3470
3428
|
/// pointing at itself (`loop`).
|
|
3471
|
-
#[cfg(unix)]
|
|
3472
3429
|
struct LinkedBeneath(std::path::PathBuf);
|
|
3473
3430
|
|
|
3474
|
-
#[cfg(unix)]
|
|
3475
3431
|
impl LinkedBeneath {
|
|
3476
3432
|
fn new(name: &str) -> Self {
|
|
3477
3433
|
let host =
|
|
@@ -3492,7 +3448,7 @@ impl LinkedBeneath {
|
|
|
3492
3448
|
("missing", "dir/nowhere"),
|
|
3493
3449
|
("loop", "dir/loop"),
|
|
3494
3450
|
] {
|
|
3495
|
-
|
|
3451
|
+
super::testing::symlink(target, host.join(link));
|
|
3496
3452
|
}
|
|
3497
3453
|
Self(host)
|
|
3498
3454
|
}
|
|
@@ -3505,7 +3461,7 @@ impl LinkedBeneath {
|
|
|
3505
3461
|
Arc::new(
|
|
3506
3462
|
Overlay::new(
|
|
3507
3463
|
vec![Filesystem::new(directory).expect("the instance must stand")],
|
|
3508
|
-
Some(Filesystem::new(
|
|
3464
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
3509
3465
|
)
|
|
3510
3466
|
.expect("an upper over a lower Layer must make a view"),
|
|
3511
3467
|
)
|
|
@@ -3516,7 +3472,6 @@ impl LinkedBeneath {
|
|
|
3516
3472
|
}
|
|
3517
3473
|
}
|
|
3518
3474
|
|
|
3519
|
-
#[cfg(unix)]
|
|
3520
3475
|
impl Drop for LinkedBeneath {
|
|
3521
3476
|
fn drop(&mut self) {
|
|
3522
3477
|
let _ = std::fs::remove_dir_all(&self.0);
|
|
@@ -3526,7 +3481,6 @@ impl Drop for LinkedBeneath {
|
|
|
3526
3481
|
// Each link names a real file outside `dir` yet inside the Mount, so only
|
|
3527
3482
|
// a link kept within the descriptor, not the Mount's root, is refused.
|
|
3528
3483
|
// @behavior RT-140
|
|
3529
|
-
#[cfg(unix)]
|
|
3530
3484
|
#[test]
|
|
3531
3485
|
fn a_link_leading_out_of_an_opened_directory_escapes_it() {
|
|
3532
3486
|
let host = LinkedBeneath::new("out");
|
|
@@ -3556,7 +3510,6 @@ fn a_link_leading_out_of_an_opened_directory_escapes_it() {
|
|
|
3556
3510
|
// The second `..` leaves `sub`, where `in` led, two names after the link, so
|
|
3557
3511
|
// only a walk standing where the link led reaches `sub/y` from `dir`.
|
|
3558
3512
|
// @behavior RT-119
|
|
3559
|
-
#[cfg(unix)]
|
|
3560
3513
|
#[test]
|
|
3561
3514
|
fn a_step_out_of_where_a_link_led_lands_beside_it() {
|
|
3562
3515
|
let host = LinkedBeneath::new("led");
|
|
@@ -3574,7 +3527,6 @@ fn a_step_out_of_where_a_link_led_lands_beside_it() {
|
|
|
3574
3527
|
// on its own, so only a rename recognised as onto its own path, rather
|
|
3575
3528
|
// than by the directory each walk opened, changes nothing and succeeds.
|
|
3576
3529
|
// @behavior RT-155
|
|
3577
|
-
#[cfg(unix)]
|
|
3578
3530
|
#[test]
|
|
3579
3531
|
fn a_directory_renamed_onto_its_own_path_beneath_a_policy_stays() {
|
|
3580
3532
|
let host = LinkedBeneath::new("onto-itself");
|
|
@@ -3598,7 +3550,6 @@ fn a_directory_renamed_onto_its_own_path_beneath_a_policy_stays() {
|
|
|
3598
3550
|
// The two paths differ, so only the walk ending on one dentry tells the
|
|
3599
3551
|
// rename it is onto itself; otherwise it waits on that name's lock twice.
|
|
3600
3552
|
// @behavior RT-168
|
|
3601
|
-
#[cfg(unix)]
|
|
3602
3553
|
#[test]
|
|
3603
3554
|
fn a_file_renamed_onto_itself_through_a_link_stays() {
|
|
3604
3555
|
let host = LinkedBeneath::new("onto-itself-linked");
|
|
@@ -3615,7 +3566,6 @@ fn a_file_renamed_onto_itself_through_a_link_stays() {
|
|
|
3615
3566
|
}
|
|
3616
3567
|
|
|
3617
3568
|
// @behavior RT-154
|
|
3618
|
-
#[cfg(unix)]
|
|
3619
3569
|
#[test]
|
|
3620
3570
|
fn a_link_loop_answers_eloop() {
|
|
3621
3571
|
let host = LinkedBeneath::new("loop");
|
|
@@ -3629,7 +3579,6 @@ fn a_link_loop_answers_eloop() {
|
|
|
3629
3579
|
}
|
|
3630
3580
|
|
|
3631
3581
|
// @behavior RT-141
|
|
3632
|
-
#[cfg(unix)]
|
|
3633
3582
|
#[test]
|
|
3634
3583
|
fn a_link_staying_within_an_opened_directory_is_followed() {
|
|
3635
3584
|
let host = LinkedBeneath::new("in");
|
|
@@ -3650,7 +3599,6 @@ fn a_link_staying_within_an_opened_directory_is_followed() {
|
|
|
3650
3599
|
|
|
3651
3600
|
// An Overlay's change lands in its upper, so only a Bind shows it on the host.
|
|
3652
3601
|
// @behavior RT-142
|
|
3653
|
-
#[cfg(unix)]
|
|
3654
3602
|
#[test]
|
|
3655
3603
|
fn a_create_through_a_dangling_link_beneath_an_opened_directory_makes_its_target() {
|
|
3656
3604
|
let answers = |name, overlay| {
|
|
@@ -3672,7 +3620,6 @@ fn a_create_through_a_dangling_link_beneath_an_opened_directory_makes_its_target
|
|
|
3672
3620
|
// The link names a file outside the host directory by an absolute path, so
|
|
3673
3621
|
// the walk refuses it before any host call is made.
|
|
3674
3622
|
// @behavior RT-143
|
|
3675
|
-
#[cfg(unix)]
|
|
3676
3623
|
#[test]
|
|
3677
3624
|
fn a_link_leading_out_of_a_mount_escapes_it() {
|
|
3678
3625
|
let host = LinkedBeneath::new("mount");
|
|
@@ -3680,7 +3627,7 @@ fn a_link_leading_out_of_a_mount_escapes_it() {
|
|
|
3680
3627
|
std::env::temp_dir().join(format!("kobako-beneath-outside-{}", std::process::id()));
|
|
3681
3628
|
std::fs::write(&outside, "host").expect("the outside file must be written");
|
|
3682
3629
|
std::fs::remove_file(host.0.join("dir/up")).expect("the link must be removed");
|
|
3683
|
-
|
|
3630
|
+
super::testing::symlink(&outside, host.0.join("dir/up"));
|
|
3684
3631
|
let errno = host.guest(false).call("open_following", DIR_UP);
|
|
3685
3632
|
let _ = std::fs::remove_file(&outside);
|
|
3686
3633
|
assert_eq!(
|
|
@@ -3716,27 +3663,27 @@ fn a_files_access_is_checked_before_a_buffer_outside_memory_is_bounded() {
|
|
|
3716
3663
|
#[cfg(unix)]
|
|
3717
3664
|
const PUB_X: (i32, i32) = (1150, 5);
|
|
3718
3665
|
|
|
3719
|
-
/// A Policy allowing `/
|
|
3666
|
+
/// A Policy allowing `/pub/` alone, which swaps `pub` for a link to
|
|
3720
3667
|
/// `secret` the first time it is asked, as another writer could between
|
|
3721
3668
|
/// its judgment and the call.
|
|
3722
3669
|
#[cfg(unix)]
|
|
3723
3670
|
struct SwapsWhileAsked(std::path::PathBuf, std::sync::atomic::AtomicBool);
|
|
3724
3671
|
|
|
3725
3672
|
#[cfg(unix)]
|
|
3726
|
-
impl Policy for SwapsWhileAsked {
|
|
3727
|
-
fn allows(&self,
|
|
3673
|
+
impl Policy<MountRequest<'_>> for SwapsWhileAsked {
|
|
3674
|
+
fn allows(&self, request: &MountRequest<'_>) -> bool {
|
|
3728
3675
|
if self.1.swap(false, Ordering::SeqCst) {
|
|
3729
3676
|
std::fs::rename(self.0.join("pub"), self.0.join("pub_old")).expect("pub must move");
|
|
3730
|
-
|
|
3731
|
-
.expect("the link must be made");
|
|
3677
|
+
super::testing::symlink("secret", self.0.join("pub"));
|
|
3732
3678
|
}
|
|
3733
|
-
path.starts_with("/
|
|
3679
|
+
request.path.starts_with("/pub/")
|
|
3734
3680
|
}
|
|
3735
3681
|
}
|
|
3736
3682
|
|
|
3737
3683
|
// The swap happens inside the Policy's own judgment, after the walk opened
|
|
3738
3684
|
// `pub`, so only a call acting on the directory it walked to, rather than
|
|
3739
|
-
// on the path again, keeps from reading `secret/x`.
|
|
3685
|
+
// on the path again, keeps from reading `secret/x`. Windows refuses to move a
|
|
3686
|
+
// directory the walk holds open, so there no swap can be staged.
|
|
3740
3687
|
// @behavior RT-145
|
|
3741
3688
|
#[cfg(unix)]
|
|
3742
3689
|
#[test]
|