kobako 0.31.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 +125 -0
- data/Cargo.lock +457 -494
- data/README.md +2 -3
- data/ROADMAP.md +0 -1
- data/crates/kobako-runtime/CHANGELOG.md +90 -0
- data/crates/kobako-runtime/Cargo.toml +14 -15
- data/crates/kobako-runtime/README.md +1 -1
- data/crates/kobako-runtime/src/cred.rs +32 -20
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +300 -22
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +56 -22
- data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +33 -14
- data/crates/kobako-runtime/src/filesystem/bind.rs +393 -220
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +2 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +9 -10
- data/crates/kobako-runtime/src/filesystem/overlay.rs +277 -46
- data/crates/kobako-runtime/src/filesystem/rdir.rs +8 -27
- data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +47 -13
- data/crates/kobako-runtime/src/filesystem.rs +2 -0
- data/crates/kobako-runtime/src/fork.rs +239 -16
- data/crates/kobako-runtime/src/limits.rs +17 -41
- data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
- data/crates/kobako-runtime/src/locking.rs +508 -113
- data/crates/kobako-runtime/src/memcg.rs +83 -160
- data/crates/kobako-runtime/src/mount.rs +0 -30
- data/crates/kobako-runtime/src/net/connections.rs +53 -13
- data/crates/kobako-runtime/src/net/egress.rs +44 -24
- data/crates/kobako-runtime/src/net/http.rs +888 -456
- data/crates/kobako-runtime/src/net/lookup.rs +150 -50
- data/crates/kobako-runtime/src/net/namespace.rs +97 -95
- data/crates/kobako-runtime/src/net/reactor.rs +298 -203
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +8 -3
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +50 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +29 -23
- data/crates/kobako-runtime/src/net/resolv/windows.rs +14 -44
- data/crates/kobako-runtime/src/net/resolv.rs +39 -15
- data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
- data/crates/kobako-runtime/src/net/socket.rs +51 -52
- data/crates/kobako-runtime/src/net/task.rs +223 -0
- data/crates/kobako-runtime/src/net/tcp.rs +410 -158
- data/crates/kobako-runtime/src/net/tls.rs +65 -3
- data/crates/kobako-runtime/src/net/transport.rs +72 -47
- data/crates/kobako-runtime/src/net/udp.rs +231 -129
- data/crates/kobako-runtime/src/net.rs +3 -0
- data/crates/kobako-runtime/src/sched.rs +244 -58
- data/crates/kobako-runtime/src/security.rs +27 -16
- data/crates/kobako-runtime/src/vfs/dentry.rs +80 -41
- data/crates/kobako-runtime/src/vfs/file.rs +52 -53
- data/crates/kobako-runtime/src/vfs/kern_path.rs +24 -11
- data/crates/kobako-runtime/src/vfs/namei.rs +399 -184
- data/crates/kobako-runtime/src/vfs/namespace.rs +123 -40
- data/crates/kobako-runtime/src/vfs/stat.rs +105 -16
- data/crates/kobako-runtime/src/vfs.rs +1 -0
- data/crates/kobako-runtime/src/wait.rs +75 -50
- data/crates/kobako-transport/CHANGELOG.md +7 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +1 -1
- data/crates/kobako-wasmtime/CHANGELOG.md +47 -0
- data/crates/kobako-wasmtime/Cargo.toml +27 -6
- data/crates/kobako-wasmtime/README.md +3 -3
- data/crates/kobako-wasmtime/src/abi.rs +2 -1
- data/crates/kobako-wasmtime/src/ambient.rs +11 -2
- 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 +88 -103
- data/crates/kobako-wasmtime/src/driver.rs +40 -27
- data/crates/kobako-wasmtime/src/invocation.rs +21 -7
- data/crates/kobako-wasmtime/src/lib.rs +2 -0
- data/crates/kobako-wasmtime/src/limiter.rs +78 -25
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +13 -17
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +4 -5
- data/crates/kobako-wasmtime/src/preview1/differential.rs +1 -1
- data/crates/kobako-wasmtime/src/preview1/fd.rs +23 -19
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +130 -197
- data/crates/kobako-wasmtime/src/preview1/path.rs +3 -3
- data/crates/kobako-wasmtime/src/preview1/poll.rs +28 -22
- data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
- data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
- data/crates/kobako-wasmtime/src/preview1.rs +85 -9
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +2 -2
- data/crates/kobako-wasmtime/src/preview2/host.rs +609 -249
- data/crates/kobako-wasmtime/src/preview2/http.rs +299 -215
- data/crates/kobako-wasmtime/src/preview2/io.rs +17 -4
- data/crates/kobako-wasmtime/src/preview2/table.rs +24 -72
- data/crates/kobako-wasmtime/src/trap.rs +68 -23
- data/crates/kobako-wasmtime/src/waits.rs +59 -0
- data/crates/kobako-wasmtime/src/wasi.rs +91 -10
- 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/escape.rs +332 -26
- data/ext/kobako/src/filesystem/grants.rs +5 -7
- data/ext/kobako/src/filesystem/ruby.rs +10 -3
- data/ext/kobako/src/filesystem.rs +47 -8
- data/ext/kobako/src/fork.rs +72 -0
- data/ext/kobako/src/gvl.rs +499 -76
- data/ext/kobako/src/handoff.rs +490 -0
- data/ext/kobako/src/lib.rs +10 -0
- data/ext/kobako/src/network.rs +5 -3
- data/ext/kobako/src/pinned_value.rs +28 -15
- data/ext/kobako/src/runtime/bridge.rs +32 -25
- data/ext/kobako/src/runtime.rs +74 -43
- data/lib/kobako/catalog/handles.rb +9 -5
- data/lib/kobako/codec/decoder.rb +1 -1
- data/lib/kobako/codec/state.rb +2 -18
- data/lib/kobako/codec/value_budget.rb +4 -4
- data/lib/kobako/codec.rb +5 -6
- data/lib/kobako/errors.rb +4 -7
- data/lib/kobako/filesystem.rb +1 -1
- data/lib/kobako/fork.rb +42 -0
- data/lib/kobako/handle.rb +1 -2
- data/lib/kobako/sandbox.rb +17 -36
- data/lib/kobako/sandbox_options.rb +7 -9
- data/lib/kobako/usage.rb +4 -2
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +2 -2
- data/sig/kobako/catalog/handles.rbs +2 -0
- data/sig/kobako/codec/state.rbs +0 -4
- data/sig/kobako/codec/value_budget.rbs +1 -1
- data/sig/kobako/codec.rbs +2 -2
- data/sig/kobako/errors.rbs +0 -3
- data/sig/kobako/fork.rbs +17 -0
- data/sig/kobako/runtime.rbs +2 -2
- data/sig/kobako/sandbox.rbs +3 -12
- data/sig/kobako/sandbox_options.rbs +0 -2
- metadata +15 -4
- data/lib/kobako/pool.rb +0 -162
- data/sig/core/thread.rbs +0 -6
- data/sig/kobako/pool.rbs +0 -46
|
@@ -68,10 +68,8 @@ const ERRNO_MFILE: i32 = 33;
|
|
|
68
68
|
const ERRNO_INVAL: i32 = 28;
|
|
69
69
|
const ERRNO_IO: i32 = 29;
|
|
70
70
|
const ERRNO_ISDIR: i32 = 31;
|
|
71
|
-
#[cfg(unix)]
|
|
72
71
|
const ERRNO_LOOP: i32 = 32;
|
|
73
72
|
const ERRNO_NOENT: i32 = 44;
|
|
74
|
-
const ERRNO_NOMEM: i32 = 48;
|
|
75
73
|
const ERRNO_OVERFLOW: i32 = 61;
|
|
76
74
|
const ERRNO_NOTDIR: i32 = 54;
|
|
77
75
|
const ERRNO_NOTEMPTY: i32 = 55;
|
|
@@ -156,11 +154,12 @@ const PROBE_WAT: &str = r#"
|
|
|
156
154
|
(data (i32.const 700) "file.txt")
|
|
157
155
|
(data (i32.const 720) "../file.txt")
|
|
158
156
|
|
|
159
|
-
|
|
157
|
+
;; The name of the preopen at the descriptor into 512.
|
|
158
|
+
(func (export "preopen_name") (param $fd i32) (result i32)
|
|
160
159
|
(local $errno i32)
|
|
161
|
-
(local.set $errno (call $prestat (
|
|
160
|
+
(local.set $errno (call $prestat (local.get $fd) (i32.const 256)))
|
|
162
161
|
(if (local.get $errno) (then (return (local.get $errno))))
|
|
163
|
-
(call $prestat_name (
|
|
162
|
+
(call $prestat_name (local.get $fd) (i32.const 512) (i32.load (i32.const 260))))
|
|
164
163
|
|
|
165
164
|
;; Open the path read-only and read it into 512.
|
|
166
165
|
(func (export "read_file") (param $path i32) (param $len i32) (result i32)
|
|
@@ -457,7 +456,6 @@ const THROUGH_MISSING: (i32, i32) = (760, 19);
|
|
|
457
456
|
const OUT_OF_FILE: (i32, i32) = (780, 11);
|
|
458
457
|
const FILE_AS_DIRECTORY: (i32, i32) = (800, 9);
|
|
459
458
|
const NEW_AS_DIRECTORY: (i32, i32) = (820, 8);
|
|
460
|
-
#[cfg(unix)]
|
|
461
459
|
const THROUGH_FILE: (i32, i32) = (860, 12);
|
|
462
460
|
const DIR_DOT: (i32, i32) = (880, 5);
|
|
463
461
|
const DIR_DOT_DOT: (i32, i32) = (890, 6);
|
|
@@ -465,16 +463,12 @@ const BENEATH_FILE: (i32, i32) = (900, 10);
|
|
|
465
463
|
const MOVED: (i32, i32) = (920, 5);
|
|
466
464
|
const DIR: (i32, i32) = (930, 3);
|
|
467
465
|
const MISSING_DOT: (i32, i32) = (940, 9);
|
|
468
|
-
#[cfg(unix)]
|
|
469
466
|
const LINK_DOT: (i32, i32) = (970, 10);
|
|
470
|
-
#[cfg(unix)]
|
|
471
467
|
const OUT_OF_LINK: (i32, i32) = (990, 20);
|
|
472
468
|
const HOLDING_NUL: (i32, i32) = (1010, 9);
|
|
473
469
|
const NOT_UTF8: (i32, i32) = (1440, 1);
|
|
474
470
|
const DIR_FILE: (i32, i32) = (1030, 12);
|
|
475
|
-
#[cfg(unix)]
|
|
476
471
|
const DIR_AS_DIRECTORY: (i32, i32) = (1050, 4);
|
|
477
|
-
#[cfg(unix)]
|
|
478
472
|
const GONE_AS_DIRECTORY: (i32, i32) = (1060, 5);
|
|
479
473
|
const ERRNO_EXIST: i32 = 20;
|
|
480
474
|
const OFLAGS_EXCL: i32 = 1 << 2;
|
|
@@ -492,11 +486,11 @@ fn grant(
|
|
|
492
486
|
policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
|
|
493
487
|
) -> Grant {
|
|
494
488
|
let mount = Mount::new(
|
|
495
|
-
"/
|
|
489
|
+
"/",
|
|
496
490
|
Filesystem::new(filesystem).expect("the instance must stand"),
|
|
497
491
|
access,
|
|
498
492
|
)
|
|
499
|
-
.expect("/
|
|
493
|
+
.expect("/ is a guest path");
|
|
500
494
|
Grant::Mount(match policy {
|
|
501
495
|
Some(policy) => mount.with_policy(policy),
|
|
502
496
|
None => mount,
|
|
@@ -516,40 +510,27 @@ impl Guest {
|
|
|
516
510
|
|
|
517
511
|
/// A guest holding at most `open_file_limit` descriptors at once.
|
|
518
512
|
fn with_open_file_limit(open_file_limit: Option<usize>, grants: &[Grant]) -> Self {
|
|
519
|
-
Self::build(open_file_limit,
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/// A guest allotted `memory_limit` bytes.
|
|
523
|
-
fn with_memory_limit(memory_limit: usize, grants: &[Grant]) -> Self {
|
|
524
|
-
Self::build(
|
|
525
|
-
None,
|
|
526
|
-
Some(memory_limit),
|
|
527
|
-
Profile::Hermetic,
|
|
528
|
-
Vec::new(),
|
|
529
|
-
grants,
|
|
530
|
-
)
|
|
513
|
+
Self::build(open_file_limit, Profile::Hermetic, Vec::new(), grants)
|
|
531
514
|
}
|
|
532
515
|
|
|
533
516
|
/// A guest on `profile`.
|
|
534
517
|
fn for_profile(profile: Profile, grants: &[Grant]) -> Self {
|
|
535
|
-
Self::build(None,
|
|
518
|
+
Self::build(None, profile, Vec::new(), grants)
|
|
536
519
|
}
|
|
537
520
|
|
|
538
521
|
/// A guest whose Driver was built with `security`.
|
|
539
522
|
fn with_security(security: Vec<Arc<dyn SecurityOperations>>, grants: &[Grant]) -> Self {
|
|
540
|
-
Self::build(None,
|
|
523
|
+
Self::build(None, Profile::Hermetic, security, grants)
|
|
541
524
|
}
|
|
542
525
|
|
|
543
526
|
fn build(
|
|
544
527
|
open_file_limit: Option<usize>,
|
|
545
|
-
memory_limit: Option<usize>,
|
|
546
528
|
profile: Profile,
|
|
547
529
|
security: Vec<Arc<dyn SecurityOperations>>,
|
|
548
530
|
grants: &[Grant],
|
|
549
531
|
) -> Self {
|
|
550
532
|
let engine = load_engine().expect("shared engine must be constructible");
|
|
551
533
|
let mut config = Config::for_profile(profile);
|
|
552
|
-
config.limits.memory_limit = memory_limit;
|
|
553
534
|
config.limits.open_file_limit = open_file_limit;
|
|
554
535
|
config.security = security;
|
|
555
536
|
let wasi = Wasi::for_invocation(&config, grants).expect("WASI context must build");
|
|
@@ -625,6 +606,15 @@ impl Guest {
|
|
|
625
606
|
.expect("probe call must not trap")
|
|
626
607
|
}
|
|
627
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
|
+
|
|
628
618
|
/// Stat `file.txt`, without following a link, into 384.
|
|
629
619
|
fn call_flagged_stat(&mut self) -> i32 {
|
|
630
620
|
self.instance
|
|
@@ -811,7 +801,7 @@ impl InodeOperations for StoresUpperCase {
|
|
|
811
801
|
// @behavior RT-120
|
|
812
802
|
#[test]
|
|
813
803
|
fn a_policy_judges_a_path_as_its_filesystem_stores_it() {
|
|
814
|
-
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/
|
|
804
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/FILE.TXT"));
|
|
815
805
|
let mut guest = Guest::new(&[grant(
|
|
816
806
|
Arc::new(StoresUpperCase(&["FILE.TXT"])),
|
|
817
807
|
Access::Read,
|
|
@@ -820,18 +810,18 @@ fn a_policy_judges_a_path_as_its_filesystem_stores_it() {
|
|
|
820
810
|
assert_eq!(
|
|
821
811
|
guest.call("read_file", FILE),
|
|
822
812
|
ERRNO_ACCES,
|
|
823
|
-
"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 \
|
|
824
814
|
Filesystem storing that name as `FILE.TXT`, through preview1 must answer EACCES"
|
|
825
815
|
);
|
|
826
816
|
}
|
|
827
817
|
|
|
828
818
|
// A Policy handed the descriptor's path as the guest spelled it would see
|
|
829
|
-
// `/
|
|
819
|
+
// `/dir/inner` and let the read through.
|
|
830
820
|
// @behavior RT-120
|
|
831
821
|
#[test]
|
|
832
822
|
fn a_policy_judges_a_path_beneath_an_opened_directory_as_its_filesystem_stores_it() {
|
|
833
823
|
const INNER: (i32, i32) = (960, 5);
|
|
834
|
-
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/
|
|
824
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/DIR/INNER"));
|
|
835
825
|
let mut guest = Guest::new(&[grant(
|
|
836
826
|
Arc::new(StoresUpperCase(&["DIR/INNER"])),
|
|
837
827
|
Access::Read,
|
|
@@ -841,28 +831,37 @@ fn a_policy_judges_a_path_beneath_an_opened_directory_as_its_filesystem_stores_i
|
|
|
841
831
|
guest.call("open_beneath_dir", INNER),
|
|
842
832
|
ERRNO_ACCES,
|
|
843
833
|
"path_open of `inner` through `dir` opened beneath a Mount whose Policy refuses \
|
|
844
|
-
`/
|
|
834
|
+
`/DIR/INNER`, over a Filesystem storing both names in upper case, through \
|
|
845
835
|
preview1 must answer EACCES"
|
|
846
836
|
);
|
|
847
837
|
}
|
|
848
838
|
|
|
849
839
|
// @behavior RT-075
|
|
850
840
|
#[test]
|
|
851
|
-
fn
|
|
852
|
-
let
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
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),
|
|
857
855
|
);
|
|
858
856
|
let memory = guest
|
|
859
857
|
.instance
|
|
860
858
|
.get_memory(&mut guest.store, "memory")
|
|
861
859
|
.expect("probe exports its memory");
|
|
860
|
+
let data = memory.data(&guest.store);
|
|
862
861
|
assert_eq!(
|
|
863
|
-
&
|
|
864
|
-
b"/
|
|
865
|
-
"
|
|
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"
|
|
866
865
|
);
|
|
867
866
|
}
|
|
868
867
|
|
|
@@ -922,16 +921,21 @@ fn a_permissive_guest_tells_entries_apart_by_their_inode_numbers() {
|
|
|
922
921
|
);
|
|
923
922
|
}
|
|
924
923
|
|
|
925
|
-
// A Tmpfs's device number depends on how many came before it, so
|
|
926
|
-
//
|
|
927
|
-
// @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
|
|
928
927
|
#[test]
|
|
929
|
-
fn
|
|
928
|
+
fn a_hermetic_guest_tells_entries_apart_by_numbers_of_its_own() {
|
|
929
|
+
let (stat, listed, dot) = inodes_seen(Profile::Hermetic);
|
|
930
930
|
assert_eq!(
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
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}"
|
|
935
939
|
);
|
|
936
940
|
}
|
|
937
941
|
|
|
@@ -993,57 +997,16 @@ fn a_listing_goes_on_over_the_entries_it_began_with() {
|
|
|
993
997
|
);
|
|
994
998
|
}
|
|
995
999
|
|
|
996
|
-
// A buffer of 51 takes only the dots, one of 4096 the whole listing; the limit
|
|
997
|
-
// the listing is held against is the memory the guest was allotted, counted
|
|
998
|
-
// from the moment the listing is read.
|
|
999
|
-
// @behavior RT-237
|
|
1000
|
-
#[test]
|
|
1001
|
-
fn a_listing_it_cannot_hold_within_a_guests_memory_answers_enomem() {
|
|
1002
|
-
let dir = host_dir_with_a_file("holds");
|
|
1003
|
-
let answer = |memory_limit, len| {
|
|
1004
|
-
let bind = Arc::new(Bind::new(&dir).expect("the host directory must open"));
|
|
1005
|
-
let mut guest =
|
|
1006
|
-
Guest::with_memory_limit(memory_limit, &[grant(bind, Access::ReadWrite, None)]);
|
|
1007
|
-
let errno = guest.call_list(0, len);
|
|
1008
|
-
let memory = guest
|
|
1009
|
-
.instance
|
|
1010
|
-
.get_memory(&mut guest.store, "memory")
|
|
1011
|
-
.expect("probe exports its memory");
|
|
1012
|
-
let used = u32::from_le_bytes(memory.data(&guest.store)[136..140].try_into().unwrap());
|
|
1013
|
-
(errno, used)
|
|
1014
|
-
};
|
|
1015
|
-
assert_eq!(
|
|
1016
|
-
[answer(1, 51), answer(1, 4096), answer(1 << 20, 51)],
|
|
1017
|
-
[(ERRNO_NOMEM, 0), (ERRNO_NOMEM, 0), (0, 51)],
|
|
1018
|
-
"fd_readdir through preview1, with more to hold than the guest's memory_limit, must \
|
|
1019
|
-
answer ENOMEM before it hands any entry, read part way or whole, and within it succeed"
|
|
1020
|
-
);
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
// @behavior RT-400
|
|
1024
|
-
#[test]
|
|
1025
|
-
fn an_open_the_memory_limit_cannot_hold_answers_enomem_whatever_the_path_names() {
|
|
1026
|
-
let mut starved =
|
|
1027
|
-
Guest::with_memory_limit(1, &[grant(file_and_directory(), Access::Read, None)]);
|
|
1028
|
-
let refused = [FILE, THROUGH_MISSING].map(|path| starved.call("open_close", path));
|
|
1029
|
-
let mut held =
|
|
1030
|
-
Guest::with_memory_limit(1 << 20, &[grant(file_and_directory(), Access::Read, None)]);
|
|
1031
|
-
let reopened = (0..10_000).all(|_| held.call("open_close", FILE) == 0);
|
|
1032
|
-
assert_eq!(
|
|
1033
|
-
(refused, reopened),
|
|
1034
|
-
([ERRNO_NOMEM; 2], true),
|
|
1035
|
-
"path_open through preview1 under a memory_limit that holds no more files must answer \
|
|
1036
|
-
ENOMEM for a file and a missing path alike, as Linux's path_openat allocates the file \
|
|
1037
|
-
before the walk, and a closed file must give its room back for the next open"
|
|
1038
|
-
);
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
1000
|
/// A root whose listing hands `.` and `..`, then fails as a host read would.
|
|
1042
1001
|
struct FailsPastTheDots;
|
|
1043
1002
|
|
|
1044
1003
|
struct FailsPastTheDotsDir;
|
|
1045
1004
|
|
|
1046
1005
|
impl FileOperations for FailsPastTheDotsDir {
|
|
1006
|
+
fn has_iterate_shared(&self) -> bool {
|
|
1007
|
+
true
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1047
1010
|
fn iterate_shared(
|
|
1048
1011
|
&mut self,
|
|
1049
1012
|
dentry: &Dentry,
|
|
@@ -1317,8 +1280,8 @@ fn a_descriptor_moved_beneath_a_policy_still_lists_itself() {
|
|
|
1317
1280
|
fn a_directory_moved_beneath_another_mount_of_its_instance_is_reached_beneath_a_policy() {
|
|
1318
1281
|
let open_after_move = |policy: Arc<dyn for<'a> Policy<MountRequest<'a>>>| {
|
|
1319
1282
|
let instance = Filesystem::new(file_and_directory()).expect("the instance must stand");
|
|
1320
|
-
let mount =
|
|
1321
|
-
.expect("/
|
|
1283
|
+
let mount =
|
|
1284
|
+
Mount::new("/", instance.clone(), Access::ReadWrite).expect("/ is a guest path");
|
|
1322
1285
|
let mut guest = Guest::new(&[Grant::Mount(mount.clone().with_policy(policy))]);
|
|
1323
1286
|
assert_eq!(guest.call_bare("open_dir"), 0, "dir must open");
|
|
1324
1287
|
let other = Path::root(mount.mnt());
|
|
@@ -1331,7 +1294,7 @@ fn a_directory_moved_beneath_another_mount_of_its_instance_is_reached_beneath_a_
|
|
|
1331
1294
|
assert_eq!(
|
|
1332
1295
|
(
|
|
1333
1296
|
open_after_move(Arc::new(AllowsAll)),
|
|
1334
|
-
open_after_move(Arc::new(Refuses("/
|
|
1297
|
+
open_after_move(Arc::new(Refuses("/moved/inner")))
|
|
1335
1298
|
),
|
|
1336
1299
|
(0, ERRNO_ACCES),
|
|
1337
1300
|
"path_open of inner through a directory descriptor beneath a Mount with a Policy, \
|
|
@@ -1516,31 +1479,54 @@ fn a_full_table_answers_emfile_whatever_the_path_names() {
|
|
|
1516
1479
|
);
|
|
1517
1480
|
}
|
|
1518
1481
|
|
|
1519
|
-
// The three standard descriptors and the preopen leave room for
|
|
1482
|
+
// The three standard descriptors and the preopen leave room for two more,
|
|
1520
1483
|
// so a directory spanning both Layers taking more than one leaves none
|
|
1521
1484
|
// for the file.
|
|
1522
1485
|
// @behavior RT-152
|
|
1523
1486
|
#[test]
|
|
1524
1487
|
fn an_overlay_directory_takes_one_descriptor_however_many_layers_it_spans() {
|
|
1525
|
-
let
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
)
|
|
1529
|
-
.expect("
|
|
1530
|
-
let
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
);
|
|
1534
|
-
|
|
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 = [
|
|
1535
1504
|
(
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
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"),
|
|
1539
1508
|
),
|
|
1540
|
-
(
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
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");
|
|
1544
1530
|
}
|
|
1545
1531
|
|
|
1546
1532
|
// The open looks the directory up without following a link at its end, so
|
|
@@ -1580,7 +1566,7 @@ fn a_directory_moved_back_to_its_path_is_reached_through_its_descriptor_again()
|
|
|
1580
1566
|
#[test]
|
|
1581
1567
|
fn a_policy_refusing_an_open_answers_access_denied() {
|
|
1582
1568
|
let tmpfs: Tmpfs = [("file.txt", "granted")].into_iter().collect();
|
|
1583
|
-
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/
|
|
1569
|
+
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/file.txt"));
|
|
1584
1570
|
let mut guest = Guest::new(&[grant(Arc::new(tmpfs), Access::Read, Some(policy))]);
|
|
1585
1571
|
assert_eq!(
|
|
1586
1572
|
guest.call("read_file", FILE),
|
|
@@ -1774,23 +1760,18 @@ fn an_append_lands_after_another_writers_append() {
|
|
|
1774
1760
|
|
|
1775
1761
|
#[cfg(unix)]
|
|
1776
1762
|
const FILETYPE_UNKNOWN: u8 = 0;
|
|
1777
|
-
#[cfg(unix)]
|
|
1778
1763
|
const FILETYPE_DIRECTORY: u8 = 3;
|
|
1779
|
-
#[cfg(unix)]
|
|
1780
1764
|
const FILETYPE_REGULAR_FILE: u8 = 4;
|
|
1781
|
-
#[cfg(unix)]
|
|
1782
1765
|
const FILETYPE_SYMBOLIC_LINK: u8 = 7;
|
|
1783
1766
|
|
|
1784
1767
|
/// A host directory of its own holding `file.txt` as a link to `target`,
|
|
1785
1768
|
/// made by `make_target`, and a guest handed it as a read-only Bind
|
|
1786
1769
|
/// Mount.
|
|
1787
|
-
#[cfg(unix)]
|
|
1788
1770
|
fn mount_link(name: &str, make_target: fn(&std::path::Path)) -> (std::path::PathBuf, Guest) {
|
|
1789
1771
|
mount_link_under(name, make_target, Access::Read, None)
|
|
1790
1772
|
}
|
|
1791
1773
|
|
|
1792
1774
|
/// As `linked`, the Mount taking `access` and `policy`.
|
|
1793
|
-
#[cfg(unix)]
|
|
1794
1775
|
fn mount_link_under(
|
|
1795
1776
|
name: &str,
|
|
1796
1777
|
make_target: fn(&std::path::Path),
|
|
@@ -1801,7 +1782,7 @@ fn mount_link_under(
|
|
|
1801
1782
|
let _ = std::fs::remove_dir_all(&host);
|
|
1802
1783
|
std::fs::create_dir_all(&host).expect("the host directory must be created");
|
|
1803
1784
|
make_target(&host.join("target"));
|
|
1804
|
-
|
|
1785
|
+
super::testing::symlink("target", host.join("file.txt"));
|
|
1805
1786
|
let directory = Bind::new(&host).expect("the host directory must open");
|
|
1806
1787
|
let guest = Guest::new(&[grant(Arc::new(directory), access, policy)]);
|
|
1807
1788
|
(host, guest)
|
|
@@ -1810,7 +1791,6 @@ fn mount_link_under(
|
|
|
1810
1791
|
/// What each stat of `path` with the given lookupflags answers, and the
|
|
1811
1792
|
/// filetype it wrote, beneath a Bind Mount whose host directory
|
|
1812
1793
|
/// holds `file.txt` as a link to `target`, made by `make_target`.
|
|
1813
|
-
#[cfg(unix)]
|
|
1814
1794
|
fn stat_link(
|
|
1815
1795
|
name: &str,
|
|
1816
1796
|
make_target: fn(&std::path::Path),
|
|
@@ -1898,7 +1878,6 @@ fn a_guest_sees_a_socket_as_one_and_cannot_open_it() {
|
|
|
1898
1878
|
// The link points at a regular file, so only a stat that follows none
|
|
1899
1879
|
// can answer a link.
|
|
1900
1880
|
// @behavior RT-097
|
|
1901
|
-
#[cfg(unix)]
|
|
1902
1881
|
#[test]
|
|
1903
1882
|
fn a_stat_following_no_link_reports_the_link_itself() {
|
|
1904
1883
|
let answers = stat_link(
|
|
@@ -1917,7 +1896,6 @@ fn a_stat_following_no_link_reports_the_link_itself() {
|
|
|
1917
1896
|
// A host link reports the length of where it points, so only what the runtime
|
|
1918
1897
|
// shows a guest keeps that length from it.
|
|
1919
1898
|
// @behavior RT-173
|
|
1920
|
-
#[cfg(unix)]
|
|
1921
1899
|
#[test]
|
|
1922
1900
|
fn a_link_reports_no_size_however_its_filesystem_sizes_it() {
|
|
1923
1901
|
let (host, mut guest) = mount_link("link-size", |target| {
|
|
@@ -2046,7 +2024,6 @@ fn a_file_time_past_what_a_timestamp_holds_answers_overflow() {
|
|
|
2046
2024
|
// The stat follows no link, so only the trailing `/` can make it reach
|
|
2047
2025
|
// the directory the link points at, as Linux's `lstat` does.
|
|
2048
2026
|
// @behavior RT-098
|
|
2049
|
-
#[cfg(unix)]
|
|
2050
2027
|
#[test]
|
|
2051
2028
|
fn a_stat_of_a_link_named_with_a_trailing_slash_reports_its_directory() {
|
|
2052
2029
|
let answers = stat_link(
|
|
@@ -2067,7 +2044,6 @@ fn a_stat_of_a_link_named_with_a_trailing_slash_reports_its_directory() {
|
|
|
2067
2044
|
/// `file.txt/` to a directory beneath a read-write Bind Mount taking
|
|
2068
2045
|
/// `policy`, and whether the link stays; `name` keeps its host directory
|
|
2069
2046
|
/// its own.
|
|
2070
|
-
#[cfg(unix)]
|
|
2071
2047
|
fn change_link_named_as_directory(
|
|
2072
2048
|
name: &str,
|
|
2073
2049
|
policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
|
|
@@ -2086,7 +2062,6 @@ fn change_link_named_as_directory(
|
|
|
2086
2062
|
// directory, so a Policy, refusing only a link a call follows, changes
|
|
2087
2063
|
// neither answer.
|
|
2088
2064
|
// @behavior RT-123
|
|
2089
|
-
#[cfg(unix)]
|
|
2090
2065
|
#[test]
|
|
2091
2066
|
fn a_link_named_with_a_trailing_slash_is_neither_removed_nor_moved() {
|
|
2092
2067
|
assert_eq!(
|
|
@@ -2104,7 +2079,6 @@ fn a_link_named_with_a_trailing_slash_is_neither_removed_nor_moved() {
|
|
|
2104
2079
|
// The link points at nothing, so only an unlink that follows no link
|
|
2105
2080
|
// finds it there to answer ENOTDIR rather than ENOENT.
|
|
2106
2081
|
// @behavior RT-134
|
|
2107
|
-
#[cfg(unix)]
|
|
2108
2082
|
#[test]
|
|
2109
2083
|
fn an_unlink_with_a_trailing_slash_answers_for_the_name_itself() {
|
|
2110
2084
|
let host = std::env::temp_dir().join(format!(
|
|
@@ -2114,7 +2088,7 @@ fn an_unlink_with_a_trailing_slash_answers_for_the_name_itself() {
|
|
|
2114
2088
|
let _ = std::fs::remove_dir_all(&host);
|
|
2115
2089
|
std::fs::create_dir_all(host.join("dir")).expect("the host directory must be created");
|
|
2116
2090
|
std::fs::write(host.join("file.txt"), "granted").expect("the host file must be written");
|
|
2117
|
-
|
|
2091
|
+
super::testing::symlink("nowhere", host.join("gone"));
|
|
2118
2092
|
let directory = Bind::new(&host).expect("the host directory must open");
|
|
2119
2093
|
let mut guest = Guest::new(&[grant(Arc::new(directory), Access::ReadWrite, None)]);
|
|
2120
2094
|
let answers = [
|
|
@@ -2250,7 +2224,6 @@ fn an_allocation_past_a_tmpfs_size_answers_enospc() {
|
|
|
2250
2224
|
// The probe's opens follow no link, so only the trailing `/` can make one
|
|
2251
2225
|
// reach the directory the link points at, as Linux's `open` does.
|
|
2252
2226
|
// @behavior RT-100
|
|
2253
|
-
#[cfg(unix)]
|
|
2254
2227
|
#[test]
|
|
2255
2228
|
fn an_open_following_no_link_refuses_a_link_to_a_directory() {
|
|
2256
2229
|
let (host, mut guest) = mount_link("open-nofollow", |target| {
|
|
@@ -2270,7 +2243,6 @@ fn an_open_following_no_link_refuses_a_link_to_a_directory() {
|
|
|
2270
2243
|
}
|
|
2271
2244
|
|
|
2272
2245
|
/// A host directory linked in as `file.txt`, holding `key`.
|
|
2273
|
-
#[cfg(unix)]
|
|
2274
2246
|
fn directory_with_key(target: &std::path::Path) {
|
|
2275
2247
|
std::fs::create_dir(target).expect("the host directory must be created");
|
|
2276
2248
|
std::fs::write(target.join("key"), "secret").expect("the host file must be written");
|
|
@@ -2279,11 +2251,9 @@ fn directory_with_key(target: &std::path::Path) {
|
|
|
2279
2251
|
// The link itself is allowed; only judging where it leads refuses the key, so
|
|
2280
2252
|
// a walk that took the link's own path for the answer would hand it over.
|
|
2281
2253
|
// @behavior RT-101
|
|
2282
|
-
#[cfg(unix)]
|
|
2283
2254
|
#[test]
|
|
2284
2255
|
fn a_path_through_a_link_beneath_a_mount_with_a_policy_is_judged_where_it_leads() {
|
|
2285
|
-
let refuses_key: Arc<dyn for<'a> Policy<MountRequest<'a>>> =
|
|
2286
|
-
Arc::new(Refuses("/data/target/key"));
|
|
2256
|
+
let refuses_key: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/target/key"));
|
|
2287
2257
|
let (host, mut guest) = mount_link_under(
|
|
2288
2258
|
"policy-link-refused",
|
|
2289
2259
|
directory_with_key,
|
|
@@ -2321,7 +2291,6 @@ fn a_path_through_a_link_beneath_a_mount_with_a_policy_is_judged_where_it_leads(
|
|
|
2321
2291
|
// it and one into itself loops, as beneath a Mount without a Policy, and an unlink
|
|
2322
2292
|
// acts on the link itself.
|
|
2323
2293
|
// @behavior RT-125
|
|
2324
|
-
#[cfg(unix)]
|
|
2325
2294
|
#[test]
|
|
2326
2295
|
fn a_link_out_of_a_directory_or_into_a_loop_answers_as_without_a_policy() {
|
|
2327
2296
|
let outside = std::env::temp_dir().join(format!("kobako-outside-{}", std::process::id()));
|
|
@@ -2341,8 +2310,7 @@ fn a_link_out_of_a_directory_or_into_a_loop_answers_as_without_a_policy() {
|
|
|
2341
2310
|
));
|
|
2342
2311
|
let _ = std::fs::remove_dir_all(&host);
|
|
2343
2312
|
std::fs::create_dir_all(&host).expect("the host directory must be created");
|
|
2344
|
-
|
|
2345
|
-
.expect("the link must be made");
|
|
2313
|
+
super::testing::symlink(target, host.join("file.txt"));
|
|
2346
2314
|
let directory = Bind::new(&host).expect("the host directory must open");
|
|
2347
2315
|
let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
|
|
2348
2316
|
let mut guest =
|
|
@@ -2407,7 +2375,6 @@ impl Hook for FailsLookingUpDir {
|
|
|
2407
2375
|
// Each path lands on what the link's target or its parent holds, so only a
|
|
2408
2376
|
// walk taking `.` and `..` from where the link led answers.
|
|
2409
2377
|
// @behavior RT-119
|
|
2410
|
-
#[cfg(unix)]
|
|
2411
2378
|
#[test]
|
|
2412
2379
|
fn a_step_out_of_a_link_lands_where_it_leads() {
|
|
2413
2380
|
assert_eq!(
|
|
@@ -2550,19 +2517,18 @@ fn a_create_of_what_already_stands_changes_nothing() {
|
|
|
2550
2517
|
// The host file only reads, so a host open asking to create, and so to
|
|
2551
2518
|
// write, would be refused where the guest asked only to read.
|
|
2552
2519
|
// @behavior RT-103
|
|
2553
|
-
#[cfg(unix)]
|
|
2554
2520
|
#[test]
|
|
2555
2521
|
fn a_create_of_a_host_file_that_only_reads_opens_it() {
|
|
2556
|
-
use std::os::unix::fs::PermissionsExt;
|
|
2557
2522
|
let host = std::env::temp_dir().join(format!("kobako-granted-creat-{}", std::process::id()));
|
|
2558
2523
|
let _ = std::fs::remove_dir_all(&host);
|
|
2559
2524
|
std::fs::create_dir_all(&host).expect("the host directory must be created");
|
|
2560
|
-
|
|
2561
|
-
std::fs::
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
.
|
|
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");
|
|
2566
2532
|
let directory = Bind::new(&host).expect("the host directory must open");
|
|
2567
2533
|
let answer = Guest::new(&[grant(Arc::new(directory), Access::ReadWrite, None)]).call_flagged(
|
|
2568
2534
|
FILE,
|
|
@@ -2580,17 +2546,15 @@ fn a_create_of_a_host_file_that_only_reads_opens_it() {
|
|
|
2580
2546
|
/// A host directory of the test's own beneath a read-write Bind Mount,
|
|
2581
2547
|
/// `dir` a link to the directory `real` and `gone` a link to nothing,
|
|
2582
2548
|
/// removed when it drops.
|
|
2583
|
-
#[cfg(unix)]
|
|
2584
2549
|
struct LinkedHost(std::path::PathBuf);
|
|
2585
2550
|
|
|
2586
|
-
#[cfg(unix)]
|
|
2587
2551
|
impl LinkedHost {
|
|
2588
2552
|
fn new(name: &str) -> Self {
|
|
2589
2553
|
let host = std::env::temp_dir().join(format!("kobako-{name}-{}", std::process::id()));
|
|
2590
2554
|
let _ = std::fs::remove_dir_all(&host);
|
|
2591
2555
|
std::fs::create_dir_all(host.join("real/inner")).expect("the host tree must be made");
|
|
2592
|
-
|
|
2593
|
-
|
|
2556
|
+
super::testing::symlink("real", host.join("dir"));
|
|
2557
|
+
super::testing::symlink("nowhere", host.join("gone"));
|
|
2594
2558
|
Self(host)
|
|
2595
2559
|
}
|
|
2596
2560
|
|
|
@@ -2600,7 +2564,6 @@ impl LinkedHost {
|
|
|
2600
2564
|
}
|
|
2601
2565
|
}
|
|
2602
2566
|
|
|
2603
|
-
#[cfg(unix)]
|
|
2604
2567
|
impl Drop for LinkedHost {
|
|
2605
2568
|
fn drop(&mut self) {
|
|
2606
2569
|
let _ = std::fs::remove_dir_all(&self.0);
|
|
@@ -2611,7 +2574,6 @@ impl Drop for LinkedHost {
|
|
|
2611
2574
|
// link that is not the last name, and the dot answers as one through a
|
|
2612
2575
|
// directory does.
|
|
2613
2576
|
// @behavior RT-161
|
|
2614
|
-
#[cfg(unix)]
|
|
2615
2577
|
#[test]
|
|
2616
2578
|
fn a_path_ending_in_a_dot_through_a_link_is_neither_removed_nor_moved() {
|
|
2617
2579
|
let host = LinkedHost::new("dot-link");
|
|
@@ -2634,7 +2596,6 @@ fn a_path_ending_in_a_dot_through_a_link_is_neither_removed_nor_moved() {
|
|
|
2634
2596
|
// The dot is the last name, which these act on rather than land on, so
|
|
2635
2597
|
// nothing of where the link points shows, and the answers are Linux's.
|
|
2636
2598
|
// @behavior RT-219
|
|
2637
|
-
#[cfg(unix)]
|
|
2638
2599
|
#[test]
|
|
2639
2600
|
fn a_change_naming_a_dot_through_a_link_answers_as_linux() {
|
|
2640
2601
|
let host = LinkedHost::new("dot-change");
|
|
@@ -2653,7 +2614,6 @@ fn a_change_naming_a_dot_through_a_link_answers_as_linux() {
|
|
|
2653
2614
|
}
|
|
2654
2615
|
|
|
2655
2616
|
/// The root of `host` beneath a Bind Mount, as the VFS walks it.
|
|
2656
|
-
#[cfg(unix)]
|
|
2657
2617
|
fn bind_root(host: &std::path::Path) -> Path {
|
|
2658
2618
|
let directory = Bind::new(host).expect("the host directory must open");
|
|
2659
2619
|
let mount = Mount::new(
|
|
@@ -2668,7 +2628,6 @@ fn bind_root(host: &std::path::Path) -> Path {
|
|
|
2668
2628
|
// No security module is registered, so were the link followed the file would
|
|
2669
2629
|
// be made where it points, and only `O_EXCL` keeps that from happening.
|
|
2670
2630
|
// @behavior RT-220
|
|
2671
|
-
#[cfg(unix)]
|
|
2672
2631
|
#[test]
|
|
2673
2632
|
fn an_exclusive_create_follows_no_link_at_the_end() {
|
|
2674
2633
|
let host = LinkedHost::new("excl-link");
|
|
@@ -2694,7 +2653,6 @@ fn an_exclusive_create_follows_no_link_at_the_end() {
|
|
|
2694
2653
|
// The trailing `/` follows the link, so what is read stands at the directory,
|
|
2695
2654
|
// where the walk that reports a link as itself would answer ENOTDIR.
|
|
2696
2655
|
// @behavior RT-221
|
|
2697
|
-
#[cfg(unix)]
|
|
2698
2656
|
#[test]
|
|
2699
2657
|
fn a_trailing_slash_on_a_link_to_a_directory_reads_no_link() {
|
|
2700
2658
|
let host = LinkedHost::new("readlink-slash");
|
|
@@ -2709,7 +2667,6 @@ fn a_trailing_slash_on_a_link_to_a_directory_reads_no_link() {
|
|
|
2709
2667
|
// Linux answers the trailing slash of a create before it would follow the
|
|
2710
2668
|
// link, which points at nothing a create could make.
|
|
2711
2669
|
// @behavior RT-162
|
|
2712
|
-
#[cfg(unix)]
|
|
2713
2670
|
#[test]
|
|
2714
2671
|
fn a_create_through_a_trailing_slash_answers_eisdir_before_following_a_link() {
|
|
2715
2672
|
let host = LinkedHost::new("slash-link");
|
|
@@ -2852,8 +2809,8 @@ fn a_mount_whose_policy_decides_may_be_written() {
|
|
|
2852
2809
|
call("size_with", RIGHTS_FD_WRITE),
|
|
2853
2810
|
),
|
|
2854
2811
|
(
|
|
2855
|
-
(0, vec![("/
|
|
2856
|
-
(0, vec![("/
|
|
2812
|
+
(0, vec![("/file.txt".to_owned(), Access::Read)]),
|
|
2813
|
+
(0, vec![("/file.txt".to_owned(), Access::ReadWrite)]),
|
|
2857
2814
|
),
|
|
2858
2815
|
"through preview1 beneath a read-write Mount whose Policy allows every change, \
|
|
2859
2816
|
poll_oneoff waiting to write a file opened only to read must be ready, and \
|
|
@@ -2882,12 +2839,12 @@ fn an_open_that_may_create_asks_to_make_the_file_before_it_finds_what_stands() {
|
|
|
2882
2839
|
assert_eq!(
|
|
2883
2840
|
(open(NEW), open(FILE)),
|
|
2884
2841
|
(
|
|
2885
|
-
(0, vec![("/
|
|
2842
|
+
(0, vec![("/new.txt".to_owned(), Access::ReadWrite)]),
|
|
2886
2843
|
(
|
|
2887
2844
|
0,
|
|
2888
2845
|
vec![
|
|
2889
|
-
("/
|
|
2890
|
-
("/
|
|
2846
|
+
("/file.txt".to_owned(), Access::ReadWrite),
|
|
2847
|
+
("/file.txt".to_owned(), Access::Read),
|
|
2891
2848
|
]
|
|
2892
2849
|
),
|
|
2893
2850
|
),
|
|
@@ -2905,7 +2862,7 @@ struct RefusesTheRoot(std::sync::Mutex<Vec<String>>);
|
|
|
2905
2862
|
impl Policy<MountRequest<'_>> for RefusesTheRoot {
|
|
2906
2863
|
fn allows(&self, request: &MountRequest<'_>) -> bool {
|
|
2907
2864
|
self.0.lock().unwrap().push(request.path.to_owned());
|
|
2908
|
-
request.path != "/
|
|
2865
|
+
request.path != "/"
|
|
2909
2866
|
}
|
|
2910
2867
|
}
|
|
2911
2868
|
|
|
@@ -2925,7 +2882,7 @@ fn a_mount_whose_policy_refuses_its_root_still_reads_beneath_it() {
|
|
|
2925
2882
|
let asked = policy.0.lock().unwrap().clone();
|
|
2926
2883
|
assert_eq!(
|
|
2927
2884
|
(read, asked),
|
|
2928
|
-
(0, vec!["/
|
|
2885
|
+
(0, vec!["/file.txt".to_owned()]),
|
|
2929
2886
|
"path_open of a file beneath a Mount whose Policy refuses its root, through preview1, \
|
|
2930
2887
|
must read the file and ask the Policy only about it, as a Linux task opens what it \
|
|
2931
2888
|
keeps before landlock_restrict_self"
|
|
@@ -3251,7 +3208,6 @@ fn a_file_moved_beneath_itself_is_no_directory() {
|
|
|
3251
3208
|
// The link points at nothing, so only the link itself, not a file it
|
|
3252
3209
|
// would follow to, can be what each open finds there.
|
|
3253
3210
|
// @behavior RT-106
|
|
3254
|
-
#[cfg(unix)]
|
|
3255
3211
|
#[test]
|
|
3256
3212
|
fn an_open_following_no_link_finds_a_dangling_link_as_itself() {
|
|
3257
3213
|
let (host, mut guest) = mount_link_under("dangling", |_| {}, Access::ReadWrite, None);
|
|
@@ -3453,39 +3409,25 @@ fn an_open_of_a_directory_answers_its_other_flags_as_linux_does() {
|
|
|
3453
3409
|
);
|
|
3454
3410
|
}
|
|
3455
3411
|
|
|
3456
|
-
#[cfg(unix)]
|
|
3457
3412
|
const UP: (i32, i32) = (1070, 2);
|
|
3458
|
-
#[cfg(unix)]
|
|
3459
3413
|
const THROUGH_UPDIR: (i32, i32) = (1080, 7);
|
|
3460
|
-
#[cfg(unix)]
|
|
3461
3414
|
const IN_LINKED: (i32, i32) = (1090, 4);
|
|
3462
|
-
#[cfg(unix)]
|
|
3463
3415
|
const TWISTY: (i32, i32) = (1100, 6);
|
|
3464
|
-
#[cfg(unix)]
|
|
3465
3416
|
const DANGLE: (i32, i32) = (1110, 6);
|
|
3466
|
-
#[cfg(unix)]
|
|
3467
3417
|
const DIR_UP: (i32, i32) = (1120, 6);
|
|
3468
|
-
#[cfg(unix)]
|
|
3469
3418
|
const NOWHERE: (i32, i32) = (1130, 7);
|
|
3470
|
-
#[cfg(unix)]
|
|
3471
3419
|
const OUT_OF_IN: (i32, i32) = (1160, 20);
|
|
3472
|
-
#[cfg(unix)]
|
|
3473
3420
|
const LOOP: (i32, i32) = (1184, 4);
|
|
3474
|
-
#[cfg(unix)]
|
|
3475
3421
|
const DIR_SUB: (i32, i32) = (1190, 7);
|
|
3476
|
-
#[cfg(unix)]
|
|
3477
3422
|
const DIR_IN_Y: (i32, i32) = (1400, 8);
|
|
3478
|
-
#[cfg(unix)]
|
|
3479
3423
|
const DIR_SUB_Y: (i32, i32) = (1420, 9);
|
|
3480
3424
|
|
|
3481
3425
|
/// A host directory whose `dir` holds links staying within it (`in`,
|
|
3482
3426
|
/// `twisty`), links leading out of it (`up`, `updir`), links pointing at
|
|
3483
3427
|
/// nothing out of it (`dangle`) and within it (`nowhere`), and a link
|
|
3484
3428
|
/// pointing at itself (`loop`).
|
|
3485
|
-
#[cfg(unix)]
|
|
3486
3429
|
struct LinkedBeneath(std::path::PathBuf);
|
|
3487
3430
|
|
|
3488
|
-
#[cfg(unix)]
|
|
3489
3431
|
impl LinkedBeneath {
|
|
3490
3432
|
fn new(name: &str) -> Self {
|
|
3491
3433
|
let host =
|
|
@@ -3506,7 +3448,7 @@ impl LinkedBeneath {
|
|
|
3506
3448
|
("missing", "dir/nowhere"),
|
|
3507
3449
|
("loop", "dir/loop"),
|
|
3508
3450
|
] {
|
|
3509
|
-
|
|
3451
|
+
super::testing::symlink(target, host.join(link));
|
|
3510
3452
|
}
|
|
3511
3453
|
Self(host)
|
|
3512
3454
|
}
|
|
@@ -3530,7 +3472,6 @@ impl LinkedBeneath {
|
|
|
3530
3472
|
}
|
|
3531
3473
|
}
|
|
3532
3474
|
|
|
3533
|
-
#[cfg(unix)]
|
|
3534
3475
|
impl Drop for LinkedBeneath {
|
|
3535
3476
|
fn drop(&mut self) {
|
|
3536
3477
|
let _ = std::fs::remove_dir_all(&self.0);
|
|
@@ -3540,7 +3481,6 @@ impl Drop for LinkedBeneath {
|
|
|
3540
3481
|
// Each link names a real file outside `dir` yet inside the Mount, so only
|
|
3541
3482
|
// a link kept within the descriptor, not the Mount's root, is refused.
|
|
3542
3483
|
// @behavior RT-140
|
|
3543
|
-
#[cfg(unix)]
|
|
3544
3484
|
#[test]
|
|
3545
3485
|
fn a_link_leading_out_of_an_opened_directory_escapes_it() {
|
|
3546
3486
|
let host = LinkedBeneath::new("out");
|
|
@@ -3570,7 +3510,6 @@ fn a_link_leading_out_of_an_opened_directory_escapes_it() {
|
|
|
3570
3510
|
// The second `..` leaves `sub`, where `in` led, two names after the link, so
|
|
3571
3511
|
// only a walk standing where the link led reaches `sub/y` from `dir`.
|
|
3572
3512
|
// @behavior RT-119
|
|
3573
|
-
#[cfg(unix)]
|
|
3574
3513
|
#[test]
|
|
3575
3514
|
fn a_step_out_of_where_a_link_led_lands_beside_it() {
|
|
3576
3515
|
let host = LinkedBeneath::new("led");
|
|
@@ -3588,7 +3527,6 @@ fn a_step_out_of_where_a_link_led_lands_beside_it() {
|
|
|
3588
3527
|
// on its own, so only a rename recognised as onto its own path, rather
|
|
3589
3528
|
// than by the directory each walk opened, changes nothing and succeeds.
|
|
3590
3529
|
// @behavior RT-155
|
|
3591
|
-
#[cfg(unix)]
|
|
3592
3530
|
#[test]
|
|
3593
3531
|
fn a_directory_renamed_onto_its_own_path_beneath_a_policy_stays() {
|
|
3594
3532
|
let host = LinkedBeneath::new("onto-itself");
|
|
@@ -3612,7 +3550,6 @@ fn a_directory_renamed_onto_its_own_path_beneath_a_policy_stays() {
|
|
|
3612
3550
|
// The two paths differ, so only the walk ending on one dentry tells the
|
|
3613
3551
|
// rename it is onto itself; otherwise it waits on that name's lock twice.
|
|
3614
3552
|
// @behavior RT-168
|
|
3615
|
-
#[cfg(unix)]
|
|
3616
3553
|
#[test]
|
|
3617
3554
|
fn a_file_renamed_onto_itself_through_a_link_stays() {
|
|
3618
3555
|
let host = LinkedBeneath::new("onto-itself-linked");
|
|
@@ -3629,7 +3566,6 @@ fn a_file_renamed_onto_itself_through_a_link_stays() {
|
|
|
3629
3566
|
}
|
|
3630
3567
|
|
|
3631
3568
|
// @behavior RT-154
|
|
3632
|
-
#[cfg(unix)]
|
|
3633
3569
|
#[test]
|
|
3634
3570
|
fn a_link_loop_answers_eloop() {
|
|
3635
3571
|
let host = LinkedBeneath::new("loop");
|
|
@@ -3643,7 +3579,6 @@ fn a_link_loop_answers_eloop() {
|
|
|
3643
3579
|
}
|
|
3644
3580
|
|
|
3645
3581
|
// @behavior RT-141
|
|
3646
|
-
#[cfg(unix)]
|
|
3647
3582
|
#[test]
|
|
3648
3583
|
fn a_link_staying_within_an_opened_directory_is_followed() {
|
|
3649
3584
|
let host = LinkedBeneath::new("in");
|
|
@@ -3664,7 +3599,6 @@ fn a_link_staying_within_an_opened_directory_is_followed() {
|
|
|
3664
3599
|
|
|
3665
3600
|
// An Overlay's change lands in its upper, so only a Bind shows it on the host.
|
|
3666
3601
|
// @behavior RT-142
|
|
3667
|
-
#[cfg(unix)]
|
|
3668
3602
|
#[test]
|
|
3669
3603
|
fn a_create_through_a_dangling_link_beneath_an_opened_directory_makes_its_target() {
|
|
3670
3604
|
let answers = |name, overlay| {
|
|
@@ -3686,7 +3620,6 @@ fn a_create_through_a_dangling_link_beneath_an_opened_directory_makes_its_target
|
|
|
3686
3620
|
// The link names a file outside the host directory by an absolute path, so
|
|
3687
3621
|
// the walk refuses it before any host call is made.
|
|
3688
3622
|
// @behavior RT-143
|
|
3689
|
-
#[cfg(unix)]
|
|
3690
3623
|
#[test]
|
|
3691
3624
|
fn a_link_leading_out_of_a_mount_escapes_it() {
|
|
3692
3625
|
let host = LinkedBeneath::new("mount");
|
|
@@ -3694,7 +3627,7 @@ fn a_link_leading_out_of_a_mount_escapes_it() {
|
|
|
3694
3627
|
std::env::temp_dir().join(format!("kobako-beneath-outside-{}", std::process::id()));
|
|
3695
3628
|
std::fs::write(&outside, "host").expect("the outside file must be written");
|
|
3696
3629
|
std::fs::remove_file(host.0.join("dir/up")).expect("the link must be removed");
|
|
3697
|
-
|
|
3630
|
+
super::testing::symlink(&outside, host.0.join("dir/up"));
|
|
3698
3631
|
let errno = host.guest(false).call("open_following", DIR_UP);
|
|
3699
3632
|
let _ = std::fs::remove_file(&outside);
|
|
3700
3633
|
assert_eq!(
|
|
@@ -3730,7 +3663,7 @@ fn a_files_access_is_checked_before_a_buffer_outside_memory_is_bounded() {
|
|
|
3730
3663
|
#[cfg(unix)]
|
|
3731
3664
|
const PUB_X: (i32, i32) = (1150, 5);
|
|
3732
3665
|
|
|
3733
|
-
/// A Policy allowing `/
|
|
3666
|
+
/// A Policy allowing `/pub/` alone, which swaps `pub` for a link to
|
|
3734
3667
|
/// `secret` the first time it is asked, as another writer could between
|
|
3735
3668
|
/// its judgment and the call.
|
|
3736
3669
|
#[cfg(unix)]
|
|
@@ -3741,16 +3674,16 @@ impl Policy<MountRequest<'_>> for SwapsWhileAsked {
|
|
|
3741
3674
|
fn allows(&self, request: &MountRequest<'_>) -> bool {
|
|
3742
3675
|
if self.1.swap(false, Ordering::SeqCst) {
|
|
3743
3676
|
std::fs::rename(self.0.join("pub"), self.0.join("pub_old")).expect("pub must move");
|
|
3744
|
-
|
|
3745
|
-
.expect("the link must be made");
|
|
3677
|
+
super::testing::symlink("secret", self.0.join("pub"));
|
|
3746
3678
|
}
|
|
3747
|
-
request.path.starts_with("/
|
|
3679
|
+
request.path.starts_with("/pub/")
|
|
3748
3680
|
}
|
|
3749
3681
|
}
|
|
3750
3682
|
|
|
3751
3683
|
// The swap happens inside the Policy's own judgment, after the walk opened
|
|
3752
3684
|
// `pub`, so only a call acting on the directory it walked to, rather than
|
|
3753
|
-
// 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.
|
|
3754
3687
|
// @behavior RT-145
|
|
3755
3688
|
#[cfg(unix)]
|
|
3756
3689
|
#[test]
|